Skip to content

Conversation

@logaretm
Copy link
Collaborator

@logaretm logaretm commented Dec 1, 2025

This PR updates the Sentry Next.js integration to improve tree-shaking configuration and add new options for finer control over what SDK code is included in the final bundle.

The most significant changes are:

  • Renaming of the debugLogs option to debugLogging
  • Added several new tree-shaking flags for better user DX.

@linear
Copy link

linear bot commented Dec 1, 2025

@logaretm logaretm requested a review from chargome December 1, 2025 16:01
@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.8 kB added added
@sentry/browser - with treeshaking flags 23.31 kB added added
@sentry/browser (incl. Tracing) 41.54 kB added added
@sentry/browser (incl. Tracing, Profiling) 46.13 kB added added
@sentry/browser (incl. Tracing, Replay) 79.96 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.69 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 84.64 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 96.88 kB added added
@sentry/browser (incl. Feedback) 41.48 kB added added
@sentry/browser (incl. sendFeedback) 29.49 kB added added
@sentry/browser (incl. FeedbackAsync) 34.47 kB added added
@sentry/react 26.52 kB added added
@sentry/react (incl. Tracing) 43.74 kB added added
@sentry/vue 29.25 kB added added
@sentry/vue (incl. Tracing) 43.34 kB added added
@sentry/svelte 24.82 kB added added
CDN Bundle 27.21 kB added added
CDN Bundle (incl. Tracing) 42.21 kB added added
CDN Bundle (incl. Tracing, Replay) 78.75 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 84.2 kB added added
CDN Bundle - uncompressed 79.96 kB added added
CDN Bundle (incl. Tracing) - uncompressed 125.34 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 241.37 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 254.13 kB added added
@sentry/nextjs (client) 45.96 kB added added
@sentry/sveltekit (client) 41.9 kB added added
@sentry/node-core 51.19 kB added added
@sentry/node 159.36 kB added added
@sentry/node - without tracing 92.83 kB added added
@sentry/aws-serverless 108.08 kB added added

@logaretm logaretm force-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch 2 times, most recently from bf5a673 to 66aa19c Compare December 4, 2025 14:44
Copilot AI review requested due to automatic review settings December 4, 2025 14:44
Copilot finished reviewing on behalf of logaretm December 4, 2025 14:47
Copy link

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

This PR enhances the Sentry Next.js SDK's tree-shaking capabilities by renaming debugLogs to debugLogging and introducing four new configuration options for fine-grained control over SDK bundle inclusion.

Key Changes:

  • Renamed configuration option from debugLogs to debugLogging for consistency
  • Added tracing, excludeReplayIframe, excludeReplayShadowDOM, and excludeReplayCompressionWorker tree-shaking options
  • Refactored webpack configuration to use a dedicated setupTreeshakingFromConfig function for improved maintainability

Reviewed changes

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

File Description
packages/nextjs/src/config/types.ts Added type definitions and JSDoc documentation for four new tree-shaking options
packages/nextjs/src/config/webpack.ts Extracted tree-shaking setup into a dedicated function that handles all five tree-shaking flags via webpack DefinePlugin
packages/nextjs/test/config/fixtures.ts Updated DefinePlugin mock to accept and store definitions for test verification
packages/nextjs/test/config/webpack/constructWebpackConfig.test.ts Added comprehensive test suite covering all tree-shaking options across different build contexts (server, client, edge)

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

tracing?: boolean;

