Skip to content

feat(server-utils): Add orchestrion aws-sdk channel integration core#22142

Open
andreiborza wants to merge 14 commits into
developfrom
ab/aws-sdk-server-utils
Open

feat(server-utils): Add orchestrion aws-sdk channel integration core#22142
andreiborza wants to merge 14 commits into
developfrom
ab/aws-sdk-server-utils

Conversation

@andreiborza

@andreiborza andreiborza commented Jul 9, 2026

Copy link
Copy Markdown
Member

The integration subscribes to the orchestrion:<smithy-pkg>:send channels the transform injects into the smithy Client.prototype.send (@smithy/core, @smithy/smithy-client, @aws-sdk/smithy-client) and emits a client rpc span per command (rpc.system/rpc.method/rpc.service, cloud.region, request id metadata), with a distinct auto.aws.orchestrion.aws_sdk origin.

The per-service extension registry (span names, messaging/db/gen_ai attributes, trace propagation) starts empty and mirrors the OTel integration's ServiceExtension contract; the services are ported one group at a time in the follow-up PRs of this stack.

The OTel instrumentation was only added to the @sentry/aws-serverless SDK, but it is useable in other SDKS so the orchestrion version lives in server-utils now.

User-facing differences to the vendored OTel instrumentation

  • span origin is auto.aws.orchestrion.aws_sdk instead of auto.otel.aws
  • spans started after SQS ReceiveMessage parent to the surrounding span instead of the receive span; receive-to-consumer linkage uses span links (messaging PR)
  • outgoing SQS/SNS/Lambda trace propagation uses sentry-trace/baggage message attributes instead of W3C headers (messaging PR)
  • errored spans may carry aws.request.id/aws.request.extended_id where the OTel path missed them ($metadata fallback)

Part of #20946

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.6 kB - -
@sentry/browser - with treeshaking flags 26.04 kB - -
@sentry/browser (incl. Tracing) 46.35 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.14 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.13 kB - -
@sentry/browser (incl. Tracing, Replay) 85.62 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.26 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 90.33 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.99 kB - -
@sentry/browser (incl. Feedback) 44.78 kB - -
@sentry/browser (incl. sendFeedback) 32.4 kB - -
@sentry/browser (incl. FeedbackAsync) 37.53 kB - -
@sentry/browser (incl. Metrics) 28.68 kB - -
@sentry/browser (incl. Logs) 28.93 kB - -
@sentry/browser (incl. Metrics & Logs) 29.61 kB - -
@sentry/react 29.39 kB - -
@sentry/react (incl. Tracing) 48.62 kB - -
@sentry/vue 33.03 kB - -
@sentry/vue (incl. Tracing) 48.33 kB - -
@sentry/svelte 27.63 kB - -
CDN Bundle 30 kB - -
CDN Bundle (incl. Tracing) 48.33 kB - -
CDN Bundle (incl. Logs, Metrics) 31.58 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.65 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.82 kB - -
CDN Bundle (incl. Tracing, Replay) 85.84 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.16 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.92 kB - -
CDN Bundle - uncompressed 89.33 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.07 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.03 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.05 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.76 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.28 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.24 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.98 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.93 kB - -
@sentry/nextjs (client) 51.17 kB - -
@sentry/sveltekit (client) 46.8 kB - -
@sentry/core/server 78.42 kB - -
@sentry/core/browser 64.77 kB - -
@sentry/node-core 62.73 kB +0.01% +1 B 🔺
@sentry/node 125.35 kB +0.01% +1 B 🔺
@sentry/node (incl. diagnostics channel injection) 140.59 kB +0.69% +959 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.96 kB - -
@sentry/node/light 50.73 kB -0.01% -1 B 🔽
@sentry/node - without tracing 74.04 kB +0.01% +3 B 🔺
@sentry/aws-serverless 83.26 kB +0.01% +1 B 🔺
@sentry/cloudflare (withSentry) - minified 181.58 kB - -
@sentry/cloudflare (withSentry) 449.49 kB - -

View base workflow run

