feat(anthropic): Emit gen_ai.chat spans for synchronous messages.stream()
#17811
ci.yml
on: pull_request
Lint Sources
1m 23s
Build Package
15s
Build SDK API Doc
26s
Annotations
3 errors and 4 warnings
|
Lint Sources
Process completed with exit code 1.
|
|
Missing error handling in _wrap_message_stream_manager_enter causes potential AttributeError crashes:
sentry_sdk/integrations/anthropic.py#L95
The `_sentry_patched_enter` function in `_wrap_message_stream_manager_enter` accesses `self._max_tokens`, `self._messages`, and other attributes directly without error handling. If these attributes don't exist (e.g., if `MessageStreamManager` is instantiated without going through the wrapped `Messages.stream()` method), an `AttributeError` will propagate and crash the user's application. Unlike other patched methods in this file which use `capture_internal_exceptions()` or `getattr()` for defensive access, this new code has no such protection.
|
|
[8MF-E57] Missing error handling in _wrap_message_stream_manager_enter causes potential AttributeError crashes (additional location):
sentry_sdk/integrations/anthropic.py#L812
The `_sentry_patched_enter` function in `_wrap_message_stream_manager_enter` accesses `self._max_tokens`, `self._messages`, and other attributes directly without error handling. If these attributes don't exist (e.g., if `MessageStreamManager` is instantiated without going through the wrapped `Messages.stream()` method), an `AttributeError` will propagate and crash the user's application. Unlike other patched methods in this file which use `capture_internal_exceptions()` or `getattr()` for defensive access, this new code has no such protection.
|
|
Missing async stream support for `AsyncMessages.stream()`:
sentry_sdk/integrations/anthropic.py#L94
The code patches `Messages.stream` and `MessageStreamManager.__enter__` for synchronous streaming, but does not patch `AsyncMessages.stream` or its corresponding `AsyncMessageStreamManager.__aenter__`. This means users using async streaming via `await client.messages.stream()` will not get `gen_ai.chat` spans emitted, inconsistent with the sync behavior. The existing `Messages.create` and `AsyncMessages.create` both have patching parity.
|
|
[GQA-V3Z] Missing async stream support for `AsyncMessages.stream()` (additional location):
sentry_sdk/integrations/anthropic.py#L812
The code patches `Messages.stream` and `MessageStreamManager.__enter__` for synchronous streaming, but does not patch `AsyncMessages.stream` or its corresponding `AsyncMessageStreamManager.__aenter__`. This means users using async streaming via `await client.messages.stream()` will not get `gen_ai.chat` spans emitted, inconsistent with the sync behavior. The existing `Messages.create` and `AsyncMessages.create` both have patching parity.
|
|
Calling len() on Iterable type may raise TypeError:
sentry_sdk/integrations/anthropic.py#L286
The `messages` parameter is typed as `Iterable[MessageParam]`, but `len(messages)` is called at line 286. General iterables (like generators) don't support `len()`, which would cause a `TypeError`. While the Anthropic SDK likely receives lists in practice, the type annotation suggests arbitrary iterables are valid. The previous code retrieved messages from `kwargs.get()` which had the same issue, so this is not a regression.
|
|
[EX6-HSK] Calling len() on Iterable type may raise TypeError (additional location):
sentry_sdk/integrations/anthropic.py#L360
The `messages` parameter is typed as `Iterable[MessageParam]`, but `len(messages)` is called at line 286. General iterables (like generators) don't support `len()`, which would cause a `TypeError`. While the Anthropic SDK likely receives lists in practice, the type annotation suggests arbitrary iterables are valid. The previous code retrieved messages from `kwargs.get()` which had the same issue, so this is not a regression.
|
Artifacts
Produced during runtime
| Name | Size | Digest | |
|---|---|---|---|
|
artifact-build_lambda_layer
|
1.47 MB |
sha256:50fecc5416ad3ef03d18d885f21ea69d03a8492149582b3e77e03664f5e3116d
|
|
|
artifact-docs
|
890 KB |
sha256:fbaabb6d305161eac7e74419d4b9ec334b2a81aff7ca702c2363be2dd262e6a4
|
|