Skip to main content

Example

Decorator Parameters

These parameters are passed to @observe(...) and forwarded directly to Langfuse’s @observe:
str
Custom span name. Defaults to the decorated function’s name.
str
Langfuse observation type: span (default), generation, agent, tool, retriever, chain, evaluator, embedding, guardrail. Mapped to Galtea’s SpanType automatically. See observation types.
All other Langfuse @observe keyword arguments are forwarded as-is.

Runtime Kwargs

These kwargs are passed when calling the decorated function (not when defining the decorator):
str
Galtea trace ID to link spans to. When provided on the outermost @observe call, the wrapper manages the span context automatically. Consumed by the wrapper — does not reach the decorated function’s parameters.
If trace_id is passed to a nested @observe call where an outer context is already active, it is ignored — the outermost context takes precedence.

Returns

Returns the decorated function with Langfuse tracing and optional Galtea span linking enabled. The return type and signature of the decorated function are preserved.

Async support

@observe works on both def and async def functions. When the wrapped function is a coroutine, the decorator returns an async wrapper that awaits the coroutine before clearing the Galtea context — so spans inside the awaited body are correctly stamped with trace_id.