Official Sentry SDK for Remix
General
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.
import { useLocation, useMatches } from '@remix-run/react';
import * as Sentry from '@sentry/remix';
import { useEffect } from 'react';
Sentry.init({
dsn: '__DSN__',
tracesSampleRate: 1,
integrations: [
Sentry.browserTracingIntegration({
useEffect,
useLocation,
useMatches,
}),
],
});
import { prisma } from '~/db.server';
import * as Sentry from '@sentry/remix';
Sentry.init({
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.
import {
Links,
LiveReload,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from "@remix-run/react";
import { withSentry } from "@sentry/remix";
function App() {
return (
<html>
<head>
<Meta />
<Links />
</head>
<body>
<Outlet />
<ScrollRestoration />
<Scripts />
<LiveReload />
</body>
</html>
);
}
export default withSentry(App);
You can disable or configure ErrorBoundary
using a second parameter to withSentry
.
withSentry(App, {
wrapWithErrorBoundary: false
});
withSentry(App, {
errorBoundaryOptions: {
fallback: <p>An error has occurred</p>
}
});
To set context information or send manual events, use the exported functions of @sentry/remix
.
import * as Sentry from '@sentry/remix';
Sentry.setExtra('battery', 0.7);
Sentry.setTag('user_mode', 'admin');
Sentry.setUser({ id: '4711' });
Sentry.addBreadcrumb({
message: 'My Breadcrumb',
});
Sentry.captureMessage('Hello, world!');
Sentry.captureException(new Error('Good bye'));
Sentry.captureEvent({
message: 'Manual',
stacktrace: [
],
});
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.
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..
8.23.0
Important Changes
- feat(cloudflare): Add Cloudflare D1 instrumentation (#13142)
This release includes support for Cloudflare D1, Cloudflare's serverless SQL database. To instrument your Cloudflare D1
database, use the instrumentD1WithSentry
method as follows:
// env.DB is the D1 DB binding configured in your `wrangler.toml`
const db = instrumentD1WithSentry(env.DB);
// Now you can use the database as usual
await db.prepare('SELECT * FROM table WHERE id = ?').bind(1).run();
Other Changes
- feat(cloudflare): Allow users to pass handler to sentryPagesPlugin (#13192)
- feat(cloudflare): Instrument scheduled handler (#13114)
- feat(core): Add
getTraceData
function (#13134) - feat(nestjs): Automatic instrumentation of nestjs interceptors before route execution (#13153)
- feat(nestjs): Automatic instrumentation of nestjs pipes (#13137)
- feat(nuxt): Filter out Nuxt build assets (#13148)
- feat(profiling): Attach sdk info to chunks (#13145)
- feat(solidstart): Add sentry
onBeforeResponse
middleware to enable distributed tracing (#13221) - feat(solidstart): Filter out low quality transactions for build assets (#13222)
- fix(browser): Avoid showing browser extension error message in non-
window
global scopes (#13156) - fix(feedback): Call dialog.close() in dialog close callbacks in
\_loadAndRenderDialog
(#13203) - fix(nestjs): Inline Observable type to resolve missing 'rxjs' dependency (#13166)
- fix(nuxt): Detect pageload by adding flag in Vue router (#13171)
- fix(utils): Handle when requests get aborted in fetch instrumentation (#13202)
- ref(browser): Improve browserMetrics collection (#13062)
Work in this release was contributed by @horochx. Thank you for your contribution!