Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions docs/platforms/javascript/guides/react-router/bun.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
title: React Router Framework on Bun
sidebar_title: Quick Start (Bun)
sidebar_order: 0.7
description: Learn how to set up Sentry in your React Router app (v7.15+) that runs on Bun and capture your first errors and traces.
runtime: bun
---

This guide sets up Sentry in a React Router app in framework mode that you build with Vite and serve with `react-router-serve` on Bun. At the end, your app sends errors, traces, logs, and session replays to Sentry.

## Prerequisites

You need:

- A Sentry [account](https://sentry.io/signup/) and [project](/product/projects/)
- A React Router app in framework mode, version `7.15.0` or above
- [Bun](https://bun.sh/)

<StepConnector selector="h2" showNumbers={true}>

## Install

Add the Sentry React Router SDK for your app and the Sentry Bun SDK for your server:

```bash
bun add @sentry/react-router @sentry/bun
```

## 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](#send-logs) and [#4](#send-application-metrics-).
This guide also enables **Tracing**, **Session Replay**, and **User Feedback**.

<Include name="quick-start-features-expandable-cloudflare-frameworks" />

<Include name="react-router/client-setup" />

### Configure Server-Side Sentry

Create a file called `instrument.server.mjs` in the root of your project, and initialize Sentry with the Bun SDK. Don't use `Sentry.init()` from `@sentry/react-router` on the server: it's made for Node.js.

```javascript {filename: instrument.server.mjs}
import * as Sentry from "@sentry/bun";

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

<Include name="react-router/server-entry" />

To use a Content Security Policy nonce or your own `handleRequest` or `handleError` logic, see the <PlatformLink to="/manual-setup/#configure-server-side-sentry">manual setup</PlatformLink>.

<Include name="react-router/source-maps" />

Keep the plugin even if you don't upload source maps: on Bun, it's the only way to get spans for packages such as database clients. You don't need `sentryBunPlugin` from the [Bun guide](/platforms/javascript/guides/bun/). That plugin is for apps that you build with `Bun.build()`, and Vite builds your React Router app.

### Start Your App

Preload `instrument.server.mjs` and run the `react-router-serve` script with Bun. Update the `start` script in your `package.json`:

```json {filename: package.json}
"scripts": {
"start": "bun --preload ./instrument.server.mjs ./node_modules/@react-router/serve/bin.cjs ./build/server/index.js"
}
```

Use the path of the script file, not the `react-router-serve` command. With the command, the preloaded file doesn't apply to the server, and Sentry receives no data.

When the server starts, Bun shows the message `[Sentry] No diagnostics-channel injection detected`. You can ignore it: the Sentry Vite plugin instruments the packages in your server build.

On Bun, you get no spans for the Express middleware of `react-router-serve`, because Express isn't part of your server build. Errors, request spans, spans for loaders and actions, and outgoing `fetch` requests work.

### Control the Data You Send to Sentry

<PlatformContent includePath="getting-started-data-collection" />

<Include name="react-router/logs-metrics-verify" />

## Next Steps

At this point, you should have integrated Sentry into your React Router Framework application on Bun. Here's what to explore next:

- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup
- <PlatformLink to="/troubleshooting/#dealing-with-ad-blockers">Set up tunneling</PlatformLink> to avoid ad blockers blocking Sentry events
- Learn more about the [Sentry Bun SDK](/platforms/javascript/guides/bun/)

<Expandable permalink={false} title="Are you having problems setting up the SDK?">

- Find various topics in <PlatformLink to="/troubleshooting/">Troubleshooting</PlatformLink>
- [Get support](https://www.sentry.help/en/)

</Expandable>

</StepConnector>
176 changes: 176 additions & 0 deletions docs/platforms/javascript/guides/react-router/cloudflare.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
---
title: React Router Framework on Cloudflare
sidebar_title: Quick Start (Cloudflare)
sidebar_order: 0.5
description: Learn how to set up Sentry in your React Router app (v7.15+) deployed on Cloudflare Workers and capture your first errors and traces.
runtime: cloudflare
---

<Alert level="info">

Using Shopify Hydrogen? Follow the [Hydrogen with React Router](/platforms/javascript/guides/react-router/hydrogen/) guide.

</Alert>

This guide sets up Sentry in a React Router app in framework mode that runs on Cloudflare Workers. At the end, your app sends errors, traces, logs, and session replays to Sentry. The guide is for apps that you build with Vite and `@cloudflare/vite-plugin`, for example an app made with [Cloudflare's React Router guide](https://developers.cloudflare.com/workers/framework-guides/web-apps/react-router/).

## Prerequisites

You need:

- A Sentry [account](https://sentry.io/signup/) and [project](/product/projects/)
- A React Router app in framework mode, version `7.15.0` or above, that uses `@cloudflare/vite-plugin`
- `@sentry/react-router` and `@sentry/cloudflare` version `11.8.0` or above

<StepConnector selector="h2" showNumbers={true}>

## Install

Add the Sentry React Router SDK for your app and the Sentry Cloudflare SDK for your Worker:

```bash {tabTitle:npm}
npm install @sentry/react-router @sentry/cloudflare --save
```

```bash {tabTitle:yarn}
yarn add @sentry/react-router @sentry/cloudflare
```

```bash {tabTitle:pnpm}
pnpm add @sentry/react-router @sentry/cloudflare
```

## Configure

**Error Monitoring** starts working as soon as you configure the SDK. **Logs** and **Application Metrics** need no extra configuration, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-).
This guide also enables **Tracing**, **Session Replay**, and **User Feedback**.

<Include name="quick-start-features-expandable-cloudflare-frameworks" />

<Include name="react-router/client-setup" />

### Configure Server-Side Sentry

Add `sentryCloudflareVitePlugin` to your `vite.config.ts`, after your other plugins:

```typescript {filename: vite.config.ts} {diff}
import { cloudflare } from "@cloudflare/vite-plugin";
import { reactRouter } from "@react-router/dev/vite";
+import { sentryCloudflareVitePlugin } from "@sentry/cloudflare/vite";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [
cloudflare({ viteEnvironment: { name: "ssr" } }),
reactRouter(),
+ sentryCloudflareVitePlugin(),
],
});
```

When Vite builds your app, the plugin wraps the default export of your Worker entry with Sentry. The Worker entry is the file in `main` of your Wrangler configuration, for example `workers/app.ts`, and you don't change it. The plugin also instruments supported packages, such as database clients.

Create an `instrument.server.ts` file next to your Worker entry, for example `workers/instrument.server.ts`. The plugin uses its default export as the Sentry options:

```typescript {filename: workers/instrument.server.ts}
import { defineCloudflareOptions } from "@sentry/cloudflare";

