Skip to content

feat: initialize Sentry in a preload module and widen capture - #3

Open
DASPRiD wants to merge 1 commit into
mainfrom
sentry-improvements
Open

feat: initialize Sentry in a preload module and widen capture#3
DASPRiD wants to merge 1 commit into
mainfrom
sentry-improvements

Conversation

@DASPRiD

@DASPRiD DASPRiD commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Move Sentry.init out of main.tsx into an instrument.ts imported first from entry.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.
  • Wire all three React 19 createRoot error handlers (uncaught, caught, recoverable) and drop the RootError capture effect the caught-error handler now covers; wire browserTracingIntegration with a VITE_APP_SENTRY_TRACES_SAMPLE_RATE env var deployed as 0, so tracing is a config flip rather than a code change.
  • Emit source maps only when SENTRY_AUTH_TOKEN is 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 keep sourcemap: true deliberately.

- 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
@@ -0,0 +1,13 @@
import * as Sentry from "@sentry/react";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should check that all the variables are set instead of just VITE_APP_SENTRY_DSN

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants