Repository navigation
feat(boto3): Instrument Bedrock Runtime Converse calls as gen_ai spans - #8186
Draft
sentry-junior[bot] wants to merge 7 commits into
Draft
sentry-junior[bot] wants to merge 7 commits into
sentry-junior[bot] wants to merge 7 commits into
Conversation
Record Bedrock Runtime `Converse` calls as `gen_ai.chat` spans with the `auto.ai.boto3` origin, the request model and inference parameters, token usage, and finish reasons. Input and output messages, system instructions, and tool definitions are recorded when `data_collection` allows gen_ai inputs/outputs, or with `send_default_pii` when `data_collection` isn't set. Adds a `get_span_name()` hook to `_ServiceExtension`. Refs #5470 Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
Record Bedrock prompts and responses like the other gen_ai integrations: `data_collection.gen_ai.inputs`/`outputs` decide when `data_collection` is set, otherwise `send_default_pii` and the new `include_prompts` option of Boto3Integration do. Refs #5470 Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
Contributor
Coverage Results 📊✅ 138456 passed | ⏭️ 7497 skipped | Total: 145953 | Pass Rate: 94.86% | Execution Time: 451m 35s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 96.37% (239 of 248 changed executable lines covered; target 80%). Changed files with executable lines (7)
Coverage diff@@ Coverage Diff @@
## master #8186 +/-##
==========================================
+ Coverage 90.32% 90.38% +0.06%
==========================================
Files 203 204 +1
Tracked lines 26905 27151 +246
Branches 10048 10186 +138
==========================================
+ Hits 24302 24540 +238
- Misses 2603 2611 +8
- Partials 1516 1544 +28Generated by Coverage Action |
…tegrations When gen_ai spans are sent in transactions (`should_truncate_gen_ai_input()`), keep only the last input message with `truncate_and_annotate_messages()`, like the Anthropic and OpenAI integrations, so long histories don't exceed the transaction size limit. The helper needs the started span, so request data is now added through a new `_ServiceExtension.get_span_start_attributes()` hook. Refs #5470 Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
`truncate_and_annotate_messages()` only truncates a message's `content`, so when only the last input message is kept, its text parts were kept in full. Truncate them to `MAX_SINGLE_MESSAGE_CONTENT_CHARS` with the same `...` suffix. Only the input messages need the started span, so the request parameters, system instructions, and tool definitions are request attributes again. Messages aren't transformed for spans that won't be sent. Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
sentry-junior
Bot
force-pushed
the
junior/boto3-bedrock-converse
branch
from
November 5, 2026 00:29
886ef2a to
1057e9c
Compare
The last input message's text was capped, but its tool call arguments and tool results weren't, so a huge tool result, which is usually the last message in agent loops, was kept in full. They now share the message's limit with its text. Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
…esults Only string tool call arguments and tool results were capped, so a large JSON tool input or result was kept in full. JSON values now count with their serialized length, and are replaced by their truncated serialization when they don't fit. Co-Authored-By: Sergiy Dybskiy <3760543+sergical@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.
Description
This is the first of 3 stacked PRs that add AWS Bedrock Runtime gen_ai instrumentation to
Boto3Integration, so Bedrock calls appear in AI Agents monitoring. Spans, ops, and attributes match the JS SDK'saws-sdkBedrock Runtime extension (packages/server-utils/src/integrations/aws-sdk/services/bedrock-runtime.ts).This PR covers
Converse, using the existing_servicesextension registry:chat {modelId}, opgen_ai.chat,gen_ai.provider.name=aws.bedrockSPANDATA.GEN_AI_REQUEST_STOP_SEQUENCES), finish reasons, and token usageget_span_name()hook to_ServiceExtensionDecisions the diff doesn't show:
auto.ai.boto3, not the genericauto.http.boto3. It follows the trace-origin spec (auto.<category>.<integration>). JS usesauto.ai.aws_sdkfor the same spans. Other bedrock-runtime operations keep the generic HTTP span.data_collectionoption. Whendata_collectionis set,data_collection.gen_ai.inputsgates system instructions, input messages, and tool definitions, anddata_collection.gen_ai.outputsgates output messages (text, reasoning, tool calls). Each is gated independently. Withoutdata_collection, both requiresend_default_piiand the newBoto3Integration(include_prompts=True)option, which defaults toTrue. JS capture is in progress in feat(server-utils): Record Bedrock prompts, tools, and responses sentry-javascript#26118.data_collectionisn't set (a legacy branch kept untilsend_default_piiis deprecated).should_truncate_gen_ai_input()is true (gen_ai spans sent in transactions),truncate_and_annotate_messagesreduces the history to the last message. The text, tool call arguments, and tool results of that message's parts are then capped atMAX_SINGLE_MESSAGE_CONTENT_CHARSin total, with the same...suffix, in the Bedrock code: the shared helper only caps a top-levelcontent, notparts. The original-length_metaannotation doesn't apply togen_ai.input.messagesyet, and teaching the shared helper aboutpartsis a follow-up._ServiceExtension.get_span_start_attributes()hook, because truncation needs the started span.ignore_spansdoesn't see them, and spans it drops skip that work. Max tokens, temperature, top_p, stop sequences, system instructions, and tool definitions stay request attributes.gen_ai.usage.input_tokensincludes cache read/write tokens. Bedrock'sinputTokensexcludes them, so this differs from JS only for prompt-cached requests.Stack: this PR → InvokeModel → streaming (ConverseStream + InvokeModelWithResponseStream).
Heads-up:
major/3.0has diverged boto3 service-extension work (_services/*,_utils.py), so porting this there will need conflict resolution.Changelog note
Conversespans change fromhttp.client/auto.http.boto3togen_ai.chat/auto.ai.boto3, and their name changes fromaws.bedrock-runtime.Conversetochat <modelId>, which affectsignore_spansrules that match on the name.Boto3Integrationis auto-enabled, so users withsend_default_pii=Truestart sendingConverseprompts and responses unless they setBoto3Integration(include_prompts=False)or configuredata_collection.Issues
bedrock-agent-runtime(InvokeAgent) is a follow-up.via @dcramer.
--
View Session [Sentry]