Tagging traces
Tags allow you to categorize and filter traces. You can tag traces (1) when they are created using the Langfuse SDKs and integrations or (2) from the Langfuse UI. To tag a trace, add a list of tags to the tags field of the trace object. Tags are strings and a trace may have multiple tags.
When using the @observe()
decorator:
from langfuse.decorators import langfuse_context, observe
@observe()
def fn():
langfuse_context.update_current_trace(
tags=["tag-1", "tag-2"]
)
fn()
When using the low-level SDK:
from langfuse import Langfuse
langfuse = Langfuse()
trace = langfuse.trace(
tags=["tag-1", "tag-2"]
)
Working with tags
Tags enable you to flexibly add metadata to your traces. You can filter for tags in the Langfuse UI and GET API.
When choosing tags, consider what aspects of the traces you might want to filter for or group by in your analysis. You may use tags to indicate specific versions of your app (‘app-v1’, ‘app-v2’), specific LLM techniques you used (‘rag’, ‘one-shot’, ‘few-shot’), or the environment of your app (‘local’, ‘staging’, ‘prod’). See Intent Classification Notebook for an end-to-end example on how tags can be created programmatically.