Skip to content

ref(server-utils): Use shared stream state and endStreamSpan for Bedrock streams - #26192

Merged
andreiborza merged 9 commits into
developfrom
ab/bedrock-shared-stream-state
Nov 10, 2026
Merged

andreiborza merged 9 commits into
developfrom
ab/bedrock-shared-stream-state

Conversation

@andreiborza

Copy link
Copy Markdown
Member

What

Bedrock ConverseStream and InvokeModelWithResponseStream spans now collect stream data into the shared stream state and end through endStreamSpan, like the other AI integrations. Stream spans now also get gen_ai.response.streaming and a total token count for all model families.

Why

The shared state is the base for recording Bedrock outputs in a later PR, and it makes Bedrock stream spans consistent with the other AI integrations.

Extracted from #26118.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a236111. Configure here.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: f206027 (PR test merge using develop at 2e4231e)

Against: 2e4231e (develop) · base run #65527

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 29.92 kB - -
@sentry/browser - with treeshaking flags 28.08 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.97 kB - -
@sentry/browser (incl. Tracing) 52.29 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.3 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.27 kB - -
@sentry/browser (incl. Tracing, Replay) 92.7 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.37 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.43 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.42 kB - -
@sentry/browser (incl. Feedback) 47.52 kB - -
@sentry/browser (incl. sendFeedback) 35.02 kB - -
@sentry/browser (incl. FeedbackAsync) 40.13 kB - -
@sentry/browser (incl. Metrics) 31.48 kB - -
@sentry/browser (incl. Logs) 31.77 kB - -
@sentry/browser (incl. Metrics & Logs) 32.45 kB - -
@sentry/react 31.78 kB - -
@sentry/react (incl. Tracing) 54.76 kB - -
@sentry/vue 38.33 kB - -
@sentry/vue (incl. Tracing) 55.33 kB - -
@sentry/svelte 29.95 kB - -
@sentry/remix (Remix 3 client bundle) 57.92 kB - -
CDN Bundle 31.72 kB - -
CDN Bundle (incl. Tracing) 52.89 kB - -
CDN Bundle (incl. Logs, Metrics) 34.52 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.39 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 76 kB - -
CDN Bundle (incl. Tracing, Replay) 91.17 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.72 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.3 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.89 kB - -
CDN Bundle - uncompressed 92.76 kB - -
CDN Bundle (incl. Tracing) - uncompressed 156.02 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.29 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.79 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 233.18 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 278.04 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.8 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 291.74 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 299.5 kB - -
@sentry/nextjs (client) 57.73 kB - -
@sentry/sveltekit (client) 52.82 kB - -
@sentry/core/server 44.29 kB - -
@sentry/core/browser 14.02 kB - -
@sentry/node 157.41 kB +0.01% +13 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.28 kB - -
@sentry/node - without tracing 97.17 kB +0.03% +26 B 🔺
@sentry/node - without channel injection 137.69 kB +0.01% +12 B 🔺
@sentry/aws-serverless 106 kB +0.16% +160 B 🔺
@sentry/cloudflare (withSentry) - minified 203.34 kB - -
@sentry/cloudflare (withSentry) 505.12 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 225.19 kB - -

View base workflow run

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 6 not successful, 51 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Failing after 57s Details
❌ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Failing after 3m Details
❌ CI: Optional E2E Tests / E2E nextjs-16-cacheComponents (cloudflare) Test (optional) Failing after 10m Details
❌ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Failing after 51s Details
❌ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Failing after 40s Details
❌ CI: Optional E2E Tests / E2E node-eve Test (optional) Failing after 3m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 57s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 50s Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 50s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 53s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 58s Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 47s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 40s Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-cloudflare Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (tunnel-dev) Test (optional) Successful in 59s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 41s Details

Base automatically changed from ab/bedrock-stream-scenario to develop November 9, 2026 08:21
andreiborza and others added 2 commits November 9, 2026 09:22
…stream-state

# Conflicts:
#	dev-packages/node-integration-tests/suites/aws-serverless/bedrock/test.ts
@andreiborza
andreiborza marked this pull request as ready for review November 9, 2026 15:26
@andreiborza
andreiborza requested a review from a team as a code owner November 9, 2026 15:27
@andreiborza
andreiborza requested review from JPeer264, chargome, isaacs, mydea and nicohrubec and removed request for a team November 9, 2026 15:27
@@ -291,6 +291,31 @@ describe('BedrockRuntimeServiceExtension token usage with prompt caching', () =>
expect(usageAttributes(span, EXPECTED_USAGE)).toEqual(EXPECTED_USAGE);
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: titan, llama and nova are not tested, we could add a test for each of those to check if they work. Feel free to change the city to Vienna.

Suggested change
it.each([
{
family: 'Llama',
modelId: 'meta.llama3-8b-instruct-v1:0',
chunks: [
{ generation: 'Paris', prompt_token_count: 12, generation_token_count: 1, stop_reason: null },
{ generation: '.', prompt_token_count: null, generation_token_count: 2, stop_reason: 'stop' },
],
expected: {
[GEN_AI_USAGE_INPUT_TOKENS]: 12,
[GEN_AI_USAGE_OUTPUT_TOKENS]: 2,
[GEN_AI_USAGE_TOTAL_TOKENS]: 14,
[GEN_AI_RESPONSE_FINISH_REASONS]: '["stop"]',
},
},
{
family: 'Titan',
modelId: 'amazon.titan-text-express-v1',
chunks: [
{ outputText: 'Paris', totalOutputTextTokenCount: null, completionReason: null, inputTextTokenCount: 5 },
{ outputText: '.', totalOutputTextTokenCount: 2, completionReason: 'FINISH', inputTextTokenCount: null },
],
expected: {
[GEN_AI_USAGE_INPUT_TOKENS]: 5,
[GEN_AI_USAGE_OUTPUT_TOKENS]: 2,
[GEN_AI_USAGE_TOTAL_TOKENS]: 7,
[GEN_AI_RESPONSE_FINISH_REASONS]: '["FINISH"]',
},
},
{
family: 'Nova',
modelId: 'amazon.nova-lite-v1:0',
chunks: [
{ contentBlockDelta: { delta: { text: 'Paris' }, contentBlockIndex: 0 } },
{ messageStop: { stopReason: 'end_turn' } },
{ metadata: { usage: { inputTokens: 7, outputTokens: 2 }, metrics: {}, trace: {} } },
],
expected: {
[GEN_AI_USAGE_INPUT_TOKENS]: 7,
[GEN_AI_USAGE_OUTPUT_TOKENS]: 2,
[GEN_AI_USAGE_TOTAL_TOKENS]: 9,
[GEN_AI_RESPONSE_FINISH_REASONS]: '["end_turn"]',
},
},
])('records token usage and finish reasons for a $family stream', async ({ modelId, chunks, expected }) => {
const span = startInactiveSpan({ name: 'bedrock' });
const encoder = new TextEncoder();
const data = {
body: (async function* () {
for (const chunk of chunks) {
yield { chunk: { bytes: encoder.encode(JSON.stringify(chunk)) } };
}
})(),
};
respond(span, 'InvokeModelWithResponseStream', { modelId }, data);
await drain(data.body);
expect(spanToJSON(span).attributes).toMatchObject(expected);
});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, with Kawasaki as the city.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 9a4006d

@andreiborza
andreiborza requested a review from a team November 10, 2026 14:04
@andreiborza
andreiborza merged commit 9154110 into develop Nov 10, 2026
431 of 437 checks passed
@andreiborza
andreiborza deleted the ab/bedrock-shared-stream-state branch November 10, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants