mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-15 23:31:29 +00:00
A failed MCP tool call aimed its error.* attributes at request_root_span(), a ContextVar written on the ASGI request task. A stateful streamable-HTTP session runs every message on the single task the session's initialize POST spawned, so inside the message handler that ContextVar still holds the initialize request's SERVER span. That span ended long ago, so the SDK dropped every write (five 'Setting attribute on ended span' warnings plus set_status and _add_event per failed call) and the POST that actually failed carried no error at all. The identity attributes seeded onto the server span went the same way. Publish the live transport span on the ASGI scope of the request being handled and read it back in the message handler through req_ctx.request, the Request the streamable-HTTP transport attaches to each message. That replaces the session-scoped field with a per-message one: a JSON-RPC response POST deliberately skips the per-session lock, since it can arrive while the tool call awaiting it is still in flight, so a field on the shared auth object could be overwritten mid-call and send the tool call's telemetry to the response's request. A scope also dies with its request rather than holding a finished span on idle session state. Publishing re-anchors the request root for the message so guardrail spans and identity seeding follow, and only a transport still open for writes is anchored or stamped: a notification POST can answer before the session task is done, and moving dropped writes from one finished span to another is no fix. Live capture goes from seven ended-span warnings and an unmarked transaction to zero warnings and ERROR on the POST that carried the call. |
||
|---|---|---|
| .. | ||
| test_otel_v2_baggage.py | ||
| test_otel_v2_components.py | ||
| test_otel_v2_config_baggage_parenting_guardrails.py | ||
| test_otel_v2_dynamic.py | ||
| test_otel_v2_emitter.py | ||
| test_otel_v2_logger.py | ||
| test_otel_v2_metrics.py | ||
| test_otel_v2_mount.py | ||
| test_otel_v2_multibackend.py | ||
| test_otel_v2_presets.py | ||
| test_otel_v2_sources_of_truth.py | ||
| test_otel_v2_vendor_mappers.py | ||
| test_runtime.py | ||