createSentryTunnelRoute
Learn how to manually define a Sentry tunnel route in your TanStack Start app.
Available since: v10.51.0
If you can use the sentryTanstackStart Vite plugin, prefer its tunnelRoute option. It registers the route for you and automatically wires up the client tunnel option. Use createSentryTunnelRoute only when you need full control over the route file, the DSN allowlist, or can't use the Vite plugin.
The createSentryTunnelRoute helper returns a TanStack Start server-route configuration with a POST handler that forwards Sentry envelopes to Sentry's ingest servers. Use it inside a file route to expose a same-origin tunnel endpoint.
Create a server route at the path you want to tunnel through, and pass the list of DSNs you want to allow:
src/routes/monitor.tsimport { createFileRoute } from "@tanstack/react-router";
import * as Sentry from "@sentry/tanstackstart-react";
export const Route = createFileRoute("/monitor")({
server: Sentry.createSentryTunnelRoute({
allowedDsns: ["___PUBLIC_DSN___"],
}),
});
import { createFileRoute } from "@tanstack/react-router";
import * as Sentry from "@sentry/tanstackstart-react";
export const Route = createFileRoute("/monitor")({
server: Sentry.createSentryTunnelRoute({
allowedDsns: ["___PUBLIC_DSN___"],
}),
});
Then, set the matching tunnel option in your client Sentry.init() so the browser SDK sends events to your route instead of directly to Sentry:
src/router.tsxSentry.init({
dsn: "___PUBLIC_DSN___",
// ...
tunnel: "/monitor",
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
// ...
tunnel: "/monitor",
});
A list of DSN strings that the route is allowed to forward to. The route validates each incoming envelope against this list and rejects any DSN that isn't allowed.
If allowedDsns is omitted or empty, the route falls back to the DSN of the active server-side Sentry SDK at runtime. If neither is available, requests to the route return a 500 response.
src/routes/monitor.tsSentry.createSentryTunnelRoute({
allowedDsns: [
"https://public@o0.ingest.sentry.io/1",
"https://public@o0.ingest.sentry.io/2",
],
});
Sentry.createSentryTunnelRoute({
allowedDsns: [
"https://public@o0.ingest.sentry.io/1",
"https://public@o0.ingest.sentry.io/2",
],
});
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").