sentryTanstackStart

Learn about the sentryTanstackStart Vite plugin.

Available since: v10.35.0

The sentryTanstackStart Vite plugin simplifies source map configuration for TanStack Start applications. It automatically handles source map generation and upload to Sentry during production builds.

To automatically upload source maps, you need to provide your Sentry auth token, organization, and project slugs in your Vite configuration. The plugin then, by default, automatically enables hidden source maps and deletes .map files after upload.

Make sure you add your auth token to your CI, if you are using one to deploy your application.

Add your auth token to your environment:

.env
Copied
SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
Using environment variables in Vite configs

Vite doesn't automatically load .env files into process.env when evaluating the config file. If you store your auth token in a .env file and want to access it via process.env.SENTRY_AUTH_TOKEN, use Vite's loadEnv helper:

vite.config.js
Copied
import { defineConfig, loadEnv } from "vite";

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), "");

  return {
    plugins: [
      sentryVitePlugin({
        authToken: env.SENTRY_AUTH_TOKEN,
        // ...
      }),
    ],
  };
});

Alternatively, use a .env.sentry-build-plugin file, which the Sentry plugin reads automatically.

Configure sentryTanstackStart in your vite.config.ts:

vite.config.ts
Copied
import { defineConfig } from "vite";
import { sentryTanstackStart } from "@sentry/tanstackstart-react/vite";
import { tanstackStart } from "@tanstack/react-start/plugin/vite";

export default defineConfig({
  plugins: [
    tanstackStart(),
    // other plugins - sentryTanstackStart should be last
    sentryTanstackStart({
      org: "___ORG_SLUG___",
      project: "___PROJECT_SLUG___",
      authToken: process.env.SENTRY_AUTH_TOKEN,
    }),
  ],
});

The plugin passes through all options to the underlying @sentry/vite-plugin. See the Sentry Vite Plugin documentation for the full list of available options.

Available since: v10.37.0

The plugin automatically instruments all TanStack Start middlewares for tracing by default. To disable this behavior:

vite.config.ts
Copied
sentryTanstackStart({
  // ...
  autoInstrumentMiddleware: false,
}),

Available since: v10.55.0

The reactComponentAnnotation option annotates your React components with data-sentry-component and data-sentry-source-file attributes at build time. This lets you see component names instead of generic selectors in Session Replay, breadcrumbs, and performance monitoring.

vite.config.ts
Copied
sentryTanstackStart({
  // ...
  reactComponentAnnotation: {
    enabled: true,
  },
}),

To exclude specific components from annotation:

vite.config.ts
Copied
sentryTanstackStart({
  // ...
  reactComponentAnnotation: {
    enabled: true,
    ignoredComponents: ["MyInternalComponent"],
  },
}),

Available since: v10.51.0

The tunnelRoute option registers a same-origin TanStack Start server route that forwards Sentry envelopes to Sentry's ingest servers. It also automatically sets the client tunnel option in Sentry.init() so browser events go through that route. This helps avoid ad blockers and corporate firewalls that block requests to *.sentry.io.

tunnelRoute accepts three shapes:

Generates an opaque, unguessable route path for each dev session and production build. Because the path changes between builds, ad blockers can't reliably target it.

vite.config.ts
Copied
sentryTanstackStart({
  tunnelRoute: true,
}),

Pass a string to use a fixed route path. This is easier to reason about, but a known path is easier for ad blockers to add to a list.

vite.config.ts
Copied
sentryTanstackStart({
  tunnelRoute: "/monitor",
}),

Use the object form to control the DSN allowlist or set a static path explicitly:

vite.config.ts
Copied
sentryTanstackStart({
  tunnelRoute: {
    allowedDsns: ["___PUBLIC_DSN___"],
    path: "/monitor",
  },
}),
  • allowedDsns — only envelopes targeting one of these DSNs are forwarded. If omitted or empty, the route falls back to the DSN of the active server-side Sentry SDK at runtime.
  • path — the public route path. If omitted, an opaque path is generated (same behavior as tunnelRoute: true).
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").