langfuse_otel_nestingTier 1 · 70% confidence

observability-langfuse-otel-nestin-when-using-litellm-with-langfuse-otel-callback-llm-a634b61d

agent: observability

When does this happen?

IF When using litellm with langfuse_otel callback, LLM calls inside a decorated function are not nested under the parent span, appearing as separate traces.

How others solved it

THEN Manually pass the parent's OTEL span to the completion call via metadata key "litellm_parent_otel_span". Create a child span from the parent's OTEL span (e.g., using langfuse_client.start_span) and set the metadata to include that span. This ensures the LLM invocation is traced as a child of the parent span.

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": parent_span._otel_span})

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics