Skip to content

Commit 7f71789

Browse files
committed
clean
1 parent 1bc90b0 commit 7f71789

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

langfuse/_client/client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ def start_as_current_generation(
669669

670670
def _get_span_class(self, as_type: str):
671671
"""Get the appropriate span class based on as_type."""
672+
# TODO: make it case insensitive
672673
if as_type == "AGENT":
673674
return LangfuseAgent
674675
elif as_type == "TOOL":
@@ -686,7 +687,6 @@ def _get_span_class(self, as_type: str):
686687
elif as_type in ("span", "SPAN"):
687688
return LangfuseSpan
688689
else:
689-
# Default to LangfuseSpan for unknown types
690690
return LangfuseSpan
691691

692692
@_agnosticcontextmanager
@@ -696,7 +696,7 @@ def _create_span_with_parent_context(
696696
name: str,
697697
parent: Optional[otel_trace_api.Span] = None,
698698
remote_parent_span: Optional[otel_trace_api.Span] = None,
699-
as_type: Optional[str] = None,
699+
as_type: Literal["generation", "span", "AGENT", "TOOL", "CHAIN", "RETRIEVER"],
700700
end_on_exit: Optional[bool] = None,
701701
input: Optional[Any] = None,
702702
output: Optional[Any] = None,
@@ -793,10 +793,9 @@ def _start_as_current_otel_span_with_processed_media(
793793
LangfuseRetriever,
794794
LangfuseEmbedding,
795795
]:
796-
# Graph observation classes set their specific observation_type internally
796+
# set their type internally in the class
797797
pass
798798
else:
799-
# Regular spans (LangfuseSpan, LangfuseEvent) need as_type
800799
if as_type is not None:
801800
common_args["as_type"] = as_type
802801

langfuse/_client/observe.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def observe(
121121
name (Optional[str]): Custom name for the created trace or span. If not provided, the function name is used.
122122
as_type (Optional[Literal["generation"]]): Set to "generation" to create a specialized LLM generation span
123123
with model metrics support, suitable for tracking language model outputs.
124-
type (Optional[Literal]): Set the observation type for agentic workflows. Supported values: "SPAN", "EVENT",
124+
type (Optional[Literal]): Set the observation type for agentic workflows. Supported values:
125125
"GENERATION", "AGENT", "TOOL", "CHAIN", "RETRIEVER", "EMBEDDING". When specified, creates spans with
126126
the specified type for graph visualization and filtering in the Langfuse UI.
127127
@@ -182,7 +182,6 @@ def sub_process():
182182
- For async functions, the decorator returns an async function wrapper.
183183
- For sync functions, the decorator returns a synchronous wrapper.
184184
"""
185-
# Validate parameters
186185
if type is not None and type not in VALID_OBSERVATION_TYPES:
187186
raise ValueError(
188187
f"Invalid observation type '{type}'. Valid types are: {', '.join(sorted(VALID_OBSERVATION_TYPES))}"
@@ -235,11 +234,11 @@ def decorator(func: F) -> F:
235234
)
236235

237236
"""Handle decorator with or without parentheses.
238-
237+
239238
This logic enables the decorator to work both with and without parentheses:
240239
- @observe - Python passes the function directly to the decorator
241240
- @observe() - Python calls the decorator first, which must return a function decorator
242-
241+
243242
When called without arguments (@observe), the func parameter contains the function to decorate,
244243
so we directly apply the decorator to it. When called with parentheses (@observe()),
245244
func is None, so we return the decorator function itself for Python to apply in the next step.

0 commit comments

Comments
 (0)