8000 Anthropic integration unexpectedly drops `message_stop` events from streamed responses · Issue #4212 · getsentry/sentry-python · GitHub
[go: up one dir, main page]

Skip to content

Anthropic integration unexpectedly drops message_stop events from streamed responses #4212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
john-sungjin opened this issue Mar 29, 2025 · 2 comments · Fixed by #4232
Closed

Comments

@john-sungjin
Copy link

It seems that the integration modifies the Anthropic stream iterators to ignore events of type message_stop:

def new_iterator():
# type: () -> Iterator[MessageStreamEvent]
input_tokens = 0
output_tokens = 0
content_blocks = [] # type: list[str]
for event in old_iterator:
input_tokens, output_tokens, content_blocks = _collect_ai_data(
event, input_tokens, output_tokens, content_blocks
)
if event.type != "message_stop":
yield event
_add_ai_data_to_span(
span, integration, input_tokens, output_tokens, content_blocks
)
span.__exit__(None, None, None)
async def new_iterator_async():
# type: () -> AsyncIterator[MessageStreamEvent]
input_tokens = 0
output_tokens = 0
content_blocks = [] # type: list[str]
async for event in old_iterator:
input_tokens, output_tokens, content_blocks = _collect_ai_data(
event, input_tokens, output_tokens, content_blocks
)
if event.type != "message_stop":
yield event
_add_ai_data_to_span(
span, integration, input_tokens, output_tokens, content_blocks
)
span.__exit__(None, None, None)

Is this intentional? This is a meaningful event (as indicated in the Anthropic documentation) and I wouldn't expect Sentry to modify this behavior.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 29, 2025
@john-sungjin john-sungjin changed the title Anthropic integration unexpectedly drops message_stop Anthropic integration unexpectedly drops message_stop events from streamed responses Mar 29, 2025
@antonpirker
Copy link
Member

Hey @john-sungjin , this seems in deed odd. I have asked the author of the integration internally. I will get back to you.

@antonpirker
Copy link
Member

We have a PR with a fix merged! This will be released soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants
0