◐ Shell
clean mode source ↗

fix(litellm): store bookkeeping span off-band, not in forwarded metadata by jgreer013 · Pull Request #6598 · getsentry/sentry-python

@jgreer013 @claude

With LiteLLMIntegration enabled, any call passing caller `metadata` crashed
during request serialization. `_input_callback` stored the live Span in the
caller's `metadata` dict, and some providers (e.g. Anthropic's /v1/messages
passthrough) forward that dict into the outbound request body, so
`json.dumps(request_body)` raised `TypeError: Object of type Span is not JSON
serializable` before the request was sent. The span (holding the verbatim
prompt under send_default_pii) could also leak to the provider.

Stash the span on a top-level key of the per-request kwargs dict
(litellm's `model_call_details`) that litellm threads through the
input/success/failure callbacks, instead of in the forwarded `metadata`
sub-dict. This ties the span's lifetime to the request with no module-level
tracking, mirroring how the clickhouse/dramatiq integrations stash a span on
their per-request object. The Anthropic request body is built only from
recognized request params, not from `model_call_details`, so the span is
never serialized onto the wire (verified end-to-end against the passthrough).

Fixes getsentry#6596

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>