ref(anthropic): Factor out streamed result handling #5563
1 issue
code-review: Found 1 issue (1 medium)
Medium
Missing null check for integration in streaming response handler could cause AttributeError - `sentry_sdk/integrations/anthropic.py:402`
The new _patch_streaming_response_iterator function fetches integration via sentry_sdk.get_client().get_integration(AnthropicIntegration) at line 402, but doesn't check if it's None before passing it to _set_output_data. If the client configuration changes or gets disabled between when the original call started and when the stream is consumed, integration could be None, causing an AttributeError when _set_output_data accesses integration.include_prompts at line 358.
Also found at:
sentry_sdk/integrations/anthropic.py:514-516
Duration: 1m 5s · Tokens: 194.4k in / 2.8k out · Cost: $0.32 (+extraction: $0.00, +merge: $0.00)
Annotations
Check warning on line 402 in sentry_sdk/integrations/anthropic.py
github-actions / warden: code-review
Missing null check for integration in streaming response handler could cause AttributeError
The new `_patch_streaming_response_iterator` function fetches `integration` via `sentry_sdk.get_client().get_integration(AnthropicIntegration)` at line 402, but doesn't check if it's `None` before passing it to `_set_output_data`. If the client configuration changes or gets disabled between when the original call started and when the stream is consumed, `integration` could be `None`, causing an `AttributeError` when `_set_output_data` accesses `integration.include_prompts` at line 358.
Check warning on line 516 in sentry_sdk/integrations/anthropic.py
github-actions / warden: code-review
[RK8-6U8] Missing null check for integration in streaming response handler could cause AttributeError (additional location)
The new `_patch_streaming_response_iterator` function fetches `integration` via `sentry_sdk.get_client().get_integration(AnthropicIntegration)` at line 402, but doesn't check if it's `None` before passing it to `_set_output_data`. If the client configuration changes or gets disabled between when the original call started and when the stream is consumed, `integration` could be `None`, causing an `AttributeError` when `_set_output_data` accesses `integration.include_prompts` at line 358.