DocsTracing FeaturesMetadata

Metadata

Traces and observations (see Langfuse Data Model) can be enriched with metadata to better understand your users, application, and experiments. Metadata can be added to traces in the form of arbitrary JSON.

When using the @observe() decorator:

from langfuse.decorators import langfuse_context, observe
 
@observe
def nested():
    # Update trace metadata from anywhere inside call stack
    langfuse_context.update_current_trace(
        metadata={"key":"value"}
    )
 
    # Update observation metadata for current observation
    langfuse_context.update_current_observation(
        metadata={"key": "value"}
    )
 
    return
 
@observe
def fn():
    nested()
 
fn()

When using the low-level SDK:

from langfuse import Langfuse
langfuse = Langfuse()
 
trace = langfuse.trace(
    metadata={"key":"value"}
)
 
span = trace.span(
    metadata={"key":"value"}
)

GitHub Discussions

Was this page useful?

Questions? We're here to help

Subscribe to updates