H-5764: Setup Sentry UserFeedback + ErrorTracker#8241
Conversation
PR SummaryIntroduces Sentry-based monitoring and a generic error tracking abstraction in the demo site.
Written by Cursor Bugbot for commit 0011c00. This will update automatically on new commits. Configure here. |
🤖 Augment PR SummarySummary: This PR wires Sentry error tracking + user feedback into the Petrinaut demo site. Changes:
🤖 Was this summary useful? React with 👍 or 👎 |
| @@ -1,12 +1,30 @@ | |||
| import "./sentry/instrument.js"; | |||
| "./*.ts", | ||
| "./*.d.ts", | ||
| "main/app.tsx", | ||
| "sentry/init-sentry.ts" |
| Sentry.withScope((scope) => { | ||
| if (context) { | ||
| for (const [key, value] of Object.entries(context)) { | ||
| scope.setContext(key, value as Record<string, unknown>); |
| @@ -0,0 +1 @@ | |||
| SENTRY_DSN=https://5c0a691258164a68eac390cd10574484@o146262.ingest.us.sentry.io/4510663776141312 | |||
There was a problem hiding this comment.
This feels like it shouldn't be committed to the repo. I've added it as an environment variable in Vercel so it will be picked up when built in Vercel.
For local testing we can add a non-committed .env.local with the value.
There was a problem hiding this comment.
Yeah, I remove it, environment variable is certainly better.
| typeof import.meta.env.MODE === "string" | ||
| ? import.meta.env.MODE | ||
| : "development"; |
There was a problem hiding this comment.
Let's call this 'environment' as it's what it tends to be called elsewhere.
I know that Vite sets a special 'mode' variable, but we don't actually want to rely on this – it means that if someone does a production build locally and runs it, any errors will be sent to Sentry as production errors.
The only 'production' errors in Sentry should be those from the main production site, so we need to handle setting the environment manually (via Vercel environment variables, added in a file below).
| typeof import.meta.env.MODE === "string" | |
| ? import.meta.env.MODE | |
| : "development"; | |
| typeof import.meta.env.ENVIRONMENT === "string" | |
| ? import.meta.env.ENVIRONMENT | |
| : "development"; |
There was a problem hiding this comment.
MODE is a constant provided by Vite:
https://vite.dev/guide/env-and-mode#built-in-constants
We could provide our own but it would be repeating what is already available, or use PROD === true.
There was a problem hiding this comment.
Thanks and sorry for misreading/misunderstanding your point.
|
|
||
| interface ImportMetaEnv { | ||
| readonly SENTRY_DSN?: string; | ||
| readonly MODE: string; |
There was a problem hiding this comment.
| readonly MODE: string; | |
| readonly ENVIRONMENT: string; |
| const envDir = isLibMode ? undefined : path.resolve(__dirname); | ||
| const env = loadEnv(mode, envDir ?? process.cwd(), ""); | ||
|
|
||
| // Get SENTRY_DSN from environment variables |
There was a problem hiding this comment.
| // Get SENTRY_DSN from environment variables |
| const isLibMode = mode === "lib" || !!process.env.VITEST; | ||
|
|
||
| // Load environment variables from .env files | ||
| // For demo-site builds, load from the package root directory |
There was a problem hiding this comment.
| // For demo-site builds, load from the package root directory |
| const env = loadEnv(mode, envDir ?? process.cwd(), ""); | ||
|
|
||
| // Get SENTRY_DSN from environment variables | ||
| const sentryDsn = env.SENTRY_DSN ?? process.env.SENTRY_DSN; |
There was a problem hiding this comment.
Load the environment from Vercel (which will be either production for the main site or preview for preview builds)
See https://vercel.com/docs/frameworks/frontend/vite#environment-variables
| const sentryDsn = env.SENTRY_DSN ?? process.env.SENTRY_DSN; | |
| const sentryDsn = env.SENTRY_DSN ?? process.env.SENTRY_DSN; | |
| const environment = process.env.VITE_VERCEL_ENV ?? "development"; |
There was a problem hiding this comment.
This line only makes sense for the demo site build so maybe we should only inject it in there somehow?
There was a problem hiding this comment.
We can leave it in here for now
There was a problem hiding this comment.
define in the config works by text replacement (if I'm not mistaken)
So this won't be bundled in the library, because there won't be no reference to the global variable in the library.
There was a problem hiding this comment.
I'm gonna use define for that.
There was a problem hiding this comment.
@CiaranMn I updated to use define, with __SENTRY_DSN__ and __ENVIRONMENT__
| // Provide minimal process shim for TypeScript language service in browser | ||
| "process.versions": JSON.stringify({ pnp: undefined }), | ||
| // Expose SENTRY_DSN at build time | ||
| "import.meta.env.SENTRY_DSN": JSON.stringify(sentryDsn), |
There was a problem hiding this comment.
| "import.meta.env.SENTRY_DSN": JSON.stringify(sentryDsn), | |
| "import.meta.env.SENTRY_DSN": JSON.stringify(sentryDsn), | |
| "import.meta.env.ENVIRONMENT": environment, |
…ider to a new path and enhance error handling callbacks
…e; improve Sentry integration by injecting SENTRY_DSN directly into the application.
This will need a better solution soon.
7a07628 to
c0d3e32
Compare
f04e2f5 to
5b67a3b
Compare
…ENVIRONMENT in vite-env.d.ts and adjust Sentry initialization accordingly.
…t files in the 'sentry' directory.
…e: replace direct access to SENTRY_DSN with build-time injected constants, and streamline Sentry initialization to use these constants.

Demo
Kapture 2026-01-07 at 20.22.59.mp4 (uploaded via Graphite)
🌟 What is the purpose of this PR?
This PR adds Sentry User Feedback + Error Tracker inside Petrinaut demo website.
🔍 What does this change?
Error Tracker
Because we don't want Petrinaut to be directly coupled to Sentry:
ErrorTrackerContext<SentryErrorTrackerProvider>(only used in demo-website)This
SentryErrorTrackerProvideris still not used for now in the app, but will be extended later to add more granular tracking of user experience in the demo app.User Feedback
For now the User Feedback widget is the default one, this keeps it simple and prevents having to deal with React component props, or with design.
If we get a good Figma design, we'll be able customize this feedback button to place it properly in the UI.
Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
Given the User Feedback widget is the default one, it's on top of the UI and could possibly hide some things.
🐾 Next steps
In the future, we'll do more granular tracking of what happens in the app.
❓ How to test this?
Use latest Petrinaut deployment