pickstack

Preact + Sentry

Error monitoring and tracing with Sentry; off until you set a DSN. This page shows exactly what pickstack adds to a Preact 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 preact --modules sentry --yes
Customize in the configurator

Packages it adds

PackageVersionType
@sentry/browser^11.19.0runtime

New files

.env.example
VITE_SENTRY_DSN=
src/sentry.ts
import * as Sentry from "@sentry/browser";

/** 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

src/main.tsx (changed)
 import { render } from "preact"; import App from "./App";+import { initSentry } from "./sentry"; import "./index.css";  +initSentry();+  render(<App />, document.getElementById("app")!);  

Project files

Related templates