/**
* Replacing this flag with true will tree shake any SDK code related to capturing iframe content with Session Replay.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "Replacing this flag with true" is awkward. This should be "Setting this to true" to match the pattern used for the tracing option and to be clearer about the action being taken.

Copilot uses AI. Check for mistakes.
tracing?: boolean;

/**
* Replacing this flag with true will tree shake any SDK code related to capturing iframe content with Session Replay.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

Inconsistent hyphenation: "tree-shake" (hyphenated) is used in line 117, but "tree shake" (no hyphen) is used in lines 122, 129, and 137. For consistency, use "tree-shake" (with hyphen) as a verb throughout the documentation.

Copilot uses AI. Check for mistakes.
excludeReplayIframe?: boolean;

/**
* Replacing this flag with true will tree shake any SDK code related to capturing shadow dom elements with Session Replay.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

Inconsistent hyphenation: "tree-shake" (hyphenated) is used in line 117, but "tree shake" (no hyphen) is used here. For consistency, use "tree-shake" (with hyphen) as a verb throughout the documentation.

Copilot uses AI. Check for mistakes.
excludeReplayShadowDOM?: boolean;

/**
* Replacing this flag with true will tree shake any SDK code that's related to the included compression web worker for Session Replay.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

Inconsistent hyphenation: "tree-shake" (hyphenated) is used in line 117, but "tree shake" (no hyphen) is used here. For consistency, use "tree-shake" (with hyphen) as a verb throughout the documentation.

Copilot uses AI. Check for mistakes.
excludeReplayIframe?: boolean;

/**
* Replacing this flag with true will tree shake any SDK code related to capturing shadow dom elements with Session Replay.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "Replacing this flag with true" is awkward. This should be "Setting this to true" to match the pattern used for the tracing option and to be clearer about the action being taken.

Copilot uses AI. Check for mistakes.
excludeReplayShadowDOM?: boolean;

/**
* Replacing this flag with true will tree shake any SDK code that's related to the included compression web worker for Session Replay.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "Replacing this flag with true" is awkward. This should be "Setting this to true" to match the pattern used for the tracing option and to be clearer about the action being taken.

Copilot uses AI. Check for mistakes.
excludeReplayShadowDOM?: boolean;

/**
* Replacing this flag with true will tree shake any SDK code that's related to the included compression web worker for Session Replay.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "SDK code that's related to" uses a contraction which is inconsistent with the documentation style of the other options. Change "that's" to "that is" for consistency and professional documentation style.

Suggested change
* Replacing this flag with true will tree shake any SDK code that's related to the included compression web worker for Session Replay.
* Replacing this flag with true will tree shake any SDK code that is related to the included compression web worker for Session Replay.

Copilot uses AI. Check for mistakes.
* Replacing this flag with true will tree shake any SDK code that's related to the included compression web worker for Session Replay.
* It's only relevant when using Session Replay.
* Enable this flag if you want to host a compression worker yourself.
* See Using a Custom Compression Worker for details.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The phrase "See Using a Custom Compression Worker for details" is unclear. It should either provide a link or clarify where this documentation can be found (e.g., "See the Sentry documentation on using a custom compression worker for details" or provide an actual URL).

Suggested change
* See Using a Custom Compression Worker for details.
* See the Sentry documentation on using a custom compression worker for details: https://docs.sentry.io/platforms/javascript/session-replay/custom-compression-worker/

Copilot uses AI. Check for mistakes.
@logaretm logaretm force-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch from 03e070a to e66a724 Compare December 5, 2025 09:56
sentryBuildTimeOptions: {
webpack: {
treeshake: {
debugLogging: true,
Copy link

Choose a reason for hiding this comment

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

Bug: Tests use debugLogging and tracing instead of removeDebugLogging and removeTracing for webpack treeshaking, causing silent feature failure.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The tests in packages/nextjs/test/config/webpack/constructWebpackConfig.test.ts incorrectly use debugLogging and tracing properties for webpack treeshaking configuration. The type definitions and implementation correctly expect removeDebugLogging and removeTracing. This mismatch causes the tests to pass without validating the correct configuration, leading users to apply the wrong property names, which results in the treeshaking feature silently failing to function.

💡 Suggested Fix

Update packages/nextjs/test/config/webpack/constructWebpackConfig.test.ts to use removeDebugLogging and removeTracing instead of debugLogging and tracing for webpack treeshaking options.

🤖 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/nextjs/test/config/webpack/constructWebpackConfig.test.ts#L462

Potential issue: The tests in
`packages/nextjs/test/config/webpack/constructWebpackConfig.test.ts` incorrectly use
`debugLogging` and `tracing` properties for webpack treeshaking configuration. The type
definitions and implementation correctly expect `removeDebugLogging` and
`removeTracing`. This mismatch causes the tests to pass without validating the correct
configuration, leading users to apply the wrong property names, which results in the
treeshaking feature silently failing to function.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5744424

sentryBuildTimeOptions: {
webpack: {
treeshake: {
debugLogging: true,
Copy link

Choose a reason for hiding this comment

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

Bug: Tests use wrong property names for treeshake options

The tests use debugLogging and tracing as property names, but the type definition in types.ts and the implementation in webpack.ts expect removeDebugLogging and removeTracing. Because the tests pass properties that don't exist in the expected interface, the implementation will never set the corresponding DefinePlugin flags, meaning these tests don't actually verify the functionality they claim to test. This affects multiple test cases throughout the new test suite.

Additional Locations (2)

Fix in Cursor Fix in Web

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