@andreiborza andreiborza force-pushed the ab/aws-sdk-server-utils branch from 6b85478 to ca51438 Compare July 9, 2026 21:22
@andreiborza andreiborza changed the title feat(server-utils): Add orchestrion aws-sdk channel integration feat(server-utils): Add orchestrion aws-sdk channel integration core Jul 9, 2026
Comment thread packages/server-utils/src/integrations/tracing-channel/aws-sdk/index.ts Outdated
Comment thread packages/server-utils/src/integrations/tracing-channel/aws-sdk/index.ts Outdated
Comment thread packages/server-utils/src/integrations/tracing-channel/aws-sdk/constants.ts Outdated
Comment thread packages/server-utils/src/integrations/tracing-channel/aws-sdk/index.ts Outdated

@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 47a0d74. Configure here.

andreiborza and others added 12 commits July 13, 2026 11:15
Adds the core of an OTel-free, orchestrion diagnostics-channel implementation of
the aws-sdk (v3) instrumentation to `@sentry/server-utils`.

The integration subscribes to the `orchestrion:<smithy-pkg>:send` channels the
transform injects into the smithy `Client.prototype.send` (`@smithy/core`,
`@smithy/smithy-client`, `@aws-sdk/smithy-client`) and emits a client rpc span
per command (`rpc.system`/`rpc.method`/`rpc.service`, `cloud.region`, request id
metadata), with a distinct `auto.aws.orchestrion.aws-sdk` origin.

The per-service extension registry (span names, messaging/db/gen_ai attributes,
trace propagation) starts empty; the services are ported one group at a time in
follow-up PRs, mirroring the OTel integration's ServiceExtension contract.

Registered in `channelIntegrations`, so it is reachable via `@sentry/node`'s
`experimentalUseDiagnosticsChannelInjection()`. The `@sentry/aws-serverless`
swap follows at the top of the stack.

Part of #20946

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Peer channel integrations (mysql, ioredis, anthropic) set the op at span start.
Default to rpc, matching what the exporter infers from rpc.service, and let
service extensions override it via RequestMetadata.spanOp where inference
yields a different op.
The return-value override from the vendored OTel path cannot work through a
tracing channel: subscribers cannot replace the value the caller's promise
resolves with, so the subscriber rightly ignores any return value. Type
responseHook as void and document that response changes (e.g. wrapping a
stream) must mutate response.data in place, which is what the extensions do.
The region provider resolves asynchronously while send proceeds; when send
settled first (e.g. an early failure) the fire-and-forget backfill hit an
already-ended span and cloud.region was lost. deferSpanEnd now keeps the span
open until the region promise settles. In the common path the SDK awaits the
region internally before sending, so the promise is long settled and nothing
changes.
Span origins only allow letters, digits, underscores, and dots per segment;
matches the auto.ai.orchestrion.google_genai precedent.
The span is already started at that point; a sync throw bubbling into the
enclosing safe wrapper would discard the span without ending it, leaking an
open span for that AWS call.
Commands with all-optional members can be constructed without an input (e.g.
new ListBucketsCommand()); the OTel path traces those, so default the command
input to an empty object instead of skipping the span. All service extensions
already read the input defensively.
@andreiborza andreiborza force-pushed the ab/aws-sdk-server-utils branch from 61916ca to 828e59f Compare July 13, 2026 09:17
Service hooks mutate commandInput (propagation headers, MessageAttributeNames,
ClientContext); with a detached default those writes never reached the
serialized request for input-less commands on older smithy clients.
@andreiborza andreiborza marked this pull request as ready for review July 13, 2026 12:02
@andreiborza andreiborza requested a review from a team as a code owner July 13, 2026 12:02
@andreiborza andreiborza requested review from JPeer264, isaacs and mydea and removed request for a team July 13, 2026 12:02
Comment on lines +213 to +215
return true;
}

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: A race condition in deferSpanEnd for streaming AWS requests can cause the cloud.region attribute to be lost if region resolution is slower than the stream completion.
Severity: MEDIUM

Suggested Fix

Modify the deferSpanEnd function to ensure that for streaming requests, it also checks for pending region resolution, similar to how it handles non-streaming requests. This involves removing the early return for streams and allowing the logic to fall through to the check that defers the span end until the region promise settles.

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/index.ts#L213-L215

