Skip to content

feat(aws-serverless): Instrument aws-sdk clients >= 3.1046.0#21548

Merged
mydea merged 3 commits into
developfrom
fix/aws-sdk-smithy-core-instrumentation
Jun 15, 2026
Merged

feat(aws-serverless): Instrument aws-sdk clients >= 3.1046.0#21548
mydea merged 3 commits into
developfrom
fix/aws-sdk-smithy-core-instrumentation

Conversation

@mydea

@mydea mydea commented Jun 15, 2026

Copy link
Copy Markdown
Member

The vendored @opentelemetry/instrumentation-aws-sdk had almost no test coverage — only S3 PutObject was exercised, leaving DynamoDB, SQS, SNS, Lambda, Kinesis, SecretsManager and StepFunctions (~97% of the service-extension code) completely untested.

This adds nock-based integration tests (mirroring the existing S3 test) that lock in the current span output (name, op, origin, and service-specific attributes) for every service the SDK instruments:

  • S3 — expanded to PutObject, GetObject, and an errored GetObject (status: internal_error)
  • DynamoDB — PutItem + Query (op: db, db.* + aws.dynamodb.*)
  • SQS — SendMessage + ReceiveMessage (messaging.*, PRODUCER/CONSUMER, message id, batch count)
  • SNS — Publish (messaging.*, topic ARN)
  • Lambda — Invoke (faas.*)
  • Kinesis — PutRecord (stream name)
  • SecretsManager — GetSecretValue (secret ARN)
  • StepFunctions — StartExecution (state machine ARN)

This showed that actually we did not instrument newer versions of the AWS SDK. So this PR also vendors a fix for this from the upstream otel instrumentation. Integration tests run for both sets of versions.

