Skip to content

ref(anthropic): Skip accumulation logic for unexpected types in streamed response #1162

ref(anthropic): Skip accumulation logic for unexpected types in streamed response

ref(anthropic): Skip accumulation logic for unexpected types in streamed response #1162

Triggered via pull request February 27, 2026 13:03
Status Success
Total duration 21s
Artifacts

changelog-preview.yml

on: pull_request_target
changelog-preview  /  preview
18s
changelog-preview / preview
Fit to window
Zoom out
Zoom in

Annotations

6 errors
NameError when Raw* types fail to import but are still referenced in isinstance checks: sentry_sdk/integrations/anthropic.py#L43
When the `RawMessageStartEvent`, `RawMessageDeltaEvent`, etc. imports fail (line 54-55), `message_types_have_raw_prefix` is set to `True`, but the `Raw*` type names remain undefined. However, when `message_types_have_raw_prefix` is `True`, the code path in `new_iterator()` (lines 436-447) and `new_iterator_async()` (lines 500-512) evaluates `isinstance(event, (RawMessageStartEvent, ...))`, causing a `NameError` at runtime.
[ENY-2R6] NameError when Raw* types fail to import but are still referenced in isinstance checks (additional location): sentry_sdk/integrations/anthropic.py#L435
When the `RawMessageStartEvent`, `RawMessageDeltaEvent`, etc. imports fail (line 54-55), `message_types_have_raw_prefix` is set to `True`, but the `Raw*` type names remain undefined. However, when `message_types_have_raw_prefix` is `True`, the code path in `new_iterator()` (lines 436-447) and `new_iterator_async()` (lines 500-512) evaluates `isinstance(event, (RawMessageStartEvent, ...))`, causing a `NameError` at runtime.
[ENY-2R6] NameError when Raw* types fail to import but are still referenced in isinstance checks (additional location): sentry_sdk/integrations/anthropic.py#L500
When the `RawMessageStartEvent`, `RawMessageDeltaEvent`, etc. imports fail (line 54-55), `message_types_have_raw_prefix` is set to `True`, but the `Raw*` type names remain undefined. However, when `message_types_have_raw_prefix` is `True`, the code path in `new_iterator()` (lines 436-447) and `new_iterator_async()` (lines 500-512) evaluates `isinstance(event, (RawMessageStartEvent, ...))`, causing a `NameError` at runtime.
Import logic will cause ImportError on newer anthropic SDK versions: sentry_sdk/integrations/anthropic.py#L57
Lines 57-64 unconditionally import non-Raw types (MessageStartEvent, etc.) after attempting to import Raw types. According to the referenced anthropic SDK commit, newer versions of the SDK renamed these types to have the "Raw" prefix. If the Raw* imports succeed (lines 46-53), the non-Raw imports (lines 57-64) will fail with ImportError since those types no longer exist in newer SDK versions. This will cause the Sentry SDK to fail initialization with 'DidNotEnable: Anthropic not installed'.
[VDT-8BN] Import logic will cause ImportError on newer anthropic SDK versions (additional location): sentry_sdk/integrations/anthropic.py#L435
Lines 57-64 unconditionally import non-Raw types (MessageStartEvent, etc.) after attempting to import Raw types. According to the referenced anthropic SDK commit, newer versions of the SDK renamed these types to have the "Raw" prefix. If the Raw* imports succeed (lines 46-53), the non-Raw imports (lines 57-64) will fail with ImportError since those types no longer exist in newer SDK versions. This will cause the Sentry SDK to fail initialization with 'DidNotEnable: Anthropic not installed'.
[VDT-8BN] Import logic will cause ImportError on newer anthropic SDK versions (additional location): sentry_sdk/integrations/anthropic.py#L500
Lines 57-64 unconditionally import non-Raw types (MessageStartEvent, etc.) after attempting to import Raw types. According to the referenced anthropic SDK commit, newer versions of the SDK renamed these types to have the "Raw" prefix. If the Raw* imports succeed (lines 46-53), the non-Raw imports (lines 57-64) will fail with ImportError since those types no longer exist in newer SDK versions. This will cause the Sentry SDK to fail initialization with 'DidNotEnable: Anthropic not installed'.