Skip to content

feat(nitro): Handle sourcemap preparation and upload#19304

Open
logaretm wants to merge 13 commits intoawad/create-nitro-sdk-metadatafrom
awad/js-1076-nitro-upload-sourcemaps
Open

feat(nitro): Handle sourcemap preparation and upload#19304
logaretm wants to merge 13 commits intoawad/create-nitro-sdk-metadatafrom
awad/js-1076-nitro-upload-sourcemaps

Conversation

@logaretm
Copy link
Copy Markdown
Member

@logaretm logaretm commented Feb 12, 2026

Adds automatic sourcemap handling to the Nitro SDK, using @sentry/bundler-plugin-core for builder-agnostic post-build upload.

Nitro uses rollup or rolldown, so it made sense to make it as agnostic as possible.

Closes #17992


This PR is part of a stack:

@linear
Copy link
Copy Markdown

linear bot commented Feb 12, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 12, 2026

Codecov Results 📊


Generated by Codecov Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 12, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.88 kB added added
@sentry/browser - with treeshaking flags 24.35 kB added added
@sentry/browser (incl. Tracing) 43.77 kB added added
@sentry/browser (incl. Tracing + Span Streaming) 45.47 kB added added
@sentry/browser (incl. Tracing, Profiling) 48.7 kB added added
@sentry/browser (incl. Tracing, Replay) 82.89 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.4 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 87.58 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 99.83 kB added added
@sentry/browser (incl. Feedback) 42.7 kB added added
@sentry/browser (incl. sendFeedback) 30.55 kB added added
@sentry/browser (incl. FeedbackAsync) 35.55 kB added added
@sentry/browser (incl. Metrics) 27.16 kB added added
@sentry/browser (incl. Logs) 27.29 kB added added
@sentry/browser (incl. Metrics & Logs) 27.98 kB added added
@sentry/react 27.62 kB added added
@sentry/react (incl. Tracing) 46.01 kB added added
@sentry/vue 30.7 kB added added
@sentry/vue (incl. Tracing) 45.58 kB added added
@sentry/svelte 25.89 kB added added
CDN Bundle 28.55 kB added added
CDN Bundle (incl. Tracing) 44.82 kB added added
CDN Bundle (incl. Logs, Metrics) 29.93 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 45.91 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 68.83 kB added added
CDN Bundle (incl. Tracing, Replay) 81.78 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 82.85 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 87.29 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 88.36 kB added added
CDN Bundle - uncompressed 83.4 kB added added
CDN Bundle (incl. Tracing) - uncompressed 134.03 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 87.55 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 137.44 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 210.91 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 251.26 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 254.66 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 264.18 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 267.56 kB added added
@sentry/nextjs (client) 48.54 kB added added
@sentry/sveltekit (client) 44.18 kB added added
@sentry/node-core 57.97 kB added added
@sentry/node 174.8 kB added added
@sentry/node - without tracing 97.93 kB added added
@sentry/aws-serverless 115.16 kB added added

@logaretm logaretm force-pushed the awad/js-1128-nitro-use-tracing-channels-for-srvx-and-h3 branch from 1923dda to be2f037 Compare February 23, 2026 14:50
@logaretm logaretm force-pushed the awad/js-1076-nitro-upload-sourcemaps branch from 0d86a79 to 9f6254a Compare February 23, 2026 14:50
@logaretm logaretm force-pushed the awad/js-1128-nitro-use-tracing-channels-for-srvx-and-h3 branch from be2f037 to 3b30e36 Compare February 23, 2026 14:52
@logaretm logaretm force-pushed the awad/js-1076-nitro-upload-sourcemaps branch from 9f6254a to 63a2175 Compare February 23, 2026 14:52
@logaretm logaretm force-pushed the awad/js-1128-nitro-use-tracing-channels-for-srvx-and-h3 branch from 3b30e36 to 36c96b6 Compare February 23, 2026 16:17
@logaretm logaretm force-pushed the awad/js-1076-nitro-upload-sourcemaps branch 2 times, most recently from d3e3ae1 to a24cad5 Compare February 23, 2026 16:23
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you apply the label PR: no-auto-close I will leave it alone ... forever!

