ref(anthropic): Skip accumulation logic for unexpected types in streamed response #5564
2 issues
High
Inverted boolean flag causes incorrect event type filtering - `sentry_sdk/integrations/anthropic.py:42-54`
The message_types_have_raw_prefix flag is set incorrectly: it starts as False and is set to True only when the RawMessage*Event imports fail. This is backwards - if the Raw* types can be imported, the SDK has the raw prefix (flag should be True). If imports fail, it means there's no raw prefix (flag should be False). This causes the streaming event type filtering logic (lines 434-459, 499-524) to behave incorrectly, potentially skipping data collection for valid events or attempting to use RawMessage*Event types that weren't successfully imported.
Also found at:
sentry_sdk/integrations/anthropic.py:434-457sentry_sdk/integrations/anthropic.py:499-522
NameError when Raw* types fail to import but are still referenced in isinstance checks - `sentry_sdk/integrations/anthropic.py:42-54`
When the RawMessageStartEvent and related types fail to import (older anthropic SDK versions), message_types_have_raw_prefix is set to True. However, the streaming iterator logic then checks message_types_have_raw_prefix and not isinstance(event, (RawMessageStartEvent, ...)), which will cause a NameError because RawMessageStartEvent is undefined when the import failed. The boolean flag semantics are inverted - it's True when Raw types DON'T exist, yet the code tries to use those types in that branch.
Also found at:
sentry_sdk/integrations/anthropic.py:434-447sentry_sdk/integrations/anthropic.py:499-522
4 skills analyzed
| Skill | Findings | Duration | Cost |
|---|---|---|---|
| code-review | 1 | 1m 52s | $0.35 |
| find-bugs | 1 | 2m 7s | $0.42 |
| skill-scanner | 0 | 59.3s | $0.18 |
| security-review | 0 | 48.8s | $0.26 |
Duration: 5m 46s · Tokens: 436.4k in / 13.7k out · Cost: $1.25 (+extraction: $0.02, +merge: $0.00, +dedup: $0.01)