Repository navigation
feat(boto3): Instrument Bedrock Runtime InvokeModel calls as gen_ai spans - #8187
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 📊✅ 139002 passed | ⏭️ 7497 skipped | Total: 146499 | Pass Rate: 94.88% | Execution Time: 475m 40s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 96.00% (240 of 250 changed executable lines covered; target 80%). Changed files with executable lines (5)
Coverage diff@@ Coverage Diff @@
## master #8187 +/-##
==========================================
+ Coverage 90.33% 90.44% +0.11%
==========================================
Files 203 204 +1
Tracked lines 26905 27350 +445
Branches 10048 10286 +238
==========================================
+ Hits 24302 24734 +432
- Misses 2603 2616 +13
- Partials 1516 1554 +38Generated by Coverage Action |
sentry-junior
Bot
force-pushed
the
junior/boto3-bedrock-invoke-model
branch
4 times, most recently
from
November 5, 2026 00:29
8400b94 to
79fee6a
Compare
sentry-junior
Bot
force-pushed
the
junior/boto3-bedrock-invoke-model
branch
2 times, most recently
from
November 5, 2026 01:16
a029b59 to
77e635d
Compare
…pans Record InvokeModel calls as `gen_ai.generate_content` spans. Request and response bodies are parsed per model family (Anthropic Claude, Amazon Nova and Titan, Meta Llama, Cohere Command and Command R, Mistral), matching the JavaScript SDK. The response body is recorded as the caller reads it, so it isn't consumed or replaced, and the span finishes once it's read or closed. Token usage falls back to Bedrock's usage response headers. Refs #5470 Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
Don't parse `InvokeModel` request bodies over 1 MB, e.g. requests with images, and ignore malformed ones quietly, like response bodies. Test that media content of Claude and Nova requests isn't recorded. Refs #5470 Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
sentry-junior
Bot
force-pushed
the
junior/boto3-bedrock-invoke-model
branch
from
November 5, 2026 01:41
77e635d to
b8c2634
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 (2 of 3, stacked on #8186) records
InvokeModelas agenerate_content {modelId}span with opgen_ai.generate_content(newOP.GEN_AI_GENERATE_CONTENT). It matches the JS SDK.The request and response bodies have a model-specific format. Like JS, this parses them per model family: Anthropic Claude (including inference profile IDs like
us.anthropic...), Amazon Nova and Titan, Meta Llama, Cohere Command and Command R, and Mistral. Prompts and responses use the same gating as Converse:data_collection.gen_ai.inputs/outputsindependently, elsesend_default_piiwithinclude_prompts.Decisions the diff doesn't show:
StreamingBodyobject. Instead,body.read,body.close, andbody._raw_stream.closeare patched on that instance, the same approach the S3 instrumentation on master uses._patch_streaming_body()is extracted from it for this. The bytes are recorded as the caller reads them (read(),read(amt),iter_chunks()), and the span finishes when the body is fully read, closed, or a read fails. A new_ServiceExtension.instrument_response()hook lets an extension take over finishing the span.x-amzn-bedrock-input/output-token-countresponse headers when the body has none (Cohere, Mistral, unknown models, early close). This replaces JS'schars / 6estimates.get_span_start_attributes(), for its parameters and input messages, so its parameters aren't visible toignore_spansand spans it drops skip the parse.MAX_INVOKE_MODEL_BODY_BYTES) aren't parsed, e.g. requests with images or image generation results; response usage still comes from the headers. Malformed JSON bodies are skipped quietly.tool_result, and Nova images) aren't recorded.Changelog note
InvokeModelspans change fromhttp.client/auto.http.boto3togen_ai.generate_content/auto.ai.boto3, and their name changes fromaws.bedrock-runtime.InvokeModeltogenerate_content <modelId>, which affectsignore_spansrules that match on the name.Boto3Integrationis auto-enabled, so users withsend_default_pii=Truestart sendingInvokeModelprompts and responses unless they setBoto3Integration(include_prompts=False)or configuredata_collection.Issues
amazon.titan-embedmodels match the Titan text family, so they get agenerate_contentspan rather than an embeddings span, and newer Mistral chat formats (messages/choices) aren't parsed.via @dcramer.
--
View Session [Sentry]