nextjs - 💡(How to fix) Fix Server dependency bundling breaks AWS OpenTelemetry instrumentation [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#88161Fetched 2026-04-08 02:05:30
View on GitHub
Comments
0
Participants
1
Timeline
7
Reactions
1
Participants
Timeline (top)
subscribed ×3labeled ×2cross-referenced ×1issue_type_added ×1

Root Cause

I'm running into this issue now because AWS recently started recommending migrating from X-Ray instrumentation to OpenTelemetry. Everyone else who uses Next.js with AWS X-Ray is going to get bitten by this issue as they migrate.

Fix Action

Fix / Workaround

// Exclude packages used by AWS SDK v3 from server bundling so OpenTelemetry instrumentation can patch them.
serverExternalPackages: ["@smithy/middleware-stack", "@smithy/smithy-client"],

Code Example

// Exclude packages used by AWS SDK v3 from server bundling so OpenTelemetry instrumentation can patch them.
serverExternalPackages: ["@smithy/middleware-stack", "@smithy/smithy-client"],

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 22.17.1
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.22.0
Relevant Packages:
  next: 16.1.1-canary.13 // Latest available version is detected (16.1.1-canary.13).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/TrevorBurnham/nextjs-aws-opentelemetry

To Reproduce

  1. Create an AWS profile if you don't already have one
  2. Run the app with AWS_PROFILE=<your profile> npm run dev
  3. Visit http://localhost:3000/api/test
  4. Check the console and wait a few seconds

Current vs. Expected behavior

Several OpenTelemetry spans are emitted to the console, but not the expected one from the AWS instrumentation (look for name: 'STS.GetCallerIdentity').

I investigated and discovered that the problem is the server bundling behavior. The @opentelemetry/instrumentation-aws-sdk package relies on require hooks, which break when the AWS SDK modules are bundled. I found that adding this to the next.config.js fixes the issue:

// Exclude packages used by AWS SDK v3 from server bundling so OpenTelemetry instrumentation can patch them.
serverExternalPackages: ["@smithy/middleware-stack", "@smithy/smithy-client"],

Perhaps those modules should be excluded from bundling by default? I notice that @aws-sdk/client-s3 is already excluded, though for different reasons (#51969).

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 22.17.1
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.22.0
Relevant Packages:
  next: 16.1.1-canary.13 // Latest available version is detected (16.1.1-canary.13).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Instrumentation

Which stage(s) are affected? (Select all that apply)

Other (Deployed), Vercel (Deployed), next start (local), next dev (local)

Additional context

I'm running into this issue now because AWS recently started recommending migrating from X-Ray instrumentation to OpenTelemetry. Everyone else who uses Next.js with AWS X-Ray is going to get bitten by this issue as they migrate.

extent analysis

TL;DR

To fix the issue with OpenTelemetry spans not being emitted due to server bundling behavior, exclude the necessary AWS SDK modules from server bundling in next.config.js.

Guidance

  • Identify the AWS SDK modules that need to be excluded from server bundling, such as @smithy/middleware-stack and @smithy/smithy-client.
  • Add these modules to the serverExternalPackages array in next.config.js to prevent them from being bundled.
  • Verify that the OpenTelemetry spans are being emitted correctly after making this change.
  • Consider submitting a pull request to update the default excluded packages in Next.js to include the necessary AWS SDK modules.

Example

// next.config.js
module.exports = {
  // ...
  serverExternalPackages: ["@smithy/middleware-stack", "@smithy/smithy-client"],
}

Notes

This fix assumes that the issue is solely due to the server bundling behavior and that excluding the necessary AWS SDK modules will resolve the issue. If the issue persists, further investigation may be needed.

Recommendation

Apply the workaround by excluding the necessary AWS SDK modules from server bundling in next.config.js, as this is a targeted fix for the identified issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix Server dependency bundling breaks AWS OpenTelemetry instrumentation [1 participants]