Repository navigation
feat(server-utils): Record Bedrock prompts, tools, and responses - #26118
Draft
sentry-junior[bot] wants to merge 5 commits into
Draft
sentry-junior[bot] wants to merge 5 commits into
sentry-junior[bot] wants to merge 5 commits into
Conversation
The Bedrock Runtime extension now records gen_ai.input.messages,
gen_ai.system_instructions, gen_ai.tool.definitions, and
gen_ai.output.messages for Converse, ConverseStream, InvokeModel, and
InvokeModelWithResponseStream, gated by dataCollection.genAI or the new
awsIntegration({ recordInputs, recordOutputs }) options.
Also fixes InvokeModel calls with a non-JSON body or no modelId that
skipped the span, prompt-cache tokens missing from input tokens, Claude
stream output tokens read from the message_start placeholder, Mistral
and Cohere stream token estimates that used only the last chunk, and
stream failures that left the span status ok or the span open.
Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
Contributor
size-limit report 📦Compared: 706009f (PR test merge using develop at 88a5e3b) Against: 88a5e3b (develop) · base run #65049 ✅ Baseline matches: this diff contains only this PR's changes.
|
Contributor
|
One or more gzipped bundles increased by more than 500 bytes. If this increase is intentional, add the Accept Bundlesize Increase label to this PR to rerun and accept the check. |
…ions for Bedrock Runs both the plain and the streaming Bedrock scenarios against the default (recorded), `dataCollection.genAI.inputs: false`, `dataCollection.genAI.outputs: false`, and `awsIntegration()` options overriding `dataCollection.genAI` in both directions. Also checks that the setting is read from the client current at call time. Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
Contributor
Optional E2E testsSome optional checks were not successful. They do not block the merge. 4 not successful, 50 successful. See the run.
Successful checks
|
…without outputs Claude InvokeModel bodies carry images and documents as base64 source data, including inside tool results. Record them as blob parts instead. Streams no longer buffer response content when outputs are not recorded; token approximation counts characters without keeping the text. Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
6 tasks
…ral stream totals The input estimate went onto the span in the request hook but never reached the stream state, so the total for a streamed Cohere or Mistral call only counted output tokens. Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
…Cohere and Mistral 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.
Why: Bedrock
gen_aispans carried only the model, params, and usage, while the other AI integrations also record prompts and responses. This PR recordsgen_ai.input.messages,gen_ai.system_instructions,gen_ai.tool.definitions, andgen_ai.output.messagesfor Converse, ConverseStream, InvokeModel, and InvokeModelWithResponseStream. It also sets the deprecatedgen_ai.response.textandgen_ai.response.tool_calls, asendStreamSpandoes.Capture follows
dataCollection.genAI, throughresolveAIRecordingOptionslike the other providers. Inputs and outputs are recorded by default (dataCollection.genAIdefaults to on), so Bedrock prompts and responses become recorded by default once this ships. This needs an Important Changes note in the release.dataCollection: { genAI: { inputs: false } }turns off prompts, system instructions, and tool definitions, andoutputs: falseturns off responses.awsIntegration({ recordInputs, recordOutputs })takes precedence over both and applies only to Bedrock spans. The setting is read per call, so it does not matter whether the client exists when the integration is built. Nothing else indataCollectionapplies here. No other AI provider readsuserInfo, and Bedrock records no user fields.Converse and Nova messages are mapped to
{role, parts}. Claude InvokeModel messages are recorded as sent, as the Anthropic integration does, except that image and document blocks (also insidetool_result) are replaced withblobparts so their base64 data is never recorded. Titan, Llama, Mistral, and Cohere prompts become a single user text part.Bugs found along the way and fixed here:
modelIdthrew and dropped the span.message_startplaceholder.ok, and a missing stream body left the span open.The stream tests hand-encode AWS eventstream frames, so nock can mock streaming after all.
How to review: Start with
bedrock-runtime-content.ts, which has the mapping, then read the response hooks inbedrock-runtime.ts.scenario-stream.mjsis mostly frame-encoding boilerplate. The integration tests run the plain and streaming scenarios against the default,inputs: false,outputs: false, and an integration option overridingdataCollectionin each direction.Unsure about:
recordInputs/recordOutputsonawsIntegration. They only affect Bedrock, but nesting them underbedrockfelt heavier.gen_ai.response.finish_reasonsis now a JSON string ('["end_turn"]'), matching the conventions type and the other integrations. It used to be an array attribute.blobparts with a modality (and MIME type when known) and no bytes. Cache points and unknown Converse blocks are dropped. Streams only buffer response content when outputs are recorded.via @sergical.
--
View Session [Sentry]