@logaretm logaretm force-pushed the awad/js-1128-nitro-use-tracing-channels-for-srvx-and-h3 branch 2 times, most recently from 3cf1515 to 342ea3b Compare April 15, 2026 13:54
@logaretm logaretm force-pushed the awad/js-1076-nitro-upload-sourcemaps branch from a24cad5 to 1583866 Compare April 15, 2026 14:44
@logaretm logaretm force-pushed the awad/js-1128-nitro-use-tracing-channels-for-srvx-and-h3 branch from 342ea3b to 8d44437 Compare April 15, 2026 14:55
@logaretm logaretm force-pushed the awad/js-1076-nitro-upload-sourcemaps branch 2 times, most recently from a967e7a to 00bd835 Compare April 15, 2026 14:59
@logaretm logaretm marked this pull request as ready for review April 15, 2026 18:13
Comment thread packages/nitro/src/sourceMaps.ts
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds build-time sourcemap generation + post-build sourcemap (and debug ID) handling to the @sentry/nitro SDK by wiring Nitro’s compiled hook to @sentry/bundler-plugin-core.

Changes:

  • Introduces packages/nitro/src/sourceMaps.ts to configure Nitro sourcemap settings and to run a post-build upload flow via createSentryBuildPluginManager.
  • Threads SentryNitroOptions through module setup so sourcemap behavior can be configured from withSentryConfig/setupSentryNitroModule.
  • Adds Vitest coverage for option-shaping and basic hook registration behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/nitro/src/sourceMaps.ts New sourcemap config + post-build hook which injects debug IDs and uploads sourcemaps via bundler-plugin-core
packages/nitro/test/sourceMaps.test.ts New unit tests for plugin option building, config mutation, and hook registration
packages/nitro/src/module.ts Passes Sentry options into module setup to enable sourcemap handling
packages/nitro/src/config.ts Defines SentryNitroOptions from bundler-plugin-core options and enables sourcemap config during module setup
packages/nitro/rollup.npm.config.mjs Marks @sentry/bundler-plugin-core as external in the package build
packages/nitro/package.json Adds @sentry/bundler-plugin-core dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/nitro/src/sourceMaps.ts
Comment thread packages/nitro/src/sourceMaps.ts Outdated
Comment thread packages/nitro/src/sourceMaps.ts Outdated
Comment thread packages/nitro/src/sourceMaps.ts Outdated
Comment thread packages/nitro/src/sourceMaps.ts Outdated
Comment thread packages/nitro/test/sourceMaps.test.ts
@logaretm logaretm force-pushed the awad/js-1076-nitro-upload-sourcemaps branch from 492a81a to 7bf357b Compare April 16, 2026 16:46
@logaretm logaretm force-pushed the awad/js-1128-nitro-use-tracing-channels-for-srvx-and-h3 branch from 0173b17 to 6b8d4d7 Compare April 16, 2026 17:09
@logaretm logaretm force-pushed the awad/js-1076-nitro-upload-sourcemaps branch from 7bf357b to 2b2c36b Compare April 16, 2026 17:11
logaretm added a commit that referenced this pull request Apr 17, 2026
Implements HTTP server instrumentation for both `h3` and `srvx` by
listening to their tracing channel events.

- `h3` TC PR: h3js/h3#1251
- `srvx` TC PR: h3js/srvx#141

Closes #18123 

---

**This PR is part of a stack:**

- #20358
- #19224
- #19225 👈
- #19304

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Base automatically changed from awad/js-1128-nitro-use-tracing-channels-for-srvx-and-h3 to awad/create-nitro-sdk-metadata April 17, 2026 15:09
@logaretm logaretm force-pushed the awad/js-1076-nitro-upload-sourcemaps branch from 2b2c36b to d3328c8 Compare April 17, 2026 15:11
Comment thread packages/nitro/src/sourceMaps.ts Outdated
logaretm added a commit that referenced this pull request Apr 17, 2026
Implements HTTP server instrumentation for both `h3` and `srvx` by
listening to their tracing channel events.

- `h3` TC PR: h3js/h3#1251
- `srvx` TC PR: h3js/srvx#141

Closes #18123

---

**This PR is part of a stack:**

- #20358
- #19224
- #19225 👈
- #19304

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@logaretm logaretm force-pushed the awad/create-nitro-sdk-metadata branch from 4cd6415 to 47d85ab Compare April 17, 2026 15:54
@logaretm logaretm force-pushed the awad/js-1076-nitro-upload-sourcemaps branch from d3328c8 to 25e2ec0 Compare April 17, 2026 15:55
Comment thread packages/nitro/src/sourceMaps.ts
Copy link
Copy Markdown

@cursor cursor bot left a comment

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.

There are 3 total unresolved issues (including 2 from previous reviews).

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 25e2ec0. Configure here.

Comment thread packages/nitro/src/sourceMaps.ts Outdated
Comment thread packages/nitro/src/sourceMaps.ts
logaretm added a commit that referenced this pull request Apr 18, 2026
Implements HTTP server instrumentation for both `h3` and `srvx` by
listening to their tracing channel events.

- `h3` TC PR: h3js/h3#1251
- `srvx` TC PR: h3js/srvx#141

Closes #18123

---

**This PR is part of a stack:**

- #20358
- #19224
- #19225 👈
- #19304

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@logaretm logaretm force-pushed the awad/create-nitro-sdk-metadata branch from 47d85ab to fa580dd Compare April 18, 2026 03:53
logaretm and others added 13 commits April 17, 2026 23:53
…is set

When `sourcemaps.disable` is `'disable-upload'`, the plugin should still
inject debug IDs and keep `.map` files so users can upload them manually.
Previously, both `injectDebugIds()` and `deleteArtifacts()` were
incorrectly gated or ungated, causing debug IDs to be skipped and source
maps to be deleted even in the manual-upload workflow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Derive `SentryNitroOptions` from `BuildTimeOptionsBase` (from `@sentry/core`)
instead of picking from the bundler plugin's internal `Options` type. This
provides a stable public API that follows this repo's semver, rather than
exposing bundler-plugin-specific fields like `_metaOptions` and top-level
`disable`.

Key changes:
- `url` option renamed to `sentryUrl` (consistent with other SDKs)
- Top-level `disable` removed (use `sourcemaps.disable` instead)
- `_metaOptions` no longer user-configurable

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ing `true`

Previously, `configureSourcemapSettings` unconditionally set
`config.sourcemap = true`, overriding the user's explicit `false`. This
could expose source maps publicly when users intentionally disabled them.

Now follows the same 3-case pattern as other meta-framework SDKs (Nuxt):
1. User disabled (false) → keep their setting, warn about unminified errors
2. User enabled (true) → keep their setting
3. User didn't set (undefined) → enable for Sentry

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
`configureSourcemapSettings` runs at build time, but the `debug` logger
from `@sentry/core` is only initialized by `Sentry.init()` at runtime.
Switch to `console.warn`/`console.log` so build-time warnings (e.g.
source maps explicitly disabled) are actually visible to developers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The `rewriteSources` option was hardcoded to `normalizePath`, silently
discarding any custom function provided by the user. Now falls back to
`normalizePath` only when the user doesn't provide their own function,
matching the behavior of other meta-framework SDKs (Nuxt, Next.js).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previously `filesToDeleteAfterUpload` defaulted to `['**/*.map']`
unconditionally, deleting user-generated source maps even when the user
explicitly set `sourcemap: true` in their Nitro config. Now the default
only applies when Sentry was the one to enable sourcemap generation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Nitro spawns a nested Nitro instance for prerendering with the user's
`modules` array re-installed, which caused the Sentry module to run
twice and upload source maps + create a release twice per build.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@logaretm logaretm force-pushed the awad/js-1076-nitro-upload-sourcemaps branch from ff591f3 to 14b31ea Compare April 18, 2026 03:53
Comment on lines +27 to +29
nitro.hooks.hook('compiled', async (_nitro: Nitro) => {
await handleSourceMapUpload(_nitro, options, sentryEnabledSourcemaps);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The compiled hook in setupSourceMaps is registered even when config.sourcemap is false, causing source map processing to run unnecessarily on builds without sourcemaps.
Severity: MEDIUM

Suggested Fix

Add an early return in setupSourceMaps to prevent the hook from being registered when sourcemaps are disabled. This can be done by checking the sentryEnabledSourcemaps parameter at the beginning of the function and returning if it's false.

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/nitro/src/sourceMaps.ts#L27-L29

Potential issue: When a user sets `config.sourcemap = false` in their Nitro
configuration, the `setupSourceMaps` function still registers a `compiled` hook. As a
result, when the build completes, `handleSourceMapUpload` is executed. This function
then calls `injectDebugIds` on a build output directory that contains no sourcemap
files, because their generation was disabled. This can lead to errors, unnecessary
processing, or confusing log output. The function lacks an early exit condition to check
if sourcemaps are disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants