Skip to main content

Tags

还没翻译译自英文(langfuse.com)本页 33 段都还没译

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. If a tag exceeds 200 characters, it will be dropped.

Note

The full set of tags applied across all observations in a trace are automatically aggregated and added to the trace object in Langfuse.

In the Langfuse UI

Once observations have tags assigned, you can:

  • Filter the traces and observations tables by one or more tags, including from the filter search bar (tags:(billing AND urgent)).
  • Segment custom dashboards and metrics by tag, for example cost or latency of checkout versus support-bot.
  • Organize traces by feature, endpoint, or workflow without mixing those categories into environment, user, or session.

Traces table with a Trace Tags column

Tags cannot be changed later

Because Langfuse uses an immutable data model for observations, tags can't be added or edited in the UI after they're created.

Implementation

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

Python SDKJS/TS SDKOpenAI (Python v2)OpenAI (JS/TS)Langchain (Python)Langchain (JS/TS)

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_observation(as_type="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_observation(
            as_type="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

Learn more: Python SDK | TypeScript SDK

GitHub Discussions