React + Sentry
Error monitoring and tracing with Sentry; off until you set a DSN. This page shows exactly what pickstack adds to a React project for Sentry: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.
$ npm create pickstack@latest my-app -- --framework react --modules sentry --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@sentry/react | ^11.19.0 | runtime |
New files
VITE_SENTRY_DSN=
import * as Sentry from "@sentry/react";
/** Sends errors and traces to Sentry; stays off until the DSN is set (see .env.example). */
export function initSentry() {
const dsn = import.meta.env.VITE_SENTRY_DSN;
if (!dsn) return;
Sentry.init({
dsn,
integrations: [Sentry.browserTracingIntegration()],
// Traces 10% of page loads; raise it while trying things out.
tracesSampleRate: 0.1,
});
}
Changes to existing files
import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import App from "./App";+import { initSentry } from "./sentry"; import "./index.css"; +initSentry();+ createRoot(document.getElementById("root")!).render( <StrictMode> <App />⋯ 3 unchanged lines
Project files
.env.example.gitignoreREADME.mdindex.htmlpackage.jsonsrc/App.tsxsrc/components/Counter.tsxsrc/index.csssrc/main.tsxsrc/sentry.tstsconfig.jsonvite.config.ts