feat: initialize Sentry in a preload module and widen capture - #3
Open
DASPRiD wants to merge 1 commit into
Open
Conversation
- Move Sentry.init from main.tsx into instrument.ts, imported first from entry.ts, so global handlers register before application code - Wire all three createRoot error handlers (uncaught, caught, recoverable) and drop the RootError capture effect the caught-error handler now covers - Wire browserTracingIntegration with the sample rate from a new VITE_APP_SENTRY_TRACES_SAMPLE_RATE env var, deployed as 0 - Emit source maps only when SENTRY_AUTH_TOKEN is present; without it the upload plugin self-disables, which also skipped the delete-after-upload step and shipped the maps to the public bucket
lart2150
requested changes
Aug 13, 2026
| @@ -0,0 +1,13 @@ | |||
| import * as Sentry from "@sentry/react"; | |||
Member
There was a problem hiding this comment.
could we make this a dynamic import based on VITE_APP_SENTRY_DSN?
| @@ -11,6 +11,7 @@ interface ImportMetaEnv { | |||
| {%- if sentry %} | |||
| readonly VITE_APP_SENTRY_DSN: string; | |||
Member
There was a problem hiding this comment.
should these be ?: or is something enforcing they are set?
|
|
||
| // Must be the first import executed in entry.ts so Sentry's global handlers are | ||
| // registered before any application code runs. | ||
| if (import.meta.env.VITE_APP_SENTRY_DSN) { |
Member
There was a problem hiding this comment.
I think this should check that all the variables are set instead of just VITE_APP_SENTRY_DSN
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.
Summary
Sentry.initout ofmain.tsxinto aninstrument.tsimported first fromentry.ts, so global handlers register before any application code (and before the Temporal polyfill's top-level await can fail). Non-sentry scaffolds skip the file via the synth ignore list.createRooterror handlers (uncaught, caught, recoverable) and drop theRootErrorcapture effect the caught-error handler now covers; wirebrowserTracingIntegrationwith aVITE_APP_SENTRY_TRACES_SAMPLE_RATEenv var deployed as 0, so tracing is a config flip rather than a code change.SENTRY_AUTH_TOKENis present. Without the token the upload plugin self-disables, which also skipped the delete-after-upload step and shipped the maps to the public bucket; non-sentry scaffolds keepsourcemap: truedeliberately.