---
title: "Manual Setup"
description: "Learn how to manually set up and configure Sentry in your TanStack Start React application and capturing your first events in Sentry."
url: https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup/
---

# Manual Setup for TanStack Start React

Runtime

* [Node.js (current page)](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md)
* [Cloudflare](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup/cloudflare.md)

Looking for automatic setup with `sentry init`? Follow the [TanStack Start React quickstart](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react.md) instead. Continue with this guide to set up Sentry manually.

This guide walks you through setting up Sentry in a [TanStack Start (React)](https://tanstack.com/start/latest/docs/framework/react/overview) app on Node.js. For [TanStack Router (React)](https://tanstack.com/router/latest/docs/framework/react/overview), see our [React TanStack Router guide](https://docs.sentry.io/platforms/javascript/guides/react/features/tanstack-router.md).

## [Prerequisites](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#prerequisites)

You need:

* A Sentry [account](https://sentry.io/signup/) and [project](https://docs.sentry.io/product/projects.md)
* Your application up and running
* `@tanstack/react-start` 1.169.0 or newer

## [Install](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#install)

Run the command for your preferred package manager to add the SDK package to your application:

```bash
npm install @sentry/tanstackstart-react --save
```

*Other available variations of the above snippet: yarn, pnpm*

## [Configure](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#configure)

**Error Monitoring** starts working as soon as you call `Sentry.init()`. **Logs** and **Application Metrics** need no extra configuration, and you'll learn how to send them in steps [#3](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#send-logs) and [#4](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#send-application-metrics-). This guide also enables **Tracing**, **Session Replay**, and **User Feedback**.

Want to learn more about these features?

* [**Issues**](https://docs.sentry.io/product/issues.md) (always enabled): Sentry's core error monitoring product that automatically reports errors, uncaught exceptions, and crashes. If you have something that looks like an exception, Sentry can capture it.
* [**Tracing**](https://docs.sentry.io/product/tracing.md): Track software performance while seeing the impact of errors across multiple systems. For example, distributed tracing allows you to follow a request from the frontend to the backend and back. On the server, this includes [Agent Tracing](https://docs.sentry.io/product/agents.md): supported AI libraries are instrumented automatically, so you can see model calls, tool executions, and token usage.
* [**Session Replay**](https://docs.sentry.io/product/session-replay.md): Get to the root cause of an issue faster by viewing a video-like reproduction of what users saw in your app before, during, and after the problem.
* [**Logs**](https://docs.sentry.io/product/logs.md): Centralize and analyze your application logs to correlate them with errors and performance issues. Search, filter, and visualize log data to understand what's happening in your applications.
* [**Application Metrics**](https://docs.sentry.io/product/metrics.md) (always enabled): Track and analyze custom application metrics, such as response times and database query durations, to understand trends and patterns in your application's performance and behavior over time.
* [**User Feedback**](https://docs.sentry.io/product/user-feedback.md): Collect feedback directly from users when they encounter errors, allowing them to describe what happened and provide context that helps you understand and resolve issues faster.

### [Configure Client-Side Sentry](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#configure-client-side-sentry)

Create an `instrument.client.ts` file in your `src/` directory and initialize Sentry in it.

The snippet also turns on:

* Tracing: via [`tracesSampleRate`](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/configuration/options.md#tracesSampleRate)
* Session Replay: via `replayIntegration()`, sampled with [`replaysSessionSampleRate`](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/configuration/options.md#replaysSessionSampleRate) and [`replaysOnErrorSampleRate`](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/configuration/options.md#replaysOnErrorSampleRate)
* User Feedback: via [`feedbackIntegration()`](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/user-feedback/configuration.md)

Don't need a feature? Remove its integration and options from the snippet.

```tsx
import * as Sentry from "@sentry/tanstackstart-react";

Sentry.init({
  dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",

  integrations: [
    // Registers the Sentry Browser Tracing integration
    Sentry.replayIntegration(),
    // Enables User Feedback
    Sentry.feedbackIntegration({
      // Additional SDK configuration goes in here, for example:
      colorScheme: "system",
    }),
  ],

  // Enables Tracing.
  // Set to 1.0 to capture 100% of spans for tracing.
  // We recommend reducing this value in production.
  tracesSampleRate: 1.0,

  // Capture replays for 10% of all sessions,
  // plus for 100% of sessions with an error
  // Requires Sentry.replayIntegration()
  replaysSessionSampleRate: 0.1,
  replaysOnErrorSampleRate: 1.0,
});
```

Then import this file as the **first import** in your [client entry point](https://tanstack.com/start/latest/docs/framework/react/guide/client-entry-point) `src/client.tsx`. This ensures Sentry initializes before any other code runs, so errors and events before hydration are captured.

```tsx
// Sentry initialization should be imported first!
import "./instrument.client";

import { StartClient } from "@tanstack/react-start/client";
import { StrictMode, startTransition } from "react";
import { hydrateRoot } from "react-dom/client";

startTransition(() => {
  hydrateRoot(
    document,
    <StrictMode>
      <StartClient />
    </StrictMode>,
  );
});
```

Then add the TanStack Router browser tracing integration in your `src/router.tsx` file:

```tsx
+import * as Sentry from "@sentry/tanstackstart-react";
 import { createRouter } from '@tanstack/react-router'

// Create a new router instance
export const getRouter = () => {
  const router = createRouter();

+ if (!router.isServer) {
+   Sentry.addIntegration(
+     Sentry.tanstackRouterBrowserTracingIntegration(router)
+   );
+ }

  return router;
}
```

### [Configure Server-Side Sentry](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#configure-server-side-sentry)

Create an instrument file `instrument.server.mjs` in the root of your project. In this file, initialize the Sentry SDK for your server.

This snippet also turns on:

* Tracing: via [`tracesSampleRate`](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/configuration/options.md#tracesSampleRate)

```tsx
import * as Sentry from "@sentry/tanstackstart-react";

Sentry.init({
  dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",

  // Enables Tracing.
  // Set to 1.0 to capture 100% of spans for tracing.
  // We recommend reducing this value in production.
  tracesSampleRate: 1.0,
});
```

#### [Add the sentryTanstackStart Vite Plugin](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#add-the-sentrytanstackstart-vite-plugin)

Configure `sentryTanstackStart` in your `vite.config.ts`.

By default, this plugin manages source map uploads. When tracing is enabled, it also automatically instruments middlewares for tracing. For all available options, see the [Vite Plugin documentation](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/features/sentryTanstackStart.md).

```typescript
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: "<your-org-slug>",
      project: "<your-project-slug>",
      authToken: process.env.SENTRY_AUTH_TOKEN,
    }),
  ],
});
```

To keep your auth token secure, always store it in an environment variable instead of directly in your files:

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

```bash
SENTRY_AUTH_TOKEN=<your-sentry-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`](https://vite.dev/guide/api-javascript#loadenv) helper.

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

```javascript
import { defineConfig, loadEnv } from "vite";

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

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

#### [Instrument the Server Entry Point](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#instrument-the-server-entry-point)

To capture server-side errors and tracing data, you need to explicitly define a [server entry point](https://tanstack.com/start/latest/docs/framework/react/guide/server-entry-point) in your application and wrap your request handler with `wrapFetchWithSentry`.

Create a `src/server.ts` file in your project. Pass `opts` on to the handler, so the request context that TanStack Start passes to it isn't lost:

```typescript
import { wrapFetchWithSentry } from "@sentry/tanstackstart-react";
import handler, {
  createServerEntry,
} from "@tanstack/react-start/server-entry";
import type { ServerEntry } from "@tanstack/react-start/server-entry";

const requestHandler: ServerEntry = wrapFetchWithSentry({
  fetch(request, opts) {
    return handler.fetch(request, opts);
  },
});

export default createServerEntry(requestHandler);
```

#### [Load the Server Config When the Server Starts](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#load-the-server-config-when-the-server-starts)

Available since: `v11.13.0`

If your app builds with [Nitro](https://nitro.build/) for a Node.js runtime, the `sentryTanstackStart` Vite plugin loads your server config for you in production builds:

* It looks for `instrument.server.{ts,mts,js,mjs}` in the project root, then in `src/`.
* It bundles the file into the Nitro server build and loads it when the server starts.
* It instruments database drivers and other libraries at build time.

You start your production build as usual, without the `--import` flag.

`vite dev` doesn't create a server build, so in development, load the file with the `--import` flag in the `NODE_OPTIONS` environment variable:

```json
{
  "scripts": {
     "build": "vite build",
-    "dev": "vite dev --port 3000",
+    "dev": "NODE_OPTIONS='--import ./instrument.server.mjs' vite dev --port 3000",
     "start": "node .output/server/index.mjs",
  }
}
```

This doesn't apply to Cloudflare. For Cloudflare Workers, follow the [Cloudflare guide](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup/cloudflare.md).

##### [Without Nitro](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#without-nitro)

The plugin loads the server config through a Nitro hook. If you deploy to Node.js without Nitro, load `instrument.server.mjs` yourself: add the `--import` flag to your start command, or import the file at the top of `src/server.ts`.

### [Capture TanStack Start React Errors](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#capture-tanstack-start-react-errors)

#### [Capture Server-Side Errors](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#capture-server-side-errors)

To capture server-side errors from HTTP requests and server function calls, add Sentry's global middlewares to `createStart()` in your `src/start.ts` file. Since version 11.15.0, `sentryGlobalFunctionMiddleware` also creates a span for every server function call, including calls from other server functions or from loaders on the server. Without this middleware, Sentry doesn't create server function spans.

The Sentry middleware should be the first middleware in the arrays to ensure all errors are captured.

A custom `src/start.ts` turns off the CSRF protection that TanStack Start adds to server functions by default, so the snippet adds it back with `createCsrfMiddleware`.

```tsx
import {
  sentryGlobalFunctionMiddleware,
  sentryGlobalRequestMiddleware,
} from "@sentry/tanstackstart-react";
import { createCsrfMiddleware, createStart } from "@tanstack/react-start";

// Assign the middleware to a variable. Sentry's Vite plugin
// doesn't instrument a middleware array that contains a function call.
const csrfMiddleware = createCsrfMiddleware({
  filter: (ctx) => ctx.handlerType === "serverFn",
});

export const startInstance = createStart(() => {
  return {
    requestMiddleware: [sentryGlobalRequestMiddleware, csrfMiddleware],
    functionMiddleware: [sentryGlobalFunctionMiddleware],
  };
});
```

#### [Capture Errors in Route Loaders](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#capture-errors-in-route-loaders)

If a `loader` or `beforeLoad` throws while a page renders on the server, the router catches the error and shows the route's error component. Sentry doesn't report these errors automatically. To report them, set `onError` on the route:

```tsx
import * as Sentry from "@sentry/tanstackstart-react";
import { createFileRoute } from "@tanstack/react-router";

export const Route = createFileRoute("/posts")({
  loader: () => fetchPosts(),
  onError: (error) => {
    Sentry.captureException(error);
  },
});
```

TanStack Router has no router-wide `onError`, so set it on each route.

#### [Capture Errors in Error Boundaries and Components (Optional)](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#capture-errors-in-error-boundaries-and-components-optional)

Sentry automatically captures unhandled client-side errors. Errors caught by your own error boundaries aren't captured unless you report them manually:

##### [Custom Error Boundary](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#custom-error-boundary)

To report the errors that an error boundary catches, use Sentry's `ErrorBoundary` component instead of your own. Learn more in [React Error Boundary](https://docs.sentry.io/platforms/javascript/guides/react/features/error-boundary.md).

##### [TanStack Router `errorComponent`](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#tanstack-router-errorcomponent)

Use Sentry's `captureException` function inside a `useEffect` hook within your `errorComponent`:

```tsx
import { createRoute } from "@tanstack/react-router";
import * as Sentry from "@sentry/tanstackstart-react";
import { useEffect } from "react";

const route = createRoute({
  errorComponent: ({ error }) => {
    useEffect(() => {
      Sentry.captureException(error)
    }, [error])

    return (
      // ...
    )
  }
})
```

### [Add Readable Stack Traces With Source Maps](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#add-readable-stack-traces-with-source-maps)

If you configured the `sentryTanstackStart` Vite plugin [in an earlier step](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#add-the-sentrytanstackstart-vite-plugin), source maps are automatically uploaded during production builds.

If you need more control over the upload process, see our [source maps guide](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/sourcemaps.md) for manual configuration options.

### [Avoid Ad Blockers With Tunneling](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#avoid-ad-blockers-with-tunneling)

Ad blockers and corporate firewalls often block requests to `*.sentry.io`, which can cause events to be dropped before they reach Sentry. To work around this, send them through a tunnel on your own origin.

Set `tunnel: true` in your browser `Sentry.init`, and add `serveTunnelIntegration` to your server `Sentry.init`:

```tsx
Sentry.init({
  dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
  tunnel: true,
});
```

```javascript
Sentry.init({
  dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
  integrations: [Sentry.serveTunnelIntegration()],
});
```

Learn more in [Tunneling](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/configuration/tunneling.md).

### [Control the Data You Send to Sentry](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#control-the-data-you-send-to-sentry)

By default, the SDK sends user identity data (IP address, ID, and similar) and other data like HTTP bodies and URL query parameters. This will give you rich debugging context.

The SDK always filters sensitive values whose keys match a built-in denylist, such as `auth` or `password`, and sends `[Filtered]` instead.

To send less data, turn off the categories you don't need in the `dataCollection` option. For the full list of categories and their defaults, [see the `dataCollection` options](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/configuration/options.md#dataCollection).

```javascript
Sentry.init({
  dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
  dataCollection: {
    userInfo: false,
    // other categories
  },
});
```

## [Send Logs](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#send-logs)

Use `Sentry.logger` to send logs at different levels, such as `info`, `warn`, or `error`. You can pass any attributes you want and search or filter by them later. See [Set Up Logs](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/logs.md) for all available logging methods and the syntax for formatting messages.

```javascript
Sentry.logger.info("User example action completed");

Sentry.logger.warn("Slow operation detected", {
  operation: "data_fetch",
  duration: 3500,
});

Sentry.logger.error("Validation failed", {
  form_field: "email",
  reason: "Invalid email",
});
```

If you already use `console`, capture those calls as Sentry Logs with [`consoleLoggingIntegration`](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/logs.md#console-integration). We also provide integrations for:

* [Consola](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/logs.md#console-integration)
* [Pino](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/configuration/integrations/pino.md)

## [Send Application Metrics NEW](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#send-application-metrics-)

Use `Sentry.metrics` to send counters, gauges, and distributions from your app to Sentry. You can pass any attributes you want and search or filter by them later. See [Set Up Metrics](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/metrics.md) for all available metric types and configuration options.

```javascript
Sentry.metrics.count("checkout.failed", 1);

Sentry.metrics.gauge("time_since_refresh", 4, { unit: "hour" });

Sentry.metrics.distribution("api_latency", 187, {
  unit: "millisecond",
  attributes: { endpoint: "/api/orders" },
});
```

On Node.js, [`nodeRuntimeMetricsIntegration`](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/configuration/integrations/noderuntimemetrics.md) also collects runtime health metrics automatically.

## [Verify](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#verify)

Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.

Add a test button to one of your pages, which will trigger an error that Sentry will capture when you click it:

```tsx
<button
  type="button"
  onClick={() => {
    throw new Error("Sentry Test Error");
  }}
>
  Break the world
</button>;
```

##### Important

Errors triggered from within your browser's developer tools (like the browser console) are sandboxed, so they will not trigger Sentry's error monitoring.

### [View Captured Data in Sentry](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#view-captured-data-in-sentry)

Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear).

Need help locating captured data in your Sentry project?

* Open the [**Issues**](https://sentry.io/orgredirect/organizations/:orgslug/issues/) page and select an error from the issues list to view the full details and context of this error. For more details, see the [Issue Details documentation](https://docs.sentry.io/product/issues/issue-details.md).
* Open the [**Traces**](https://sentry.io/orgredirect/organizations/:orgslug/explore/traces/) page and select a trace to reveal more information about each span, its duration, and any errors. For an interactive UI walkthrough, click [here](https://docs.sentry.io/product/sentry-basics/getting-started-tutorial/generate-first-error.md#ui-walkthrough).
* Open the [**Replays**](https://sentry.io/orgredirect/organizations/:orgslug/replays/) page and select an entry from the list to get a detailed view where you can replay the interaction and get more information to help you troubleshoot.
* Open the [**Logs**](https://sentry.io/orgredirect/organizations/:orgslug/explore/logs/) page and filter by service, environment, or search keywords to view log entries from your application. For an interactive UI walkthrough, click [here](https://docs.sentry.io/product/logs.md#overview).
* Open the [**Application Metrics**](https://sentry.io/orgredirect/organizations/:orgslug/explore/metrics) page to view and analyze your metrics. For more details, see this [interactive walkthrough](https://docs.sentry.io/product/metrics.md#overview).
* Open the [**User Feedback**](https://sentry.io/orgredirect/organizations/:orgslug/feedback/) page and click on individual feedback to see more details all in one view. For more information, click [here](https://docs.sentry.io/product/user-feedback.md).

## [Next Steps](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#next-steps)

At this point, you should have integrated Sentry into your TanStack Start React application. Here's what to explore next:

* Explore [practical guides](https://docs.sentry.io/get-started/guides.md) on what to monitor, log, track, and investigate after setup
* [Set up Agent Tracing](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/agent-tracing.md) to follow agent runs from system prompt to final output, capturing every model call, tool execution, and handoff as a span

Are you having problems setting up the SDK?

* Find various topics in [Troubleshooting](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/troubleshooting.md)
* [Get support](https://www.sentry.help/en/)

## Pages in this section

- [Cloudflare](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup/cloudflare.md)

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
