Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(remix): Add custom browserTracingIntegration #10442

Merged
merged 8 commits into from
Feb 5, 2024
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
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ jobs:
yarn test

job_remix_integration_tests:
name: Remix v${{ matrix.remix }} (Node ${{ matrix.node }}) Tests
name: Remix v${{ matrix.remix }} (Node ${{ matrix.node }}) ${{ matrix.tracingIntegration && 'TracingIntegration'}} Tests
needs: [job_get_metadata, job_build]
if: needs.job_get_metadata.outputs.changed_remix == 'true' || github.event_name != 'pull_request'
runs-on: ubuntu-20.04
Expand All @@ -912,6 +912,8 @@ jobs:
remix: 1
- node: 16
remix: 1
- tracingIntegration: true
remix: 2
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v4
Expand All @@ -929,6 +931,7 @@ jobs:
env:
NODE_VERSION: ${{ matrix.node }}
REMIX_VERSION: ${{ matrix.remix }}
TRACING_INTEGRATION: ${{ matrix.tracingIntegration }}
run: |
cd packages/remix
yarn test:integration:ci
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ module.exports = {
// serverBuildPath: 'build/index.js',
// publicPath: '/build/',
serverModuleFormat: 'cjs',
entry,
};
39 changes: 21 additions & 18 deletions packages/remix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,26 @@

## General

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

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

```ts
// entry.client.tsx

import { useLocation, useMatches } from "@remix-run/react";
import * as Sentry from "@sentry/remix";
import { useEffect } from "react";
import { useLocation, useMatches } from '@remix-run/react';
import * as Sentry from '@sentry/remix';
import { useEffect } from 'react';

Sentry.init({
dsn: "__DSN__",
dsn: '__DSN__',
tracesSampleRate: 1,
integrations: [
new Sentry.BrowserTracing({
routingInstrumentation: Sentry.remixRouterInstrumentation(
useEffect,
useLocation,
useMatches,
),
Sentry.browserTracingIntegration({
useEffect,
useLocation,
useMatches,
}),
],
// ...
Expand All @@ -42,19 +41,20 @@ Sentry.init({
```ts
// entry.server.tsx

import { prisma } from "~/db.server";
import { prisma } from '~/db.server';

import * as Sentry from "@sentry/remix";
import * as Sentry from '@sentry/remix';

Sentry.init({
dsn: "__DSN__",
dsn: '__DSN__',
tracesSampleRate: 1,
integrations: [new Sentry.Integrations.Prisma({ client: prisma })],
// ...
});
```

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

```ts
// root.tsx
Expand Down Expand Up @@ -139,8 +139,11 @@ Sentry.captureEvent({

## Sourcemaps and Releases

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

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

For more advanced configuration, [directly use `sentry-cli` to upload source maps.](https://github.com/getsentry/sentry-cli).
For more advanced configuration,
[directly use `sentry-cli` to upload source maps.](https://github.com/getsentry/sentry-cli).
5 changes: 3 additions & 2 deletions packages/remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@
"fix": "eslint . --format stylish --fix",
"lint": "eslint . --format stylish",
"test": "yarn test:unit",
"test:integration": "run-s test:integration:v1 test:integration:v2",
"test:integration": "run-s test:integration:v1 test:integration:v2 test:integration:tracingIntegration",
"test:integration:v1": "run-s test:integration:clean test:integration:prepare test:integration:client test:integration:server",
"test:integration:v2": "export REMIX_VERSION=2 && run-s test:integration:v1",
"test:integration:tracingIntegration": "export TRACING_INTEGRATION=true && run-s test:integration:v2",
"test:integration:ci": "run-s test:integration:clean test:integration:prepare test:integration:client:ci test:integration:server",
"test:integration:prepare": "(cd test/integration && yarn)",
"test:integration:prepare": "(cd test/integration && yarn install)",
"test:integration:clean": "(cd test/integration && rimraf .cache node_modules build)",
"test:integration:client": "yarn playwright install-deps && yarn playwright test test/integration/test/client/ --project='chromium'",
"test:integration:client:ci": "yarn test:integration:client --reporter='line'",
Expand Down
41 changes: 41 additions & 0 deletions packages/remix/src/client/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { browserTracingIntegration as originalBrowserTracingIntegration } from '@sentry/react';
import type { Integration } from '@sentry/types';
import { setGlobals, startPageloadSpan } from './performance';
import type { RemixBrowserTracingIntegrationOptions } from './performance';
/**
* Creates a browser tracing integration for Remix applications.
* This integration will create pageload and navigation spans.
*/
export function browserTracingIntegration(options: RemixBrowserTracingIntegrationOptions): Integration {
if (options.instrumentPageLoad === undefined) {
options.instrumentPageLoad = true;
}

if (options.instrumentNavigation === undefined) {
options.instrumentNavigation = true;
}

setGlobals({
useEffect: options.useEffect,
useLocation: options.useLocation,
useMatches: options.useMatches,
instrumentNavigation: options.instrumentNavigation,
});

const browserTracingIntegrationInstance = originalBrowserTracingIntegration({
...options,
instrumentPageLoad: false,
instrumentNavigation: false,
});

return {
...browserTracingIntegrationInstance,
afterAllSetup(client) {
browserTracingIntegrationInstance.afterAllSetup(client);

if (options.instrumentPageLoad) {
startPageloadSpan();
}
},
};
}
Loading
Loading