Repository navigation
feat(boto3): Instrument Bedrock Runtime streaming calls as gen_ai spans - #8189
Draft
sentry-junior[bot] wants to merge 2 commits into
Draft
sentry-junior[bot] wants to merge 2 commits into
sentry-junior[bot] wants to merge 2 commits into
Conversation
Contributor
Coverage Results 📊✅ 139674 passed | ⏭️ 7497 skipped | Total: 147171 | Pass Rate: 94.91% | Execution Time: 466m 57s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 94.83% (220 of 232 changed executable lines covered; target 80%). Changed files with executable lines (3)
Coverage diff@@ Coverage Diff @@
## master #8189 +/-##
==========================================
+ Coverage 90.33% 90.44% +0.11%
==========================================
Files 203 204 +1
Tracked lines 26905 27554 +649
Branches 10048 10386 +338
==========================================
+ Hits 24302 24919 +617
- Misses 2603 2635 +32
- Partials 1516 1561 +45Generated by Coverage Action |
sentry-junior
Bot
force-pushed
the
junior/boto3-bedrock-streaming
branch
2 times, most recently
from
November 4, 2026 23:50
febb4e2 to
dc0d1ab
Compare
sentry-junior
Bot
force-pushed
the
junior/boto3-bedrock-streaming
branch
from
November 5, 2026 00:13
dc0d1ab to
d740ea6
Compare
sentry-junior
Bot
force-pushed
the
junior/boto3-bedrock-streaming
branch
2 times, most recently
from
November 5, 2026 01:08
7007b79 to
34c9160
Compare
sentry-junior
Bot
force-pushed
the
junior/boto3-bedrock-streaming
branch
from
November 5, 2026 01:16
34c9160 to
5a2015e
Compare
Record ConverseStream and InvokeModelWithResponseStream calls as gen_ai spans that finish once the caller has received the stream: when it's exhausted, closed, iteration stops early, or it fails. The finish reason, token usage, and output messages are accumulated from the events the caller receives, which are unchanged. `EventStream.__iter__` and `close` are patched globally, since the iterator is a method; only streams of instrumented calls are recorded. Refs #5470 Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
…uts once Malformed InvokeModelWithResponseStream chunks are skipped quietly instead of reporting an SDK internal error, like the non-streamed response path. The buffered stream content is already gated on recording outputs, so serialize it directly rather than checking the gate a second time. That makes the buffering gate the only gate, so tests cover it. Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
sentry-junior
Bot
force-pushed
the
junior/boto3-bedrock-streaming
branch
from
November 5, 2026 01:41
5a2015e to
81e76ad
Compare
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.
Description
This PR (3 of 3, stacked on #8187) records
ConverseStream(chat) andInvokeModelWithResponseStream(generate_content) as gen_ai spans withgen_ai.response.streaming: true. The finish reason, token usage, and output messages (text, reasoning, and tool calls with streamed JSON arguments) are built from the events the caller receives. The span finishes once, when the stream is:close()d, read or unreadbreak(the iterator'sGeneratorExit)modelStreamErrorExceptionevent or a read error. The error is re-raised unchanged and the span is marked as errored.Decisions the diff doesn't show:
botocore.eventstream.EventStream.__iter__andcloseare patched globally insetup_once. Python looks up__iter__on the class, so it can't be patched per instance. The patch only acts on streams that carry a_sentry_hooksattribute, which this sets on instrumented Bedrock responses. Other event streams, e.g. S3 Select, go throughyield fromunchanged. This is the same approach as the Anthropic integration'sStream._iteratorpatch. The response object and the events the caller gets are untouched.InvokeModelWithResponseStreamchunks are parsed per model family, like JS. Nova chunks reuse the ConverseStream parser, since they share its format. Usage falls back to Bedrock'samazon-bedrock-invocationMetricsin the last chunk. Claude output tokens come frommessage_deltarather thanmessage_start, which JS uses and which reports only the first token.data_collection.gen_ai.outputs(or, withoutdata_collection,send_default_piiwithinclude_prompts) allows recording it. That check, made when the stream starts, is the only gate on streamed outputs. Input messages are gated bydata_collection.gen_ai.inputswhen the request is made, as for the non-streaming calls.InvokeModelWithResponseStreamchunks are skipped quietly. The caller still gets them unchanged.Changelog note
ConverseStreamandInvokeModelWithResponseStreamspans change fromhttp.client/auto.http.boto3togen_ai.chatandgen_ai.generate_content/auto.ai.boto3, and their names change fromaws.bedrock-runtime.ConverseStreamandaws.bedrock-runtime.InvokeModelWithResponseStreamtochat <modelId>andgenerate_content <modelId>, which affectsignore_spansrules that match on the name.Boto3Integrationis auto-enabled, so users withsend_default_pii=Truestart sending streamed prompts and responses unless they setBoto3Integration(include_prompts=False)or configuredata_collection.Issues
bedrock-agent-runtime(InvokeAgent) remains a follow-up.via @dcramer.
--
View Session [Sentry]