Context
When the triage router propagates session_id and user_id via Langfuse's propagate_attributes(), only the litellm-proxy trace (created by LiteLLM's proxy layer) inherits these attributes. The agent-completion trace (created by LiteLLM's internal LLM call instrumentation) does not — it appears as a separate trace with sessionId: null.
This was observed during PR #302 verification:
- Session-bearing request →
litellm-proxy trace gets sessionId=e2e-verify-*, userId=verify-script
- Same request →
agent-completion trace gets sessionId=None, userId=None
Why this matters
The agent-completion trace is where actual token usage, latency, and model metadata live. Without session context there, session-scoped Langfuse dashboards, cost-tracking, and user-level analytics are incomplete — you can see the proxy hop but not the actual model call.
Root cause
LiteLLM creates agent-completion as a separate trace (not an observation within our parent trace). Langfuse's propagate_attributes sets context on the current OpenTelemetry span; LiteLLM's internal agent-completion span lives in a different trace tree and doesn't inherit.
What to investigate
- Use cases: Which Langfuse features break without session on
agent-completion? (session-scoped dashboards, per-user cost reports, trace-linking in UI)
- Benefits: What would full session propagation across both
litellm-proxy AND agent-completion enable?
- Implementation options (ranked by feasibility):
- A) LiteLLM config: Does LiteLLM's
langfuse config section support a session_id parameter that would be forwarded to backend traces?
- B) Trace header forwarding: Pass
X-Langfuse-Trace-Id + X-Langfuse-Session-Id headers through LiteLLM to the backend provider — does LiteLLM respect these?
- C) LiteLLM callback: Can a LiteLLM
success_callback or failure_callback patch the agent-completion trace's session after creation?
- D) OpenTelemetry context propagation: Wire our parent trace's OTel context into LiteLLM's trace provider so child traces share context
- Sibling trace linking: If full propagation isn't feasible, can we at least link
agent-completion traces to our session-bearing traces so Langfuse UI shows them together?
Affected components
router/main.py — chat_completions (session_id/user_id extraction + propagate_attributes)
- LiteLLM's Langfuse integration (external, version-dependent)
- Langfuse UI session views, cost dashboards
Requirements
Context
When the triage router propagates
session_idanduser_idvia Langfuse'spropagate_attributes(), only thelitellm-proxytrace (created by LiteLLM's proxy layer) inherits these attributes. Theagent-completiontrace (created by LiteLLM's internal LLM call instrumentation) does not — it appears as a separate trace withsessionId: null.This was observed during PR #302 verification:
litellm-proxytrace getssessionId=e2e-verify-*,userId=verify-scriptagent-completiontrace getssessionId=None,userId=NoneWhy this matters
The
agent-completiontrace is where actual token usage, latency, and model metadata live. Without session context there, session-scoped Langfuse dashboards, cost-tracking, and user-level analytics are incomplete — you can see the proxy hop but not the actual model call.Root cause
LiteLLM creates
agent-completionas a separate trace (not an observation within our parent trace). Langfuse'spropagate_attributessets context on the current OpenTelemetry span; LiteLLM's internalagent-completionspan lives in a different trace tree and doesn't inherit.What to investigate
agent-completion? (session-scoped dashboards, per-user cost reports, trace-linking in UI)litellm-proxyANDagent-completionenable?langfuseconfig section support asession_idparameter that would be forwarded to backend traces?X-Langfuse-Trace-Id+X-Langfuse-Session-Idheaders through LiteLLM to the backend provider — does LiteLLM respect these?success_callbackorfailure_callbackpatch theagent-completiontrace's session after creation?agent-completiontraces to our session-bearing traces so Langfuse UI shows them together?Affected components
router/main.py—chat_completions(session_id/user_id extraction +propagate_attributes)Requirements