Skip to content

fix(bootstrap): Report preload request failures as real errors and metrics - #126592

Merged
billyvg merged 2 commits into
masterfrom
billyvong/fix/preload-data-rejection-errors
Oct 6, 2026
Merged

billyvg merged 2 commits into
masterfrom
billyvong/fix/preload-data-rejection-errors

Conversation

@billyvg

@billyvg billyvg commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

https://sentry.sentry.io/issues/6235565924/?project=11276&referrer=issue-list&statsPeriod=24h has re-emerged since the authv2 changes (fixed by #126593). There were a few problems with what we were doing, e.g. we were throwing an array, and then immediately catch it and expected an error object, but really we caught the re-thrown array. that's why the error message is ,.

Also noticed that we have a try/catch around _preloadData() to suppress these errors too, but it doesn't work because we don't await _preloadData(), so the try/catch doesn't do anything.

All this to say let's update this to track to Sentry metrics.

The tracking is done in #126596

Slop

Why?

When a preload request fails, the preload-data script rejects with an array instead of an Error. Its catch then rethrows [error.status, error.statusText] from that array, so every failure becomes [undefined, undefined]. That gets reported as Error: ,, with no HTTP status and no original error type. An earlier fix (#120588) only changed the standalone SPA copy of this function; server-rendered pages still use this template.

The script also runs before the Sentry SDK is initialized. A failure is only captured if it lands after SDK init and before a bootstrap query reads the promise, so the resulting issue volume is a biased sample rather than a real failure rate.

How?

A failed response now rejects with a PreloadRequestError that keeps status and statusText. Network and JSON parse errors now reject with their original errors, because the catch-and-rethrow is gone.

Each request's outcome, status, and duration is recorded on window.__sentry_preload_results for the app to report as metrics after the SDK initializes. Attaching that handler also stops failed requests from surfacing as unhandled rejections. The bootstrap queries still receive the rejected promise and fall back to fetching through the API client.

Nothing reads window.__sentry_preload_results until the frontend change lands, so this can deploy first.

Fixes JAVASCRIPT-2XH0

Generated with Claude Code

The preload-data template rejected failed requests with a [status, statusText] tuple, and its catch block rethrew [error.status, error.statusText]. Arrays have no status property, so every failure became [undefined, undefined], which is reported as "Error: ," and loses both the HTTP status and the original error type.

Non-2xx responses now reject with a PreloadRequestError that carries status and statusText, and the catch-and-rethrow is removed so network and JSON parse errors keep their original type. The bootstrap query consumers already catch any rejection and refetch.

Fixes JAVASCRIPT-2XH0
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 6, 2026
The preload-data script runs before the Sentry SDK is initialized, so failures were only reported when the rejection happened to land after SDK init and before a bootstrap query consumed the promise.

Track each preload request's outcome, status, and duration on window.__sentry_preload_results so the app can report them as metrics once the SDK loads. Handling the rejection there also stops failed requests from surfacing as unhandled rejections, while the bootstrap queries still receive the rejected promise.
@billyvg billyvg changed the title fix(bootstrap): Reject preload requests with real errors fix(bootstrap): Report preload request failures as real errors and metrics Oct 6, 2026
@billyvg
billyvg marked this pull request as ready for review October 6, 2026 16:53
@billyvg
billyvg requested a review from a team as a code owner October 6, 2026 16:53
@billyvg
billyvg merged commit 69172bf into master Oct 6, 2026
70 checks passed
@billyvg
billyvg deleted the billyvong/fix/preload-data-rejection-errors branch October 6, 2026 20:40
billyvg added a commit that referenced this pull request Oct 7, 2026
Companion PR to #126592

## Slop

### Why?

The preload requests start before the Sentry SDK is initialized. A
failure is only captured if the rejection lands after SDK init and
before a bootstrap query reads the promise, so JAVASCRIPT-2XH0 misses
fast failures and over-counts pages that never read the data. These
failures are expected, and the app already recovers by refetching, so
metrics fit better than error events.

### How?

After the SDK initializes, the app reports each preload request's
outcome from `window.__sentry_preload_results` (recorded by the preload
script in #126592) as a `ui.preload-request` distribution, with
`request`, `outcome`, `status` and `errorName` attributes.

The bootstrap queries now also count whether each request was served by
the preload or fell back to the API client: `ui.bootstrap-request` with
`preload: used | missing | failed`. The fallback requests themselves go
through the API client, so they're already measured as `ui.api-request`.

The standalone SPA preload now rejects with a `PreloadRequestError`
instead of resolving `null`, and records its outcomes the same way.

Works with or without #126592 deployed; without it there are no results
to report.

Refs JAVASCRIPT-2XH0

<sub>Generated with Claude Code</sub>
billyvg added a commit that referenced this pull request Oct 9, 2026
#126745)

### Why?

Preload request outcomes are now reported as metrics:
- #126592
- #126596

Some failures have no HTTP status (`TypeError`, `SyntaxError`), and the
metric alone doesn't say why they failed. We want to capture those as
exceptions.

### How?

Each failed request's result now includes the original error, so the app
can capture it once the SDK initializes. Either PR can deploy first: the
app ignores the field until the frontend PR lands.

Companion frontend PR:
- #126746

Refs JAVASCRIPT-2XH0

<sub>Generated with Claude Code</sub>
billyvg added a commit that referenced this pull request Oct 13, 2026
…6746)

### Why?

Preload request outcomes are now reported as metrics:
- #126592
- #126596

Some failures have no HTTP status (`TypeError`, `SyntaxError`), and the
metric alone doesn't say why they failed. We want to capture those as
exceptions.

### How?

Failures with an HTTP status stay metrics-only. Failures without one are
also sent with `captureException`, tagged with the request name and
grouped by error type, since they have no useful stack trace. Either PR
can deploy first: until the backend PR lands, only the standalone SPA
captures them.

Companion backend PR:
- #126745

Refs JAVASCRIPT-2XH0

<sub>Generated with Claude Code</sub>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants