feat(anthropic): Emit AI Client Spans for synchronous messages.stream()
#1193
Triggered via pull request
March 2, 2026 08:29
alexander-alderman-webb
synchronize
#5565
Status
Success
Total duration
22s
Artifacts
–
changelog-preview.yml
on: pull_request_target
changelog-preview
/
preview
18s
Annotations
2 warnings
|
Span opened but not closed if exception occurs during stream setup:
sentry_sdk/integrations/anthropic.py#L759
In `_sentry_patched_stream_common`, a span is entered via `span.__enter__()` at line 759, but if `_set_stream_input_data` or `_patch_streaming_response_iterator` raises an exception, the span will never be closed. Unlike `_wrap_message_create` which has error handling in its `finally` block (lines 680-684), the streaming path has no equivalent protection. This could leave orphaned spans in Sentry traces.
|
|
Return type mismatch: function returns stream but declares None return type:
sentry_sdk/integrations/anthropic.py#L737
The function `_sentry_patched_stream_common` has a return type annotation of `-> None`, but lines 741, 744, and 749 all use `return stream`. While Python allows returning non-None values from functions annotated with `-> None`, the actual returned value is discarded by the caller (`_sentry_patched_enter` at line 812-822 ignores the return value). This creates misleading code that appears to short-circuit but the return value has no effect.
|