会话
许多与 LLM 应用的交互会跨越多条 trace 和 observation。Litefuse 中的 Sessions 是一种特殊机制,可以把跨 trace 的 observation 归并到一起,并通过简单的 session replay 查看整个交互过程。只需要将 sessionId 属性在 observation 之间传播即可开始使用。
将 sessionId 传播到跨多条 trace 的 observation 上。sessionId 可以是任意小于 200 字符的 US-ASCII 字符串,用于标识会话。所有具有相同 sessionId 的 observation 会被归并到一起,包括它们所在的 trace。如果 session ID 超过 200 字符,将被丢弃。
使用 @observe() 装饰器时:
from langfuse import observe, propagate_attributes
@observe()
def process_request():
# Propagate session_id to all child observations
with propagate_attributes(session_id="your-session-id"):
# All nested observations automatically inherit session_id
result = process_chat_message()
return result直接创建 observation 时:
from langfuse import get_client, propagate_attributes
langfuse = get_client()
with langfuse.start_as_current_observation(
as_type="span",
name="process-chat-message"
) as root_span:
# Propagate session_id to all child observations
with propagate_attributes(session_id="chat-session-123"):
# All observations created here automatically have session_id
with root_span.start_as_current_observation(
as_type="generation",
name="generate-response",
model="gpt-4o"
) as gen:
# This generation automatically has session_id
passNote on Attribute Propagation
We use Attribute Propagation to propagate `sessionId` across all observations of a trace. We will use all observations with `sessionId` to create `sessionId`-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
示例
可以通过公开的示例项目来体验该功能。
跨多条 trace 的会话示例

其他功能
- 将会话发布为公开链接以便分享(示例)
- 收藏会话以便日后查找
- 通过 Litefuse UI 为会话添加
scores进行标注,记录人工评估 - 通过 SDK 或 API 程序化地添加
session-level分数,例如来自用户反馈表单、内容审查或对话级 QA pipeline。参见 Scores via API/SDK。 - 在 Litefuse 中如何评估会话?
相关资源
- 如果你需要将多个服务上的操作归并到一条 trace 中(而不是将多条 trace 归并到一起),请参阅 Trace IDs 与分布式 tracing。
这个页面对你有帮助吗?