export default defineCloudflareOptions((env: Env) => ({
dsn: "___PUBLIC_DSN___",
// Enables Tracing.
// Set to 1.0 to capture 100% of spans for tracing.
// We recommend reducing this value in production.
tracesSampleRate: 1.0,
}));
```

<PlatformContent
includePath="getting-started-config"
platform="javascript.cloudflare"
/>

### Update Your Server Entry

Replace the content of your `entry.server.tsx` file. Import from `@sentry/react-router/cloudflare`: its `createSentryHandleRequest` renders with `renderToReadableStream`, which works on Workers.

`handleError` sends server errors to Sentry. `instrumentations` uses React Router's [instrumentation API](https://reactrouter.com/how-to/instrumentation) to create spans for all loaders, actions, middleware, and request handlers, and names each request after its route, for example `GET /users/:id`.

```tsx {filename: entry.server.tsx}
import * as Sentry from "@sentry/react-router/cloudflare";
import { renderToReadableStream } from "react-dom/server";
import { ServerRouter, type HandleErrorFunction } from "react-router";

export default Sentry.createSentryHandleRequest({
ServerRouter,
renderToReadableStream,
});

export const handleError: HandleErrorFunction = (error, { request }) => {
// React Router aborts some requests, for example when the user navigates away
if (!request.signal.aborted) {
Sentry.captureException(error);
}
};

export const instrumentations = [Sentry.createSentryServerInstrumentation()];
```

### Add Readable Stack Traces With Source Maps

The `sentryReactRouter` Vite plugin uploads your source maps, so stack traces in Sentry show your original code. Add it after `sentryCloudflareVitePlugin`, and pass both the Sentry options and the Vite configuration to it:

```typescript {filename: vite.config.ts} {diff}
import { cloudflare } from "@cloudflare/vite-plugin";
import { reactRouter } from "@react-router/dev/vite";
import { sentryCloudflareVitePlugin } from "@sentry/cloudflare/vite";
+import {
+ sentryReactRouter,
+ type SentryReactRouterBuildOptions,
+} from "@sentry/react-router/vite";
import { defineConfig } from "vite";

+const sentryConfig: SentryReactRouterBuildOptions = {
+ org: "___ORG_SLUG___",
+ project: "___PROJECT_SLUG___",
+
+ // An auth token is required for uploading source maps;
+ // store it in an environment variable to keep it secure.
+ authToken: process.env.SENTRY_AUTH_TOKEN,
+};

