Repository navigation
fix(nuxt): Ignore build output and public file spans with span streaming - #26781
Conversation
size-limit report 📦Compared: 3440225 (PR test merge using develop at 6daef45) Against: 6daef45 (develop) · base run #67728 ✅ Baseline matches: this diff contains only this PR's changes.
|
Optional E2E testsSome optional checks were not successful. They do not block the merge. 2 not successful, 70 successful. See the run.
Successful checks
|
chargome
left a comment
There was a problem hiding this comment.
Looks good, just two edge cases that might matter.
| function getBuildAssetRequestFilters(): NonNullable<SentryNuxtServerOptions['ignoreSpans']> { | ||
| const buildAssetsPath = getNuxtBuildAssetsPath(); | ||
| return buildAssetsPath | ||
| ? [{ op: HTTP_SERVER, attributes: { [URL_PATH]: new RegExp(`^${escapeStringForRegex(buildAssetsPath)}`) } }] |
There was a problem hiding this comment.
With the deprecated autoInjectServerSentry modes, sentry-runtime-flags.mjs is never imported. The filter then falls back to ^/_nuxt/ and misses a custom app.baseURL or buildAssetsDir. Should we import the flags there too?
There was a problem hiding this comment.
no, this is deprecated since a long time and it would add a bunch of code to support this. It's fine if we only support this in the normal setup.
… deprecated modes The browser filter matched the manifest path anywhere in a URL, so it also dropped spans of other hosts. It now matches only the app origin or `app.cdnURL`, plus the base path. The deprecated `autoInjectServerSentry` modes did not load the runtime flags, so the server filter ignored a custom `app.baseURL` or `buildAssetsDir`. Both modes now import the flags before the server config.
The `autoInjectServerSentry` modes are deprecated, and supporting the configured build paths there needs too much code for them.
Nuxt 5 no longer fetches the build manifest after hydration. Without payload extraction it only fetches it in the hourly check for new builds.
…ifacts # Conflicts: # packages/nuxt/src/client/sdk.ts # packages/nuxt/src/server/sdk.ts
Similar to #26781 (same on Nuxt) ## What With span streaming (the default), the SolidStart SDK sent a span for every request to its build output under `/_build/`. Now the SDK ignores these requests in both trace modes, also under a base path, and it keeps real routes. | Request | Before, span streaming (default) | Before, static mode | Now, both modes | |---|---|---|---| | Build files that the HTTP integration does not ignore, for example `/_build/assets/app.js.map` | **sent** | not sent | not sent | | All build files on SolidStart 2, also `.js` and `.css` | **sent** | not sent | not sent | | Build files under a base path, for example `/app/_build/assets/app.js.map` | **sent** | **sent** | not sent | | Routes, also ones that contain `_build`, for example `/users/_build/` | sent | sent | sent | "Static mode" is `traceLifecycle: 'static'`. **Bold** marks the problems this PR fixes. ## Why The old filter was an event processor that dropped transactions by name. Event processors do not run with span streaming, so the filter silently stopped working. Now the SDK adds an `ignoreSpans` default on `url.path` instead, which works in both modes. This is the same fix as for Nuxt. The filter needs the base path (`server.baseURL` on SolidStart 1, Vite `base` on SolidStart 2) when `Sentry.init()` runs. SolidStart 2 bundles the SDK into the server build, so the build sets the value there. SolidStart 1 loads `instrument.server.mjs` with `node --import` before the server bundle, so the build now writes the base path into that file too. In development, the server SDK does not know the base path yet, so there the filter only matches `/_build/`. On SolidStart 2, the SDK still sends spans for other static files such as `/favicon.ico`, because Nitro's server spans skip the HTTP integration's static file filter. That needs a separate fix in `@sentry/server-utils`.
Nuxt 4.7.0 no longer fetches the build manifest after hydration, so the test waited for a request that never came. The test page now calls getAppManifest() on a button click.
The HTTP integration only ignores common static file extensions, so requests for other files in public/ (for example .txt or .pdf) still created spans. At build time, the SDK now lists the files in the public dirs and ignores GET requests for their exact paths. Files the HTTP integration already ignores are left out, so ignoreStaticAssets still applies to them.
| listFiles(path.resolve(dir)).map(file => | ||
| path.posix.join('/', dirURL ?? '', path.relative(path.resolve(dir), file).split(path.sep).join('/')), | ||
| ), |
There was a problem hiding this comment.
Public file ignore paths are not URL-encoded
Filesystem paths like /my file.pdf are stored and matched raw, but server spans set url.path from URL.pathname (e.g. /my%20file.pdf), so public files with spaces or non-ASCII names still create GET spans.
Evidence
getPublicFilePaths()builds URL paths frompath.relative(...)filesystem segments with noencodeURI/encodeURIComponent.- Those paths are baked into
ignoreSpansas an exacturl.pathregex ingetPublicFileRequestFilters(). - HTTP server spans set
url.pathfromparseStringToURLObject(...).pathname, which keeps percent-encoding (/my%20file.pdf,/caf%C3%A9.pdf). - Exact regex match therefore fails for any public file whose name is not already URL-safe.
Identified by Warden · code-review · MPX-U8C
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit a8c2b9b. Configure here.
## What Came up in a warden comment but PR was already auto-merged: #26781 (comment) The Nuxt server SDK now also ignores requests for `public/` files with spaces, non-ASCII letters or characters like `%` and `#` in their names, for example `/my file.pdf` or `/café.pdf`. ## Why Spans store the percent-encoded request path (`/my%20file.pdf`), but the public file list from #26781 held the raw file names, so these paths never matched. The SDK now encodes the paths with the same URL parsing that sets `url.path`, so both sides use the same form.
What
With span streaming (the default), the Nuxt SDK sent spans for Nuxt's own build files, and the browser's build manifest fetch could make pageloads longer. It also sent spans for files in
public/that the HTTP integration does not know as static files. Now the SDK ignores all of these in both trace modes, and it keeps real routes that only look like files.traceLifecycle: 'static'/_nuxt/entry.js, CSS, images,/favicon.ico/_nuxt/entry.js.map,/_nuxt/builds/latest.json/_nuxt/builds/meta/<id>.json)/api/data.jsonpublic/, for example.pdf,.txt,.webmanifestBold marks the problems this PR fixes.
The filters read
app.baseURLandapp.buildAssetsDir, so custom build folders and base paths work too. The browser filter matches only the app's own origin, orapp.cdnURLif it is set, so requests to other hosts keep their spans.Why
The old filter was an event processor that dropped transactions by name. Event processors do not run with span streaming, so the filter silently stopped working. Now the SDK adds
ignoreSpansdefaults instead, which work in both modes.The new server filter matches only paths that start with the build folder, not every path with a file extension. That keeps routes like
/api/data.json. Forpublic/, the SDK lists the files at build time and ignoresGETrequests for their exact paths, because a route can start with the same path as a folder inpublic/. Files that the HTTP integration already ignores are not in this list, soignoreStaticAssets: falsestill works for them.If you change the base path at runtime with
NUXT_APP_BASE_URL, the server filters do not match.The deprecated
autoInjectServerSentrymodes do not get the configured paths or the list of public files, so there the server filter only covers the default/_nuxt/folder.