@smithy/core@3.24.0 moved the Client class out of @smithy/smithy-client into the @smithy/core/client bundle and turned constructStack into a closed-over local. Our vendored aws-sdk instrumentation creates spans by wrapping constructStack (exported from @smithy/middleware-stack), so it silently produced no spans for any AWS service on @aws-sdk/* >= 3.1046.0. See #21546 for the full root-cause writeup.

This backports the upstream fix (open-telemetry/opentelemetry-js-contrib#3530, released in @opentelemetry/instrumentation-aws-sdk@0.74.0):

  • Patch Client.prototype.send in @smithy/core/dist-cjs/submodules/client/index.js for @smithy/core >= 3.24.0.
  • From within the send patch, patch the live middlewareStack instance directly (its resolve is the span-creation point) rather than the no-longer-patchable constructStack export.
  • Guard clone/concat wrapping with isWrapped so repeated patching is safe.

Fixes #21546

…strumentation

The vendored `@opentelemetry/instrumentation-aws-sdk` had almost no test
coverage - only S3 `PutObject` was exercised, leaving DynamoDB, SQS, SNS,
Lambda, Kinesis, SecretsManager and StepFunctions (~97% of the service
extension code) completely untested.

This adds `nock`-based integration tests (mirroring the existing S3 test)
covering the span name, op, origin and service-specific attributes for each
service the SDK instruments:

* S3 - expanded to PutObject, GetObject and an errored GetObject
* DynamoDB - PutItem + Query (db.* attributes, op `db`)
* SQS - SendMessage + ReceiveMessage (messaging.* attributes, PRODUCER/CONSUMER)
* SNS - Publish (messaging.* attributes, topic ARN)
* Lambda - Invoke (faas.* attributes)
* Kinesis - PutRecord (stream name)
* SecretsManager - GetSecretValue (secret ARN)
* StepFunctions - StartExecution (state machine ARN)

This is step 1 of streamlining the vendored aws-sdk instrumentation - the
tests lock in current behavior so the upcoming cleanup and Sentry-API
migration can be done safely.

Notes:
* The new `@aws-sdk/client-*` packages are pinned to `3.1041.0` (matching the
  existing S3 dep) because newer clients route through `@smithy/core`, which
  the current instrumentation does not patch.
* The Kinesis client is forced onto the HTTP/1 request handler because it
  defaults to HTTP/2, which `nock` cannot intercept.

Addresses step 1 of #20944

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mydea mydea force-pushed the fix/aws-sdk-smithy-core-instrumentation branch from f5a2d59 to 8b34564 Compare June 15, 2026 13:26
… 3.24.0

`@smithy/core@3.24.0` moved the `Client` class out of `@smithy/smithy-client`
into the `@smithy/core/client` bundle and turned `constructStack` into a
closed-over local, so the vendored instrumentation - which created spans by
wrapping `constructStack` exported from `@smithy/middleware-stack` - silently
produced no spans for any AWS service on `@aws-sdk/*` >= 3.1046.0.

This backports the upstream fix (open-telemetry/opentelemetry-js-contrib#3530,
released in @opentelemetry/instrumentation-aws-sdk@0.74.0):

* Patch `Client.prototype.send` in `@smithy/core/dist-cjs/submodules/client/index.js`
  for `@smithy/core` >= 3.24.0.
* From within the `send` patch, patch the live `middlewareStack` instance
  directly (its `resolve` is the span-creation point) instead of relying on the
  no-longer-patchable `constructStack` export.
* Guard `clone`/`concat` wrapping with `isWrapped` so repeated patching is safe.

The aws-integration tests are consolidated into a single scenario that exercises
all instrumented services, and run via `createEsmAndCjsTests` + `describe.each`
against two dependency sets:

* `latest` - the workspace `@aws-sdk/*` (`@smithy/core` >= 3.24.0, the new path)
* `v3.1041.0` - aws-sdk 3.1041.0 pinned together with the pre-`@smithy/core`
  smithy stack via `additionalDependencies`, exercising the old
  `@smithy/middleware-stack` path

Both run the same assertions in ESM and CJS, proving spans are produced on both
architectures. Pinning only the client is not enough - `@smithy/smithy-client`
must also be pinned < 4.13, otherwise it pulls `@smithy/core` >= 3.24.0 again.

Fixes #21546

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mydea mydea force-pushed the fix/aws-sdk-smithy-core-instrumentation branch from 8b34564 to b2ced23 Compare June 15, 2026 13:29
@mydea mydea requested a review from andreiborza June 15, 2026 13:31
@mydea mydea changed the base branch from test/aws-sdk-instrumentation-coverage to develop June 15, 2026 13:32
@mydea mydea self-assigned this Jun 15, 2026
@mydea mydea marked this pull request as ready for review June 15, 2026 13:34
@mydea mydea requested a review from a team as a code owner June 15, 2026 13:34
@mydea mydea requested review from JPeer264 and removed request for a team June 15, 2026 13:34
@mydea mydea changed the title fix(aws-serverless): Instrument aws-sdk clients using @smithy/core >= 3.24.0 feat(aws-serverless): Instrument aws-sdk clients using @smithy/core >= 3.24.0 Jun 15, 2026
@mydea mydea changed the title feat(aws-serverless): Instrument aws-sdk clients using @smithy/core >= 3.24.0 feat(aws-serverless): Instrument aws-sdk clients >= 3.1046.0 Jun 15, 2026
Comment thread packages/aws-serverless/src/integration/aws/vendored/aws-sdk.ts
@mydea mydea force-pushed the fix/aws-sdk-smithy-core-instrumentation branch from b2ced23 to f5d221f Compare June 15, 2026 14:06
@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.4 kB - -
@sentry/browser - with treeshaking flags 25.84 kB - -
@sentry/browser (incl. Tracing) 45.7 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.94 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.5 kB - -
@sentry/browser (incl. Tracing, Replay) 84.92 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.53 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.61 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.3 kB - -
@sentry/browser (incl. Feedback) 44.56 kB - -
@sentry/browser (incl. sendFeedback) 32.2 kB - -
@sentry/browser (incl. FeedbackAsync) 37.31 kB - -
@sentry/browser (incl. Metrics) 28.47 kB - -
@sentry/browser (incl. Logs) 28.71 kB - -
@sentry/browser (incl. Metrics & Logs) 29.4 kB - -
@sentry/react 29.2 kB - -
@sentry/react (incl. Tracing) 48 kB - -
@sentry/vue 32.42 kB - -
@sentry/vue (incl. Tracing) 47.59 kB - -
@sentry/svelte 27.42 kB - -
CDN Bundle 29.79 kB - -
CDN Bundle (incl. Tracing) 48.2 kB - -
CDN Bundle (incl. Logs, Metrics) 31.33 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.49 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.62 kB - -
CDN Bundle (incl. Tracing, Replay) 85.52 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.37 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.62 kB - -
CDN Bundle - uncompressed 88.59 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.8 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.29 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.77 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.12 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.67 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.63 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.37 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.31 kB - -
@sentry/nextjs (client) 50.45 kB - -
@sentry/sveltekit (client) 46.12 kB - -
@sentry/core/server 76.08 kB - -
@sentry/core/browser 63.22 kB - -
@sentry/node-core 61.72 kB - -
@sentry/node 130.45 kB +0.01% +1 B 🔺
@sentry/node - without tracing 74.11 kB +0.01% +1 B 🔺
@sentry/aws-serverless 86.35 kB +0.08% +64 B 🔺
@sentry/cloudflare (withSentry) - minified 173.69 kB - -
@sentry/cloudflare (withSentry) 433.85 kB - -

View base workflow run

@mydea mydea force-pushed the fix/aws-sdk-smithy-core-instrumentation branch from f5d221f to 0cf5876 Compare June 15, 2026 14:31
@mydea mydea merged commit 72b3aed into develop Jun 15, 2026
273 checks passed
@mydea mydea deleted the fix/aws-sdk-smithy-core-instrumentation branch June 15, 2026 14:53
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.

Ensure AWS SDK instrumentation works >= 3.1046.0

2 participants