-export default defineConfig({
+export default defineConfig((config) => ({
plugins: [
cloudflare({ viteEnvironment: { name: "ssr" } }),
reactRouter(),
sentryCloudflareVitePlugin(),
+ sentryReactRouter(sentryConfig, config),
],
-});
+}));
```

<Include name="react-router/source-maps-upload" />

### Control the Data You Send to Sentry

<PlatformContent includePath="getting-started-data-collection" />

<Include name="react-router/logs-metrics-verify" />

## Next Steps

At this point, you should have integrated Sentry into your React Router Framework application on Cloudflare. Here's what to explore next:

- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup
- <PlatformLink to="/troubleshooting/#dealing-with-ad-blockers">Set up tunneling</PlatformLink> to avoid ad blockers blocking Sentry events
- Learn what the [Sentry Cloudflare Vite plugin](/platforms/javascript/guides/cloudflare/install/vite-plugin/) instruments and how to configure it

<Expandable permalink={false} title="Are you having problems setting up the SDK?">

- Find various topics in [Cloudflare troubleshooting](/platforms/javascript/guides/cloudflare/troubleshooting/) and <PlatformLink to="/troubleshooting/">React Router troubleshooting</PlatformLink>
- [Get support](https://www.sentry.help/en/)

</Expandable>

</StepConnector>
109 changes: 109 additions & 0 deletions docs/platforms/javascript/guides/react-router/deno.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
title: React Router Framework on Deno
sidebar_title: Quick Start (Deno)
sidebar_order: 0.6
description: Learn how to set up Sentry in your React Router app (v7.15+) that runs on Deno and capture your first errors and traces.
runtime: deno
---

This guide sets up Sentry in a React Router app in framework mode that you build with Vite and serve with `react-router-serve` on Deno. At the end, your app sends errors, traces, logs, and session replays to Sentry.

## Prerequisites

You need:

- A Sentry [account](https://sentry.io/signup/) and [project](/product/projects/)
- A React Router app in framework mode, version `7.15.0` or above, with its dependencies in a `node_modules` folder
- [Deno](https://deno.com/) version `2.9.0` or above

<StepConnector selector="h2" showNumbers={true}>

## Install

Add the Sentry React Router SDK for your app and the Sentry Deno SDK for your server:

```bash {tabTitle:npm}
npm install @sentry/react-router @sentry/deno --save
```

```bash {tabTitle:yarn}
yarn add @sentry/react-router @sentry/deno
```

```bash {tabTitle:pnpm}
pnpm add @sentry/react-router @sentry/deno
```

## 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](#send-logs) and [#4](#send-application-metrics-).
This guide also enables **Tracing**, **Session Replay**, and **User Feedback**.

<Include name="quick-start-features-expandable-cloudflare-frameworks" />

<Include name="react-router/client-setup" />

### Configure Server-Side Sentry

Create a file called `instrument.server.mjs` in the root of your project, and initialize Sentry with the Deno SDK. Don't use `Sentry.init()` from `@sentry/react-router` on the server: it's made for Node.js.

```javascript {filename: instrument.server.mjs}
import * as Sentry from "@sentry/deno";

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

<Include name="react-router/server-entry" />

To use a Content Security Policy nonce or your own `handleRequest` or `handleError` logic, see the <PlatformLink to="/manual-setup/#configure-server-side-sentry">manual setup</PlatformLink>.

<Include name="react-router/source-maps" />

### Start Your App

Run the `react-router-serve` script with Deno, and preload two files: the Sentry import hook (`npm:@sentry/deno/import`), which instruments the packages that Deno loads from `node_modules`, such as Express, and then `instrument.server.mjs`. Update the `start` script in your `package.json`:

```json {filename: package.json}
"scripts": {
"start": "deno run --preload=npm:@sentry/deno/import --preload=./instrument.server.mjs --allow-net --allow-env --allow-read=. --allow-sys=hostname,osRelease,networkInterfaces ./node_modules/@react-router/serve/bin.cjs ./build/server/index.js"
}
```

Deno blocks access to the network, the file system, and system information until you grant it:

| Flag | What it gives you |
| ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `--allow-net` | The server port, and the delivery of events to Sentry. |
| `--allow-env` | The import hook and `react-router-serve`, which read environment variables. |
| `--allow-read=.` | The import hook, your server build, and the packages in `node_modules`. |
| `--allow-sys=hostname,osRelease,networkInterfaces` | The server name and the operating system version on events. `react-router-serve` needs `networkInterfaces` to start. |

### Control the Data You Send to Sentry

<PlatformContent includePath="getting-started-data-collection" />

<Include name="react-router/logs-metrics-verify" />

## Next Steps

At this point, you should have integrated Sentry into your React Router Framework application on Deno. Here's what to explore next:

- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup
- <PlatformLink to="/troubleshooting/#dealing-with-ad-blockers">Set up tunneling</PlatformLink> to avoid ad blockers blocking Sentry events
- Learn more about the [Sentry Deno SDK](/platforms/javascript/guides/deno/)

<Expandable permalink={false} title="Are you having problems setting up the SDK?">

- If your app stops at start with `NotCapable`, Deno names the missing permission in the error. Add it to the `start` script.
- Find various topics in <PlatformLink to="/troubleshooting/">Troubleshooting</PlatformLink>
- [Get support](https://www.sentry.help/en/)

</Expandable>

</StepConnector>
1 change: 1 addition & 0 deletions docs/platforms/javascript/guides/react-router/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ sdk: sentry.javascript.react-router
categories:
- browser
- server
runtime: node
---

<AgentSetupCallout
Expand Down
Loading
Loading