DocsObservabilityFeaturesTags

Tags

Tags allow you to categorize and filter observations and traces in Langfuse.

Tags are strings (max 200 characters each) and an observation may have multiple tags. The full set of tags applied across all observations in a trace are automatically aggregated and added to the trace object in Langfuse. If a tag exceeds 200 characters, it will be dropped.

Propagating Tags to Observations

Use propagate_attributes() to apply tags to a group of observations within a context.

When using the @observe() decorator:

from langfuse import observe, propagate_attributes
 
@observe()
def my_function():
    # Apply tags to all child observations
    with propagate_attributes(
        tags=["tag-1", "tag-2"]
    ):
        # All nested observations automatically have these tags
        result = process_data()
        return result

When creating observations directly:

from langfuse import get_client, propagate_attributes
 
langfuse = get_client()
 
with langfuse.start_as_current_span(name="my-operation") as root_span:
    # Apply tags to all child observations
    with propagate_attributes(tags=["tag-1", "tag-2"]):
        # All observations created here automatically have these tags
        with root_span.start_as_current_generation(
            name="llm-call",
            model="gpt-4o"
        ) as gen:
            # This generation automatically has the tags
            pass
Note on Attribute Propagation
We use Attribute Propagation to propagate `tags` across all observations of a trace. We will use all observations with `tags` to create `tags`-level metrics. Please consider the following when using Attribute Propagation:
  • Values must be strings ≤200 characters
  • Call early in your trace to ensure all observations are covered. This way you make sure that all Metrics in Langfuse are accurate.
  • Invalid values are dropped with a warning

GitHub Discussions

Was this page helpful?