DocsObservabilityFeaturesObservations

Observations

Observations are the building blocks of observability in Langfuse. They are used to track the individual steps of an application.

Observations are either created automatically by one of our integrations or manually by you using the Langfuse SDK.

Observation Types

Langfuse supports different observation types to provide more context to your observations and allow efficient filtering.

Available Types

  • event is the basic building block. An event is used to track discrete events in a trace.
  • span represents durations of units of work in a trace.
  • generation logs generations of AI models incl. prompts, token usage and costs.
  • agent decides on the application flow and can for example use tools with the guidance of a LLM.
  • tool represents a tool call, for example to a weather API.
  • chain is a link between different application steps, like passing context from a retriever to a LLM call.
  • retriever represents data retrieval steps, such as a call to a vector store or a database.
  • evaluator represents functions that assess relevance/correctness/helpfulness of a LLM’s outputs.
  • embedding is a call to a LLM to generate embeddings and can include model, token usage and costs
  • guardrail is a component that protects against malicious content or jailbreaks.

How to Use Observation Types

The integrations with agent frameworks automatically set the observation types. For example, marking a method with @tool in langchain will automatically set the Langfuse observation type to tool.

You can also manually set the observation types for your application within the Langfuse SDK. Set the as_type parameter (Python) or asType parameter (TypeScript) to the desired observation type when creating an observation.

Observation types require Python SDK version>=3.3.1.

Using @observe decorator:

from langfuse import observe
 
# Agent workflow
@observe(as_type="agent")
def run_agent_workflow(query):
    # Agent reasoning and tool orchestration
    return process_with_tools(query)
 
# Tool calls
@observe(as_type="tool")
def call_weather_api(location):
    # External API call
    return weather_service.get_weather(location)

Calling the start_as_current_observation or start_observation method:

from langfuse import get_client
 
langfuse = get_client()
 
# Start observation with specific type
with langfuse.start_as_current_observation(
    as_type="embedding",
    name="embedding-generation"
) as obs:
    embeddings = model.encode(["text to embed"])
    obs.update(output=embeddings)
 
# Start observation with specific type
transform_span = langfuse.start_observation(
    as_type="chain",
    name="transform-text"
)
transformed_text = transform_text(["text to transform"])
transform_span.update(output=transformed_text)
Was this page helpful?