Repository navigation
Conversation
…ming_response Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(integrations): record output for with_raw_response and with_streaming_response
Description
sentry_sdk/integrations/anthropic.py:794requireshasattr(result, "content"). A.with_raw_responsewrapper has nocontent, so the span ends atunknown_responseon line 824.openai.py:919passes the wrapper on too, and_set_completions_api_output_datafinds nochoicesand records nothing. Both integration docs promise Sentry "will automatically collect information about prompts, tools, tokens, and models". The Anthropic page namesmessages.createas the supported function..with_raw_responseand.with_streaming_responsecall that samecreatebehind anX-Stainless-Raw-Responseheader, so the span opens and records no output.Before:
After:
parse()caches its result, so parsing an already-read body wherecreatewould costs the caller nothing. A streamed body stays unread. The span fills when the caller parses it, and closes when the caller closes the response. A wrapper the caller neither parses nor closes leaves that span unfinished. The SDK then drops the span where baseline ends it.close()finishes the span wherever the wrapper offers one, and none of the 6 new tests covers that case.Verification
Baseline on
2ffd383is1284 passed, 1706 warnings in 26.98s, so the delta is the 6 new tests. Reverting both integration files and keeping the tests gives6 failed, 10 warnings in 0.44s.Your #5917, after #5890, stopped wrapping responses without
_iterator. It said tracingLegacyAPIResponsewas intentionally out of scope. This change keeps that guard and picks up only the deferral. It fills the span for the wrapper without touching_iteratoror reading an unread body.Fixes #7948
@alexander-alderman-webb Your #7948 reply put this on PY-2950. #7891 is the separate
parse()gap on a plaincreate, which I have not touched here. If the openai work has started, I would close this instead. Otherwise it is ready to land ahead of PY-2950. Does that timing suit you?