ref(anthropic): Separate sync and async .create() patches #5715
2 issues
Medium
Span exited without exception info loses error context - `sentry_sdk/integrations/anthropic.py:630-636`
When an exception occurs during f(*args, **kwargs), the span is exited via the finally block in _wrap_message_create with span.__exit__(None, None, None). This discards the exception context that should be passed to __exit__(exc_type, exc_val, exc_tb). While _capture_exception captures the error to Sentry, the span itself won't have the exception properly associated with its exit, potentially losing tracing context for error correlation.
Span resource leak when internal exceptions occur during non-streaming response processing - `sentry_sdk/integrations/anthropic.py:650-685`
In _sentry_patched_create_sync, the span is entered with span.__enter__() at line 626, but span.__exit__() is only called at lines 680 or 683 inside a with capture_internal_exceptions(): block. If an exception occurs in _get_token_usage(), content block iteration, or _set_output_data() before reaching span.__exit__(), the exception is silently swallowed by capture_internal_exceptions() (which returns True to suppress exceptions), but the span is never closed. The wrapper's finally block only closes spans with INTERNAL_ERROR status, which is not set for internal SDK exceptions. This causes span resource leaks.
4 skills analyzed
| Skill | Findings | Duration | Cost |
|---|---|---|---|
| code-review | 1 | 1m 12s | $0.43 |
| find-bugs | 1 | 2m 48s | $0.95 |
| skill-scanner | 0 | 49.4s | $0.21 |
| security-review | 0 | 56.2s | $0.37 |
Duration: 5m 46s · Tokens: 1.0M in / 14.4k out · Cost: $1.98 (+extraction: $0.00, +dedup: $0.01, +fix_gate: $0.00)