Skip to content

Commit 69ea641

Browse files
committed
feat(remix): Add remixBrowserTracingIntegration
1 parent 9fcbb84 commit 69ea641

25 files changed

+379
-80
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ jobs:
859859
matrix:
860860
node: [18, 20, 21]
861861
remix: [1, 2]
862+
tracingIntegration: [false, true]
862863
# Remix v2 only supports Node 18+, so run Node 14, 16 tests separately
863864
include:
864865
- node: 14
@@ -882,6 +883,7 @@ jobs:
882883
env:
883884
NODE_VERSION: ${{ matrix.node }}
884885
REMIX_VERSION: ${{ matrix.remix }}
886+
TRACING_INTEGRATION: ${{ matrix.tracingIntegration }}
885887
run: |
886888
cd packages/remix
887889
yarn test:integration:ci

dev-packages/e2e-tests/test-applications/create-remix-app-v2/remix.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ module.exports = {
66
// serverBuildPath: 'build/index.js',
77
// publicPath: '/build/',
88
serverModuleFormat: 'cjs',
9+
entry,
910
};

packages/remix/README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,26 @@
1212

1313
## General
1414

15-
This package is a wrapper around `@sentry/node` for the server and `@sentry/react` for the client, with added functionality related to Remix.
15+
This package is a wrapper around `@sentry/node` for the server and `@sentry/react` for the client, with added
16+
functionality related to Remix.
1617

1718
To use this SDK, initialize Sentry in your Remix entry points for both the client and server.
1819

1920
```ts
2021
// entry.client.tsx
2122

22-
import { useLocation, useMatches } from "@remix-run/react";
23-
import * as Sentry from "@sentry/remix";
24-
import { useEffect } from "react";
23+
import { useLocation, useMatches } from '@remix-run/react';
24+
import * as Sentry from '@sentry/remix';
25+
import { useEffect } from 'react';
2526

2627
Sentry.init({
27-
dsn: "__DSN__",
28+
dsn: '__DSN__',
2829
tracesSampleRate: 1,
2930
integrations: [
30-
new Sentry.BrowserTracing({
31-
routingInstrumentation: Sentry.remixRouterInstrumentation(
32-
useEffect,
33-
useLocation,
34-
useMatches,
35-
),
31+
Sentry.remixBrowserTracingIntegration({
32+
useEffect,
33+
useLocation,
34+
useMatches,
3635
}),
3736
],
3837
// ...
@@ -42,19 +41,20 @@ Sentry.init({
4241
```ts
4342
// entry.server.tsx
4443

45-
import { prisma } from "~/db.server";
44+
import { prisma } from '~/db.server';
4645

47-
import * as Sentry from "@sentry/remix";
46+
import * as Sentry from '@sentry/remix';
4847

4948
Sentry.init({
50-
dsn: "__DSN__",
49+
dsn: '__DSN__',
5150
tracesSampleRate: 1,
5251
integrations: [new Sentry.Integrations.Prisma({ client: prisma })],
5352
// ...
5453
});
5554
```
5655

57-
Also, wrap your Remix root with `withSentry` to catch React component errors and to get parameterized router transactions.
56+
Also, wrap your Remix root with `withSentry` to catch React component errors and to get parameterized router
57+
transactions.
5858

5959
```ts
6060
// root.tsx
@@ -139,8 +139,11 @@ Sentry.captureEvent({
139139

140140
## Sourcemaps and Releases
141141

142-
The Remix SDK provides a script that automatically creates a release and uploads sourcemaps. To generate sourcemaps with Remix, you need to call `remix build` with the `--sourcemap` option.
142+
The Remix SDK provides a script that automatically creates a release and uploads sourcemaps. To generate sourcemaps with
143+
Remix, you need to call `remix build` with the `--sourcemap` option.
143144

144-
On release, call `sentry-upload-sourcemaps` to upload source maps and create a release. To see more details on how to use the command, call `sentry-upload-sourcemaps --help`.
145+
On release, call `sentry-upload-sourcemaps` to upload source maps and create a release. To see more details on how to
146+
use the command, call `sentry-upload-sourcemaps --help`.
145147

146-
For more advanced configuration, [directly use `sentry-cli` to upload source maps.](https://github.com/getsentry/sentry-cli).
148+
For more advanced configuration,
149+
[directly use `sentry-cli` to upload source maps.](https://github.com/getsentry/sentry-cli).

packages/remix/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@
7070
"fix": "eslint . --format stylish --fix",
7171
"lint": "eslint . --format stylish",
7272
"test": "yarn test:unit",
73-
"test:integration": "run-s test:integration:v1 test:integration:v2",
73+
"test:integration": "run-s test:integration:v1 test:integration:v2 test:integration:tracingIntegration",
7474
"test:integration:v1": "run-s test:integration:clean test:integration:prepare test:integration:client test:integration:server",
7575
"test:integration:v2": "export REMIX_VERSION=2 && run-s test:integration:v1",
76+
"test:integration:tracingIntegration": "export TRACING_INTEGRATION=true && run-s test:integration:v2",
7677
"test:integration:ci": "run-s test:integration:clean test:integration:prepare test:integration:client:ci test:integration:server",
77-
"test:integration:prepare": "(cd test/integration && yarn)",
78+
"test:integration:prepare": "(cd test/integration && yarn install --force)",
7879
"test:integration:clean": "(cd test/integration && rimraf .cache node_modules build)",
7980
"test:integration:client": "yarn playwright install-deps && yarn playwright test test/integration/test/client/ --project='chromium'",
8081
"test:integration:client:ci": "yarn test:integration:client --reporter='line'",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { browserTracingIntegration as originalBrowserTracingIntegration } from '@sentry/react';
2+
import type { Integration } from '@sentry/types';
3+
import { setGlobals, startPageloadSpan } from './performance';
4+
import type { RemixBrowserTracingIntegrationOptions } from './performance';
5+
/**
6+
* Creates a browser tracing integration for Remix applications.
7+
* This integration will create pageload and navigation spans.
8+
*/
9+
export function remixBrowserTracingIntegration(options: RemixBrowserTracingIntegrationOptions): Integration {
10+
if (options.startTransactionOnPageLoad === undefined) {
11+
options.startTransactionOnPageLoad = true;
12+
}
13+
14+
if (options.startTransactionOnLocationChange === undefined) {
15+
options.startTransactionOnLocationChange = true;
16+
}
17+
18+
setGlobals({
19+
useEffect: options.useEffect,
20+
useLocation: options.useLocation,
21+
useMatches: options.useMatches,
22+
startTransactionOnLocationChange: options.startTransactionOnLocationChange,
23+
});
24+
25+
const browserTracingIntegrationInstance = originalBrowserTracingIntegration({
26+
...options,
27+
instrumentPageLoad: false,
28+
instrumentNavigation: false,
29+
});
30+
31+
return {
32+
...browserTracingIntegrationInstance,
33+
afterAllSetup(client) {
34+
browserTracingIntegrationInstance.afterAllSetup?.(client);
35+
36+
if (options.startTransactionOnPageLoad) {
37+
startPageloadSpan();
38+
}
39+
},
40+
};
41+
}

0 commit comments

Comments
 (0)