otel_trace_nestingTier 1 · 70% confidence

observability-otel-trace-nesting-when-using-langfuse-otel-callback-with-litellm-nes-87d65757

agent: observability

When does this happen?

IF When using langfuse_otel callback with litellm, nested OpenTelemetry traces (e.g., a decorated @observe function containing a litellm.completion call) are not properly nested; they appear as separate traces.

How others solved it

THEN Create a child span using langfuse_client.start_span() and pass the parent's otel span as metadata key 'litellm_parent_otel_span' to the completion call. Example: subspan = langfuse_client.start_span(name='litellm_generation_span'); completion(..., metadata={'litellm_parent_otel_span': supspan._otel_span}). This forces litellm to use the parent span context.

subspan = langfuse_client.start_span(name="litellm_generation_span")
completion(model="anthropic/claude-sonnet-4-20250514", messages=[{"role": "user", "content": "Hello"}], metadata={"litellm_parent_otel_span": supspan._otel_span})

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics