Remix
Sentry's Remix SDK enables automatic reporting of errors and exceptions, as well as the performance metrics for both client and server side operations.
Features Overview
- Error Tracking with source maps for both JavaScript and TypeScript
- Events enriched with device data
- Breadcrumbs created for outgoing HTTP request with XHR and Fetch, and console logs
- Release health for tracking crash-free users and sessions
- Performance Monitoring for both the client and server
Under the hood, Remix SDK relies on our React SDK on the frontend and Node SDK on the backend, which makes all features available in those SDKs also available in this SDK.
On this page, we get you up and running with Sentry's SDK, so that it will automatically report errors and exceptions in your application.
Don't already have an account and Sentry project established? Head over to sentry.io, then return to this page.
Install
Sentry captures data by using an SDK within your application’s runtime.
npm install --save @sentry/remix
Configure
Configuration should happen as early as possible in your application's lifecycle.
To use this SDK, initialize Sentry in your Remix entry points for both the client and server.
entry.client.tsx
import { useLocation, useMatches } from "@remix-run/react";
import * as Sentry from "@sentry/remix";
import { useEffect } from "react";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
tracesSampleRate: 1,
integrations: [
new Sentry.BrowserTracing({
routingInstrumentation: Sentry.remixRouterInstrumentation(
useEffect,
useLocation,
useMatches,
),
}),
],
// ...
});
Initialize Sentry in your entry point for the server to capture exceptions and get performance metrics for your action
and loader
functions. You can also initialize Sentry's database integrations, such as Prisma, to get spans for your database calls.
entry.server.tsx
import { prisma } from "~/db.server";
import * as Sentry from "@sentry/remix";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
tracesSampleRate: 1,
integrations: [new Sentry.Integrations.Prisma({ client: prisma })],
// ...
});
Learn more about Sentry's Prisma integration .
If you use a custom Express server in your Remix application, you should wrap your createRequestHandler
function manually with wrapExpressCreateRequestHandler
. This is not required if you use the built-in Remix App Server.
wrapExpressCreateRequestHandler
is available starting with version 7.11.0.
server/index.ts
import { wrapExpressCreateRequestHandler } from "@sentry/remix";
import { createRequestHandler } from '@remix-run/express';
// ...
const createSentryRequestHandler = wrapExpressCreateRequestHandler(createRequestHandler);
// Use createSentryRequestHandler like you would with createRequestHandler
app.all('*', createSentryRequestHandler(/* ... */));
Also, wrap your Remix root with withSentry
to catch React component errors and to get parameterized router transactions.
root.tsx
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
});
// or
withSentry(App, {
errorBoundaryOptions: {
fallback: <p>An error has occurred</p>
}
});
Once you've done this set up, the SDK will automatically capture unhandled errors and promise rejections, and monitor performance in the client. You can also manually capture errors.
You can refer to Remix Docs to learn how to use your Sentry DSN from environment variables.
Verify
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:
routes/error.tsx
<button
type="button"
onClick={() => {
throw new Error("Sentry Frontend Error");
}}
>
Throw error
</button>
This snippet adds a button that throws an error in a component or page.
Errors triggered from within Browser DevTools are sandboxed, so will not trigger an error handler. Place the snippet directly in your code instead.
Then, throw an error in a loader
or action
.
routes/error.tsx
export const action: ActionFunction = async ({ request }) => {
throw new Error("Sentry Error");
};
Learn more about manually capturing an error or message in our Usage documentation.
To view and resolve the recorded error, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.
Add Readable Stack Traces to Errors
Depending on how you've set up your JavaScript project, the stack traces in your Sentry errors probably don't look like your actual code.
To fix this, head over to our source maps documentation where you'll learn how to upload source maps, so you can make sense of your stack traces.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").
- Package:
- npm:@sentry/remix
- Version:
- 7.44.1
- Repository:
- https://github.com/getsentry/sentry-javascript