Skip to content

Conversation

chargome
Copy link
Member

@chargome chargome commented Aug 8, 2025

Makes use of the runAfterProductionCompile hook to handle sourcemap upload logic.

When activated by setting _experimental.useRunAfterProductionCompileHook true in withSentryConfig we apply the following logic:

  • Webpack: we disable sourcemap uploads and release creation in the webpack plugin and instead handle these in `runAfterProductionCompile. We do keep the debugId injection in the plugin though. We'll do that in a follow up, webpack stays as is in this PR.
  • Turbopack: as there is no bundler plugin for Turbopack we handle the entire bundler plugin cycle in the hook (release, inject, upload, delete)

Additionally we handle automatic enabling of source maps for turbopack in this PR.

  • Server side source maps are enabled by default in turbopack so we don't touch that.
  • Client side source maps are enabled by setting productionBrowserSourceMaps: true in the Next options. We do that if not explicitly disabled.
  • nextConfig.experimental.turbopackSourceMaps: false can theoretically be set by the user to disable all sourcemaps, but we don't really want to do anything different in this case.

@chargome chargome self-assigned this Aug 8, 2025
Copy link

linear bot commented Aug 8, 2025

Copy link
Contributor

github-actions bot commented Sep 2, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,816 - 8,687 +1%
GET With Sentry 1,326 15% 1,275 +4%
GET With Sentry (error only) 5,854 66% 5,998 -2%
POST Baseline 1,196 - 1,142 +5%
POST With Sentry 518 43% 496 +4%
POST With Sentry (error only) 1,059 89% 984 +8%
MYSQL Baseline 3,348 - 3,247 +3%
MYSQL With Sentry 456 14% 435 +5%
MYSQL With Sentry (error only) 2,728 81% 2,648 +3%

View base workflow run

@chargome chargome marked this pull request as ready for review September 2, 2025 15:58
@chargome chargome changed the title [WIP]feat(nextjs): Use compiler hook for uploading sourcemaps feat(nextjs): Use compiler hook for uploading sourcemaps Sep 2, 2025
@chargome chargome changed the title feat(nextjs): Use compiler hook for uploading sourcemaps feat(nextjs): Use compiler hook for uploading turbopack sourcemaps Sep 2, 2025
cursor[bot]

This comment was marked as outdated.

chargome and others added 3 commits September 3, 2025 13:32
Co-authored-by: Andrei <168741329+andreiborza@users.noreply.github.com>
Co-authored-by: Andrei <168741329+andreiborza@users.noreply.github.com>
cursor[bot]

This comment was marked as outdated.

Comment on lines 329 to 348
if (isTurbopackSupported && isTurbopack && !userSentryOptions.sourcemaps?.disable) {
// Only set if not already configured by user
if (incomingUserNextConfigObject.productionBrowserSourceMaps === undefined) {
// eslint-disable-next-line no-console
console.log('[@sentry/nextjs] Automatically enabling browser source map generation for turbopack build.');
incomingUserNextConfigObject.productionBrowserSourceMaps = true;
}

// Enable source map deletion if not explicitly disabled
if (userSentryOptions.sourcemaps?.deleteSourcemapsAfterUpload === undefined) {
// eslint-disable-next-line no-console
console.warn(
'[@sentry/nextjs] Source maps will be automatically deleted after being uploaded to Sentry. If you want to keep the source maps, set the `sourcemaps.deleteSourcemapsAfterUpload` option to false in `withSentryConfig()`. If you do not want to generate and upload sourcemaps at all, set the `sourcemaps.disable` option to true.',
);
userSentryOptions.sourcemaps = {
...userSentryOptions.sourcemaps,
deleteSourcemapsAfterUpload: true,
};
}
}
Copy link
Member

Choose a reason for hiding this comment

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

two questions:

  • is there a way to set productionBrowserSourceMaps = 'hidden' (or something similar) rather than true
  • So far, our strategy was to delete source maps only if we enabled them. Can we do this here as well? Or would this diverge from current behaviour in NextJS?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only way to enable/disable client-side sourcemaps for turbopack is productionBrowserSourceMaps (boolean)
The only way to disable all sourcemaps for turbopack is nextConfig.experimental.turbopackSourceMaps: false

Copy link
Member Author

@chargome chargome Sep 4, 2025

Choose a reason for hiding this comment

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

Updated the logic to only delete the sourcemaps automatically if we enabled them ✅

Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

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

LGTM from my side

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Thanks for explaining and making the deletion change!

@chargome chargome merged commit 9a37660 into develop Sep 4, 2025
358 of 369 checks passed
@chargome chargome deleted the cg-use-compiler-hook-for-sourcemaps branch September 4, 2025 11:31
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.

3 participants