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
18 changes: 12 additions & 6 deletions packages/react-router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { HydratedRouter } from 'react-router/dom';

Sentry.init({
dsn: '___PUBLIC_DSN___',
integrations: [Sentry.browserTracingIntegration()],
integrations: [Sentry.reactRouterTracingIntegration()],

tracesSampleRate: 1.0, // Capture 100% of the transactions

Expand All @@ -57,7 +57,7 @@ startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<HydratedRouter />
<HydratedRouter instrumentations={[Sentry.createSentryClientInstrumentation()]} onError={Sentry.sentryOnError} />
</StrictMode>,
);
});
Expand Down Expand Up @@ -113,9 +113,11 @@ Sentry.init({
});
```

In your `entry.server.tsx` file, export the `handleError` function:
In your `entry.server.tsx` file, import the instrumentation file at the very top, export the
`instrumentations` array, and export the `handleError` function:

```tsx
import './instrument.server.mjs';
import * as Sentry from '@sentry/react-router';
import { type HandleErrorFunction } from 'react-router';

Expand All @@ -128,13 +130,17 @@ export const handleError: HandleErrorFunction = (error, { request }) => {
console.error(error);
}
};

// Register the Sentry server instrumentation so loaders, actions and middleware are traced.
export const instrumentations = [Sentry.createSentryServerInstrumentation()];
// ... rest of your server entry
```

### Update Scripts
### Loading the Instrumentation via `--import` (Alternative)

Since React Router is running in ESM mode, you need to use the `--import` command line options to load our server-side instrumentation module before the application starts.
Update the `start` and `dev` script to include the instrumentation file:
Instead of importing the instrumentation file at the top of `entry.server.tsx`, you can load it before
the application starts via the `--import` command line option. Since React Router runs in ESM mode,
update the `start` and `dev` scripts accordingly:

```json
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions packages/react-router/src/client/tracingIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export interface ReactRouterTracingIntegrationOptions {
export interface ReactRouterTracingIntegration extends Integration {
/**
* Client instrumentation to pass to `HydratedRouter`'s `instrumentations` prop.
*
* @deprecated Use the standalone `createSentryClientInstrumentation()` export instead and pass its
* result to `HydratedRouter`'s `instrumentations` prop. This mirrors the server-side
* `createSentryServerInstrumentation()` API. Will be removed in a future major.
*/
readonly clientInstrumentation: ClientInstrumentation;
}
Expand Down
Loading