Skip to content

feat(server-utils): Port Bedrock aws-sdk extension and add integration tests#22166

Open
andreiborza wants to merge 2 commits into
ab/aws-sdk-serverlessfrom
ab/aws-sdk-bedrock
Open

feat(server-utils): Port Bedrock aws-sdk extension and add integration tests#22166
andreiborza wants to merge 2 commits into
ab/aws-sdk-serverlessfrom
ab/aws-sdk-bedrock

Conversation

@andreiborza

@andreiborza andreiborza commented Jul 9, 2026

Copy link
Copy Markdown
Member

Ports the BedrockRuntime gen_ai service extension from the OTel aws-sdk integration to the orchestrion channel integration: chat span name and request parameters for Converse/ConverseStream, per-model-family request body parsing for InvokeModel/InvokeModelWithResponseStream (titan, nova, claude, llama, cohere, mistral), token usage and finish reasons from responses, and deferred span end for the streaming commands (the span ends when the wrapped stream is consumed).

Adds nock-mocked integration tests for the non-streaming Converse and InvokeModel commands, asserted against both the OTel and diagnostics-channel paths. The streaming commands use the AWS binary eventstream framing which nock cannot mock, so they stay untested here.

This completes orchestrion parity with the OTel aws-sdk integration.

User-facing differences to the vendored OTel instrumentation

  • ConverseStream callers receive the original response object with its stream wrapped in place, instead of a new object (a channel subscriber can't replace the resolved value); relevant only to identity-sensitive code

Fixes #20946

@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from bdc838e to 9297436 Compare July 9, 2026 21:35
@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch 2 times, most recently from 188ac82 to ff165d4 Compare July 9, 2026 21:44
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from 9297436 to 31816fd Compare July 9, 2026 21:44
@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch from ff165d4 to a4dd353 Compare July 9, 2026 21:48
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from 31816fd to 0b89e37 Compare July 9, 2026 21:48
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.74 kB - -
@sentry/browser - with treeshaking flags 26.19 kB - -
@sentry/browser (incl. Tracing) 46.57 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.36 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.34 kB - -
@sentry/browser (incl. Tracing, Replay) 85.83 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.46 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 90.55 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 103.18 kB - -
@sentry/browser (incl. Feedback) 44.92 kB - -
@sentry/browser (incl. sendFeedback) 32.54 kB - -
@sentry/browser (incl. FeedbackAsync) 37.67 kB - -
@sentry/browser (incl. Metrics) 28.84 kB - -
@sentry/browser (incl. Logs) 29.07 kB - -
@sentry/browser (incl. Metrics & Logs) 29.76 kB - -
@sentry/react 29.54 kB - -
@sentry/react (incl. Tracing) 48.82 kB - -
@sentry/vue 33.17 kB - -
@sentry/vue (incl. Tracing) 48.55 kB - -
@sentry/svelte 27.77 kB - -
CDN Bundle 30.14 kB - -
CDN Bundle (incl. Tracing) 48.52 kB - -
CDN Bundle (incl. Logs, Metrics) 31.72 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.83 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.97 kB - -
CDN Bundle (incl. Tracing, Replay) 86.04 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.33 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.82 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 93.09 kB - -
CDN Bundle - uncompressed 89.85 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.66 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.56 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.64 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.28 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.86 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.82 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.56 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 283.52 kB - -
@sentry/nextjs (client) 51.38 kB - -
@sentry/sveltekit (client) 47 kB - -
@sentry/core/server 78.71 kB - -
@sentry/core/browser 65.08 kB - -
@sentry/node-core 63.21 kB - -
@sentry/node 125.45 kB - -
⛔️ @sentry/node (incl. diagnostics channel injection) (max: 146 kB) 147.36 kB +3.34% +4.75 kB 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.03 kB - -
@sentry/node/light 51.33 kB -0.01% -1 B 🔽
@sentry/node - without tracing 74.7 kB - -
@sentry/aws-serverless 83.92 kB - -
@sentry/cloudflare (withSentry) - minified 182.1 kB - -
@sentry/cloudflare (withSentry) 450.9 kB - -

View base workflow run

@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch from a4dd353 to 968db2f Compare July 9, 2026 22:11
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from 0b89e37 to a3978fa Compare July 9, 2026 22:11
@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch from 968db2f to 5f2a15f Compare July 9, 2026 22:14
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch 2 times, most recently from 809da29 to 8907ff9 Compare July 9, 2026 22:31
@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch from 5f2a15f to 8f3599b Compare July 9, 2026 22:31
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from 8907ff9 to c0e10d6 Compare July 9, 2026 22:46
@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch from 8f3599b to 0a944ab Compare July 9, 2026 22:46
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from c0e10d6 to 561e41b Compare July 9, 2026 22:55
@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch from 0a944ab to 5506257 Compare July 9, 2026 22:55
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from 561e41b to 8ffb46b Compare July 9, 2026 23:02
@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch 2 times, most recently from 14699e8 to a464258 Compare July 10, 2026 07:40
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch 2 times, most recently from 556da6f to 9f3cab7 Compare July 10, 2026 12:14
@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch 2 times, most recently from 2849cfe to 8e57368 Compare July 10, 2026 14:39
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from 9f3cab7 to ab2bf1b Compare July 10, 2026 14:39
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch 2 times, most recently from 506ad88 to 8b3b56a Compare July 10, 2026 18:04
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch 2 times, most recently from a982908 to 6a1e720 Compare July 15, 2026 11:20
@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch 3 times, most recently from d096bd6 to 7813fbf Compare July 15, 2026 13:05
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from 209ce0f to 58a581d Compare July 15, 2026 13:05
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch 2 times, most recently from d00cea8 to aa8192c Compare July 15, 2026 13:37
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from aa8192c to 19a3e72 Compare July 15, 2026 13:40
@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch 2 times, most recently from db6d0a5 to 86f20c1 Compare July 15, 2026 13:54
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from 19a3e72 to aa8192c Compare July 15, 2026 13:54

@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 86f20c1. Configure here.

@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from aa8192c to f3c38b1 Compare July 15, 2026 14:18
@andreiborza andreiborza force-pushed the ab/aws-sdk-bedrock branch 2 times, most recently from ee60599 to a94d0e5 Compare July 15, 2026 14:49
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from f3c38b1 to aa8192c Compare July 15, 2026 14:49
@andreiborza andreiborza force-pushed the ab/aws-sdk-serverless branch from aa8192c to 4a24188 Compare July 15, 2026 15:18

@nicohrubec nicohrubec left a comment

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.

nice, didn't know that we support this already

Comment on lines +251 to +255
private _responseHookConverseStream(response: NormalizedResponse, span: Span): void {
// Wrap and replace the response stream in place to process events into telemetry
// before yielding to the user.
response.data.stream = wrapConverseStreamResponse(response.data.stream, span);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The function _responseHookConverseStream accesses response.data.stream without checking if response.data is defined, which can cause a TypeError and a subsequent span leak.
Severity: HIGH

Suggested Fix

Add guards in _responseHookConverseStream and _responseHookInvokeModelWithResponseStream to check that response.data is not null or undefined before attempting to access its properties and wrap the stream.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
packages/server-utils/src/integrations/tracing-channel/aws-sdk/services/bedrock-runtime.ts#L251-L255

Potential issue: The `_responseHookConverseStream` function in `bedrock-runtime.ts`
accesses `response.data.stream` without verifying that `response.data` is defined. The
`response.data` object can be `undefined` as it originates from `data.result` in
`index.ts`, which is not guaranteed to be present. This can lead to a `TypeError`.
Although the error is caught by a `safe()` wrapper, the logic proceeds to defer the
span's closing. Because the stream wrapping that would normally close the span never
completes due to the error, the span is never closed, causing a span leak. A similar
issue exists in `_responseHookInvokeModelWithResponseStream`.

Also affects:

  • packages/server-utils/src/integrations/tracing-channel/aws-sdk/services/bedrock-runtime.ts:330

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.

Rewrite @opentelemetry/instrumentation-aws-sdk to orchestrion

2 participants