Potential issue: For streaming AWS SDK responses, a race condition can occur due to an
early return in the `deferSpanEnd` function. This function returns `true` for streaming
requests before checking if the AWS region resolution is still pending. If a streaming
operation completes and its corresponding span is ended before the asynchronous region
promise resolves, the subsequent attempt to set the `cloud.region` attribute on the span
will fail silently because the span is no longer recording. This results in the loss of
the `cloud.region` attribute in the telemetry data for these specific requests.

Did we get this right? 👍 / 👎 to inform future reviews.

@JPeer264 JPeer264 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.

LGTM

Comment thread packages/server-utils/src/orchestrion/config/aws-sdk.ts Outdated

export function removeSuffixFromStringIfExists(str: string, suffixToRemove: string): string {
const suffixLength = suffixToRemove.length;
return str?.slice(-suffixLength) === suffixToRemove ? str.slice(0, str.length - suffixLength) : str;

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.

super-l: Since you already using .slice(-suffixLength) you could use the following to be consistent of the usage:

Suggested change
return str?.slice(-suffixLength) === suffixToRemove ? str.slice(0, str.length - suffixLength) : str;
return str?.slice(-suffixLength) === suffixToRemove ? str.slice(0, -suffixLength) : str;

Comment thread .oxlintrc.base.json
}
},
{
"files": ["**/integrations/tracing-channel/aws-sdk/**/*.ts"],

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.

q: Any chance there is a way to not disable these entirely?

* `@opentelemetry/semantic-conventions`), inlined here so the integration stays free of OTel deps.
* Attributes that exist in `@sentry/conventions/attributes` are imported from there instead;
* TODO(aws-sdk): the active attributes below are being added to sentry-conventions and should move
* to `@sentry/conventions/attributes` imports once a release containing them ships.

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.

to @sentry/conventions/attributes imports once a release containing them ships

Is there already a plan / PR to add them?

public constructor() {
// Per-service extensions, keyed by the client's `serviceId` (e.g. `'S3'`). Services without a
// registered extension still get the base rpc span from the subscriber.
this._services = new Map();

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/q: Wouldn't the following be the same? Then we could get rid of the constructor

export class ServicesExtensions implements ServiceExtension {
  #services = new Map<string, ServiceExtension>();

  ...
}

kind: requestMetadata.spanKind ?? SPAN_KIND.CLIENT,
// `rpc` matches what the exporter infers from `rpc.service` for the OTel aws-sdk spans;
// service extensions override it where inference yields a different op (DynamoDB: `db`).
op: requestMetadata.spanOp ?? 'rpc',

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: Maybe it is better to also guard against empty strings or general falsy values? Or is this not an issue here?

Suggested change
op: requestMetadata.spanOp ?? 'rpc',
op: requestMetadata.spanOp || 'rpc',

Co-authored-by: Jan Peer Stöcklmair <jan.peer@sentry.io>
},
{
channelName: 'send',
module: { name: '@smithy/smithy-client', versionRange: '>=1.0.3', filePath: 'dist-cjs/index.js' },

@JPeer264 JPeer264 Jul 13, 2026

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.

Suggested change
module: { name: '@smithy/smithy-client', versionRange: '>=1.0.3', filePath: 'dist-cjs/index.js' },
module: { name: '@smithy/smithy-client', versionRange: '>=1.0.3 <5', filePath: 'dist-cjs/index.js' },

Comment on lines +212 to +214
if (requestMetadata?.isStream && !failed) {
return true;
}

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: An early return for streaming AWS SDK responses bypasses logic to defer ending the span, causing the cloud.region attribute to be lost if region resolution is slow.
Severity: MEDIUM

Suggested Fix

Ensure that the logic to defer ending the span until the region promise settles is also applied to streaming requests. This can be done by checking for a pending region and deferring before the early return for streams, or by making the service extension responsible for awaiting the region promise before ending the span.

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/index.ts#L212-L214

Potential issue: For streaming AWS SDK responses, an early return in `deferSpanEnd` at
lines 212-214 bypasses the logic that defers ending a span until the `cloud.region` is
resolved. When a service extension (e.g., for Bedrock) later ends the span after the
stream is consumed, the region promise might still be pending. If the promise resolves
after the span has ended, the `setAttribute` call to add the region will be ignored,
resulting in the `cloud.region` attribute being omitted from the final span. This issue
will manifest once streaming service extensions are implemented as planned in follow-up
work.

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