Skip to content

Conversation

@chargome
Copy link
Member

@chargome chargome commented Nov 24, 2025

With this PR we stop breaking builds by simply re-exporting APIs that make use of synchronous random APIs:

  • startSpan
  • startSpanManual
  • startInactiveSpan

We do this with a naive approach of detecting a prod build phase and returning a noop span in cases where we call these APIs. We hope to get a more solid API for this from Vercel at some point so we can make this more bulletproof. The current version will also still emit a warning in webpack as the behaviour seems to change there.

This will only work for Turbopack as of now, as we still need to get rid of build time instrumentation in webpack in order for this to work.

closes #17895

@chargome chargome self-assigned this Nov 24, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 24, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.8 kB - -
@sentry/browser - with treeshaking flags 23.31 kB - -
@sentry/browser (incl. Tracing) 41.54 kB - -
@sentry/browser (incl. Tracing, Profiling) 46.13 kB - -
@sentry/browser (incl. Tracing, Replay) 79.96 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.69 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 84.64 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 96.88 kB - -
@sentry/browser (incl. Feedback) 41.48 kB - -
@sentry/browser (incl. sendFeedback) 29.49 kB - -
@sentry/browser (incl. FeedbackAsync) 34.43 kB - -
@sentry/react 26.52 kB - -
@sentry/react (incl. Tracing) 43.74 kB - -
@sentry/vue 29.25 kB - -
@sentry/vue (incl. Tracing) 43.34 kB - -
@sentry/svelte 24.82 kB - -
CDN Bundle 27.17 kB - -
CDN Bundle (incl. Tracing) 42.16 kB - -
CDN Bundle (incl. Tracing, Replay) 78.7 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 84.16 kB - -
CDN Bundle - uncompressed 79.84 kB - -
CDN Bundle (incl. Tracing) - uncompressed 125.22 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 241.25 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 254.01 kB - -
@sentry/nextjs (client) 45.96 kB - -
@sentry/sveltekit (client) 41.9 kB - -
@sentry/node-core 51.19 kB - -
@sentry/node 159.24 kB - -
@sentry/node - without tracing 92.82 kB - -
@sentry/aws-serverless 108.08 kB - -

View base workflow run

@chargome chargome changed the title feat(nextjs): Support cacheComponents feat(nextjs): Support cacheComponents on turbopack Nov 24, 2025
@github-actions
Copy link
Contributor

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 9,220 - 9,214 +0%
GET With Sentry 1,734 19% 1,766 -2%
GET With Sentry (error only) 6,066 66% 6,341 -4%
POST Baseline 1,182 - 1,215 -3%
POST With Sentry 562 48% 595 -6%
POST With Sentry (error only) 1,054 89% 1,079 -2%
MYSQL Baseline 3,374 - 3,401 -1%
MYSQL With Sentry 426 13% 467 -9%
MYSQL With Sentry (error only) 2,703 80% 2,763 -2%

View base workflow run

@chargome chargome requested a review from logaretm November 24, 2025 16:22
*/
function isCacheComponentContext(): boolean {
return process.env.NEXT_PHASE === 'phase-production-build';
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

So right now now, all startSpan operations performed by users will be using the non-recording spans?

I suppose that means they can't manually instrument anything until the heuristic gets changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

This will be phase-production-build only during the build. During runtime tracing works as usual. Our tracing did not have any effect during build-time anyway since instrumentation.ts does not get registered – but we still ran into the uuid calls then

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, that makes a lot of sense 👍

@chargome chargome marked this pull request as ready for review November 24, 2025 17:39
export { captureUnderscoreErrorException } from '../common/pages-router-instrumentation/_error';

// Override core span methods with Next.js-specific implementations that support Cache Components
export { startSpan, startSpanManual, startInactiveSpan } from '../common/utils/nextSpan';
Copy link
Member

@AbhiPrasad AbhiPrasad Nov 24, 2025

Choose a reason for hiding this comment

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

A more robust change here might be to set a different acs for nextjs when you initialize the sdk server-side.

That means people can still use imports from @sentry/core or @sentry/node if they want, which might be useful for us.

Copy link
Member Author

Choose a reason for hiding this comment

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

But we would not call init in this case (of a build)

@chargome
Copy link
Member Author

@logaretm @AbhiPrasad I added a better check now to both verify that we're:

  1. not in a build
  2. not in a cached function

also updated the tests for these two scenarios

@chargome chargome merged commit 2f3144e into develop Nov 25, 2025
67 checks passed
@chargome chargome deleted the cg-next-cachecomponents branch November 25, 2025 14:50
chargome added a commit that referenced this pull request Nov 25, 2025
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.

Support cacheComponents

4 participants