feat(web): enable Sentry node and browser profiling#1431
Merged
Conversation
Adds @sentry/profiling-node and wires up profiling on both the server (nodeProfilingIntegration) and the browser (browserProfilingIntegration). Both use profileLifecycle: 'trace', so a profiler only runs while a sampled root span is active rather than continuously. Browser profiling additionally requires the document to opt into the JS Self-Profiling API, so a `Document-Policy: js-profiling` response header is added alongside the existing security headers. @sentry/profiling-node is pinned to ^10.40.0 to match @sentry/nextjs. It depends on @sentry/core and @sentry/node at exact versions, so a newer minor would pull a second copy of the SDK into the tree and the profiler would register against a different global. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
WalkthroughChangesSentry profiling
Estimated code review effort: 2 (Simple) | ~10 minutes ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributor
License Audit
Weak Copyleft Packages (informational)
Resolved Packages (17)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enables Sentry profiling in the web app, on both the server and the browser.
Changes
@sentry/profiling-nodetopackages/web.sentry.server.config.ts: registerednodeProfilingIntegration().instrumentation-client.ts: registeredSentry.browserProfilingIntegration().profileSessionSampleRate: 1.0andprofileLifecycle: 'trace', so a profiler runs only while a sampled root span is active rather than continuously.next.config.mjs: added aDocument-Policy: js-profilingresponse header, which browser profiling requires in order to opt the document into the JS Self-Profiling API.Notes
Version pinning.
@sentry/profiling-nodeis pinned to^10.40.0to match@sentry/nextjs, rather than the latest10.64.0. It depends on@sentry/coreand@sentry/nodeat exact versions, so a newer minor would install a second copy of the SDK alongside the one@sentry/nextjspulls in, and the profiler would register against a different global carrier and silently emit nothing. Verified the tree still resolves to a single@sentry/core@10.40.0. Moving to10.64.0would need a coordinated bump of@sentry/nextjs(web) and@sentry/node+@sentry/profiling-node(backend) together.No
serverExternalPackagesentry needed.@sentry/profiling-nodeloads a native.nodeaddon through arequire()whose path is computed at runtime, which normally means it has to be marked external. Next.js already ships it in its built-in external list (next/dist/lib/server-external-packages.jsonc), so no config is required. Confirmed by building with and without an explicit entry:instrumentation.jshashed identically and the file trace was unchanged.browserTracingIntegrationis not listed explicitly.@sentry/nextjspushes its own App Router-aware version into the default integrations, and passingintegrationsas an array merges with the defaults rather than replacing them. Listing the generic one would shadow it.Verification
["profile_chunk", "transaction"]for a sampled span, confirming the native addon loads andprofileLifecycle: 'trace'behaves as configured. With the option omitted (SDK default'manual') only["transaction"]is emitted.next buildpasses, and.next/standalonetraces the profiler plus all 28 prebuilt binaries, including the twolinux-*-musl-137ones thenode:24-alpineruntime image needs.Follow-up worth considering
Server-side
profileSessionSampleRate: 1.0profiles every process.app.sourcebot.devruns a single web replica whose event loop already saturates under/browserender bursts, so it may be worth dialing this down on the server. Browser profiling is client-side and costs nothing there.🤖 Generated with Claude Code
Note
Medium Risk
Server profiling uses a native addon at 100% session sampling alongside full trace sampling, which can add CPU/overhead on hot paths; changes are observability-only, not auth or data handling.
Overview
Turns on Sentry performance profiling for the Next.js web app on both the server and client, tied to sampled traces instead of always-on profiling.
Server init registers
nodeProfilingIntegration()(new@sentry/profiling-node, version-matched to@sentry/nextjs) withprofileSessionSampleRate: 1.0andprofileLifecycle: 'trace'. Client init addsbrowserProfilingIntegration()with the same profiling options.debug: falseis dropped from both inits.next.config.mjsadds a globalDocument-Policy: js-profilingheader so browser profiling can use the JS Self-Profiling API.Reviewed by Cursor Bugbot for commit a992a80. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit