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.10.0
Important Changes
- feat(remix): Migrate to
opentelemetry-instrumentation-remix
. (#12110)
You can now simplify your remix instrumentation by opting-in like this:
const Sentry = require('@sentry/remix');
Sentry.init({
dsn: YOUR_DSN
// opt-in to new auto instrumentation
autoInstrumentRemix: true,
});
With this setup, you do not need to add e.g. wrapExpressCreateRequestHandler
anymore. Additionally, the quality of the
captured data improves. The old way to use @sentry/remix
continues to work, but it is encouraged to use the new setup.
Other Changes
- feat(browser): Export
thirdPartyErrorFilterIntegration
from @sentry/browser
(#12512) - feat(feedback): Allow passing
tags
field to any feedback config param (#12197) - feat(feedback): Improve screenshot quality for retina displays (#12487)
- feat(feedback): Screenshots don't resize after cropping (#12481)
- feat(node) add max lineno and colno limits (#12514)
- feat(profiling) add global profile context while profiler is running (#12394)
- feat(react): Add React version to events (#12390)
- feat(replay): Add url to replay hydration error breadcrumb type (#12521)
- fix(core): Ensure standalone spans respect sampled flag (#12533)
- fix(core): Use maxValueLength in extra error data integration (#12174)
- fix(feedback): Fix scrolling after feedback submission (#12499)
- fix(feedback): Send feedback rejects invalid responses (#12518)
- fix(nextjs): Update @rollup/plugin-commonjs (#12527)
- fix(node): Ensure status is correct for http server span errors (#12477)
- fix(node): Unify
getDynamicSamplingContextFromSpan
(#12522) - fix(profiling): continuous profile chunks should be in seconds (#12532)
- fix(remix): Add nativeFetch support for accessing request headers (#12479)
- fix(remix): Export no-op as
captureRemixServerException
from client SDK (#12497) - ref(node) refactor contextlines to use readline (#12221)
Work in this release was contributed by @AndreyKovanov and @kiliman. Thank you for your contributions!