标签
标签让你能够在 Litefuse 中对 observation 和 trace 进行分类和过滤。
标签为字符串(每个最多 200 字符),一个 observation 可以有多个标签。一条 trace 中所有 observation 的全部标签会被自动聚合,并添加到 Litefuse 中的 trace 对象上。如果某个标签超过 200 字符,将被丢弃。
将标签传播到 observation
使用 propagate_attributes() 在 context 内为一组 observation 应用标签。
使用 @observe() 装饰器时:
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直接创建 observation 时:
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
passNote 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 Litefuse are accurate.
- Invalid values are dropped with a warning
Learn more: Python SDK | TypeScript SDK
这个页面对你有帮助吗?