Skip to content

Merge branch 'master' into webb/litellm/close-spans

7ab7959
Select commit
Loading
Failed to load commit list.
Merged

fix(litellm): Avoid double span exits when streaming #5933

Merge branch 'master' into webb/litellm/close-spans
7ab7959
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: code-review completed Apr 13, 2026 in 54s

2 issues

code-review: Found 2 issues (1 medium, 1 low)

Medium

Failure callback doesn't use pop() pattern, risking double span exit during streaming - `sentry_sdk/integrations/litellm.py:227-230`

The _failure_callback at line 240 uses .get() instead of .pop() to retrieve the span, and doesn't check for streaming. If a streaming response fails mid-stream, after _success_callback has been called once (but not completed), a subsequent _failure_callback could attempt to exit the same span. While the fix in _success_callback is correct, the same pattern should be applied to _failure_callback for consistency and to prevent potential double exits when failures occur during streaming.

Low

Test parameterization is unused - send_default_pii and include_prompts not verified - `tests/integrations/litellm/test_litellm.py:290-291`

The test_streaming_chat_completion test is parameterized with send_default_pii and include_prompts parameters (lines 225-229) that control whether prompts and PII data are captured, but the assertions at lines 290-291 only check GEN_AI_RESPONSE_STREAMING. Unlike the non-streaming test which verifies GEN_AI_REQUEST_MESSAGES and GEN_AI_RESPONSE_TEXT based on these parameters, the streaming test doesn't assert on this behavior, reducing the test's effectiveness.


Duration: 51.2s · Tokens: 547.5k in / 5.0k out · Cost: $1.19 (+merge: $0.00)

Annotations

Check warning on line 230 in sentry_sdk/integrations/litellm.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: code-review

Failure callback doesn't use pop() pattern, risking double span exit during streaming

The `_failure_callback` at line 240 uses `.get()` instead of `.pop()` to retrieve the span, and doesn't check for streaming. If a streaming response fails mid-stream, after `_success_callback` has been called once (but not completed), a subsequent `_failure_callback` could attempt to exit the same span. While the fix in `_success_callback` is correct, the same pattern should be applied to `_failure_callback` for consistency and to prevent potential double exits when failures occur during streaming.