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

# Manual Setup | Sentry for TanStack Start React

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.

##### Beta

This SDK is compatible with TanStack Start 1.0 RC and is currently in **beta**. Beta features are still in progress and may have bugs. Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if you have any feedback or concerns.

This guide walks you through setting up Sentry in a [TanStack Start (React)](https://tanstack.com/start/latest/docs/framework/react/overview) app. 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

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

Choose the features you want to configure, and this guide will show you how:

Error Monitoring\[ ]Tracing\[ ]Session Replay\[ ]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 unhandled rejections. 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.
* [**Session Replay**](https://docs.sentry.io/product/session-replay/web.md): Get to the root cause of an issue faster by viewing a video-like reproduction of what was happening in the user's browser 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.
* [**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.
* [**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.

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

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)

### [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.

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

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

  integrations: [
    // ___PRODUCT_OPTION_START___ session-replay
    Sentry.replayIntegration(),
    // ___PRODUCT_OPTION_END___ session-replay
    // ___PRODUCT_OPTION_START___ user-feedback
    Sentry.feedbackIntegration({
      // Additional SDK configuration goes in here, for example:
      colorScheme: "system",
    }),
    // ___PRODUCT_OPTION_END___ user-feedback
  ],

  // ___PRODUCT_OPTION_START___ performance
  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for tracing.
  // We recommend adjusting this value in production.
  // Learn more at https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
  tracesSampleRate: 1.0,
  // ___PRODUCT_OPTION_END___ performance
  // ___PRODUCT_OPTION_START___ session-replay

  // Capture Replay for 10% of all sessions,
  // plus for 100% of sessions with an error.
  // Learn more at https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration
  replaysSessionSampleRate: 0.1,
  replaysOnErrorSampleRate: 1.0,
  // ___PRODUCT_OPTION_END___ session-replay
});
```

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:

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

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

  // ___PRODUCT_OPTION_START___ performance
  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for tracing.
  // We recommend adjusting this value in production
  // Learn more at
  // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
  tracesSampleRate: 1.0,
  // ___PRODUCT_OPTION_END___ performance
});
```

#### [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`.

Follow the section below that matches your deployment setup:

#### [With `--import` Flag (e.g. Node.js Server)](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#with---import-flag-eg-nodejs-server)

Use this setup when you can configure Node.js CLI flags.

Create a `src/server.ts` file in your project:

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

export default createServerEntry(
  wrapFetchWithSentry({
    fetch(request: Request) {
      return handler.fetch(request);
    },
  }),
);
```

##### [Move the Sentry Server Config File for Production Usage](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#move-the-sentry-server-config-file-for-production-usage)

For production monitoring, you need to move the Sentry server config file to your build output. The exact location depends on where your build artifacts are deployed (for example, `"/dist"`, `".output/server"` or a platform-specific directory). For example, when using Nitro, copy the instrumentation file to `".output/server"` as shown in the example on the right.

```json
{
  "scripts": {
-     "build": "vite build",
+     "build": "vite build && cp instrument.server.mjs .output/server",
  }
}
```

##### [Load Instrumentation on Startup](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#load-instrumentation-on-startup)

To load `instrument.server.mjs`, add the `--import` flag either directly to your run command or to the `NODE_OPTIONS` environment variable.

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

#### [Without `--import` Flag](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#without---import-flag)

Use this setup when you can't configure Node.js CLI flags or environment variables at runtime (for example, when deploying to serverless platforms like Vercel or Netlify).

##### Restrictions

You can only instrument native Node.js APIs (such as `fetch` and the `http` module) with this installation method. This means that the Sentry SDK will not capture data from database calls, queues, ORMs, third-party libraries, or other framework-specific data. Thus, we recommend you follow the [`--import` flag setup instructions](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#with---import-flag-eg-nodejs-server) if possible.

This setup doesn't work for Cloudflare deployments.

Create a `src/server.ts` file in your project and import the server instrumentation file directly at the top of your server entry point.

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

export default createServerEntry(
  wrapFetchWithSentry({
    fetch(request: Request) {
      return handler.fetch(request);
    },
  }),
);
```

### [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.

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

SSR rendering exceptions are not captured by the middleware. Use `captureException` to manually capture those errors.

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

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

#### [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)

Wrap your custom `ErrorBoundary` component with [`withErrorBoundary`](https://docs.sentry.io/platforms/javascript/guides/react/features/error-boundary.md):

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

class MyErrorBoundary extends React.Component {
  // ...
}

export const MySentryWrappedErrorBoundary = Sentry.withErrorBoundary(
  MyErrorBoundary,
  {
    // ... sentry error wrapper options
  },
);
```

##### [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";

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

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

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

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 (Optional)](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/manual-setup.md#avoid-ad-blockers-with-tunneling-optional)

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, you can tunnel events through a same-origin route in your TanStack Start app.

The `sentryTanstackStart` Vite plugin can register a tunnel route for you and automatically wire up the client `tunnel` option.

Setting `tunnelRoute: true` generates an opaque route for each dev session and production build, making it harder for ad blockers to target. See the [`sentryTanstackStart`](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/features/sentryTanstackStart.md#tunnel-route) feature page for static paths and the full set of options.

If you can't use the Vite plugin, or need full control over the route file and DSN allowlist, use [`createSentryTunnelRoute`](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/features/createSentryTunnelRoute.md) to define the route yourself.

```typescript
import { defineConfig } from "vite";
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
import { sentryTanstackStart } from "@sentry/tanstackstart-react/vite";

export default defineConfig({
  plugins: [
    tanstackStart(),
    sentryTanstackStart({
      tunnelRoute: true,
    }),
  ],
});
```

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

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
  },
});
```

## [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.

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

To verify that Sentry captures errors and creates issues in 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.

Then, open the page in a browser and click the button to trigger a frontend error.

##### 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.

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

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

To test tracing, create a new file like `src/routes/api/sentry-example.ts` to create a test route `/api/sentry-example`:

```typescript
import { createFileRoute } from "@tanstack/react-router";
import { json } from "@tanstack/react-start";

export const Route = createFileRoute("/api/sentry-example")({
  server: {
    handlers: {
      GET: () => {
        throw new Error("Sentry Example Route Error");
        return new Response(
          JSON.stringify({ message: "Testing Sentry Error..." }),
          {
            headers: {
              "Content-Type": "application/json",
            },
          },
        );
      },
    },
  },
});
```

Next, update your test button to call this route and throw an error if the response isn't `ok`.

Open the page in a browser and click the button to trigger two errors:

* a frontend error
* an error within the API route

Additionally, this starts a performance trace to measure the time it takes for the API request to complete.

```tsx
<button
  type="button"
  onClick={async () => {
    await Sentry.startSpan(
      {
        name: "Example Frontend Span",
        op: "test",
      },
      async () => {
        const res = await fetch("/api/sentry-example");
        if (!res.ok) {
          throw new Error("Sentry Example Frontend Error");
        }
      },
    );
  }}
>
  Break the world
</button>;
```

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

To verify that Sentry catches your logs, add some log statements to your application:

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

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

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

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

[Application Metrics](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/metrics.md) are enabled by default.

Send test metrics from your app to verify that metrics are arriving in Sentry:

In a Node.js runtime, you can use the [NodeRuntimeMetrics](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/noderuntimemetrics.md) integration to automatically collect Node.js runtime health metrics.

```javascript
Sentry.metrics.count("checkout.failed", 1);
Sentry.metrics.gauge("queue.depth", 42);
Sentry.metrics.distribution("api_latency", 187, {
  unit: "millisecond",
});
```

### [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 the captured errors 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 [**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).
* 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).

## [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 and should already be sending data to your Sentry project.

Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:

* Explore [practical guides](https://docs.sentry.io/get-started/guides.md) on what to monitor, log, track, and investigate after setup
* Learn how to [manually capture errors](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/usage.md)
* Continue to [customize your configuration](https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/configuration.md)
* Get familiar with [Sentry's product features](https://docs.sentry.io/product.md) like tracing, insights, and alerts

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