Skip to content

bundleSizeOptimizations.excludeTracing no longer removes tracing code since 11.17 (Turbopack) #27184

Backlog

Description

@ciceropablo

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

11.23.0 (also 11.17.0; 11.16.0 works)

Framework Version

Next.js 16.4.6, next build --turbopack, Node 24

Link to Sentry event

No response

Reproduction Example/SDK Setup

Minimal app: an App Router page, plus these two files.

instrumentation-client.ts:

import * as Sentry from "@sentry/nextjs";
Sentry.init({ dsn: "https://public@o0.ingest.sentry.io/0" });

next.config.ts:

import { withSentryConfig } from "@sentry/nextjs/config";
export default withSentryConfig({}, {
  telemetry: false,
  silent: true,
  sourcemaps: { disable: true },
  bundleSizeOptimizations: { excludeTracing: true },
});

Steps to Reproduce

  1. Build the app above with next build --turbopack.
  2. Search .next/static/chunks/*.js for the body of browserTracingIntegration (e.g. instrumentBfcacheRestore) and for "SpanStreaming".
  3. Repeat with @sentry/nextjs 11.16.0.

Expected Result

No tracing code in the client bundle, as in 11.16.0.

Actual Result

@sentry/nextjs browserTracingIntegration body SpanStreaming client JS (gzip)
11.16.0 absent absent 210 KB
11.17.0 present present 228 KB
11.23.0 present present 228 KB

In a larger app we also see SpanStreaming in the edge (middleware) bundle.

Additional Context

#26779 changed defineIntegration from return fn to returning a new closure that records the options. Before, the minifier could inline the call and drop an unused const fooIntegration = defineIntegration(...). Now the call looks side-effectful, so every integration defined at module level stays in the bundle, with all the code it references. The __SENTRY_TRACING__ guard in getDefaultIntegrations still becomes false, so the integration is never used, but its definition is no longer removed.

We confirmed this by patching defineIntegration in @sentry/core 11.23.0 back to return fn: the tracing code leaves the browser and edge bundles again. Adding /* @__PURE__ */ to the single browserTracingIntegration = defineIntegration(...) call did not help in our app, so the fix probably has to be in defineIntegration itself, or in how it is called everywhere.

Possibly related: #26902 (web-vitals with excludeTracing in Astro, fixed by the rolldown bump in 11.23.0). This one is still present in 11.23.0 with Turbopack.

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions