|
6 | 6 |
|
7 | 7 | # Official Sentry SDK for Remix
|
8 | 8 |
|
9 |
| -This SDK is work in progress, and should not be used before officially released. |
| 9 | +[](https://www.npmjs.com/package/@sentry/remix) |
| 10 | +[](https://www.npmjs.com/package/@sentry/remix) |
| 11 | +[](https://www.npmjs.com/package/@sentry/remix) |
| 12 | +[](http://getsentry.github.io/sentry-javascript/) |
| 13 | + |
| 14 | +This SDK is considering experimental and in an alpha state. It may experience breaking changes. Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if you have any feedback/concerns. |
| 15 | +## General |
| 16 | + |
| 17 | +This package is a wrapper around `@sentry/node` for the server and `@sentry/react` for the client, with added functionality related to Remix. |
| 18 | + |
| 19 | +To use this SDK, initialize Sentry in your Remix entry points for both the client and server. |
| 20 | + |
| 21 | +```ts |
| 22 | +// entry.client.tsx |
| 23 | + |
| 24 | +import { useLocation, useMatches } from "@remix-run/react"; |
| 25 | +import * as Sentry from "@sentry/remix"; |
| 26 | +import { useEffect } from "react"; |
| 27 | + |
| 28 | +Sentry.init({ |
| 29 | + dsn: "__DSN__", |
| 30 | + tracesSampleRate: 1, |
| 31 | + integrations: [ |
| 32 | + new Sentry.BrowserTracing({ |
| 33 | + routingInstrumentation: Sentry.remixRouterInstrumentation( |
| 34 | + useEffect, |
| 35 | + useLocation, |
| 36 | + useMatches, |
| 37 | + ), |
| 38 | + }), |
| 39 | + ], |
| 40 | + // ... |
| 41 | +}); |
| 42 | +``` |
| 43 | + |
| 44 | +```ts |
| 45 | +// entry.server.tsx |
| 46 | + |
| 47 | +import { prisma } from "~/db.server"; |
| 48 | + |
| 49 | +import * as Sentry from "@sentry/remix"; |
| 50 | + |
| 51 | +Sentry.init({ |
| 52 | + dsn: "__DSN__", |
| 53 | + tracesSampleRate: 1, |
| 54 | + integrations: [new Sentry.Integrations.Prisma({ client: prisma })], |
| 55 | + // ... |
| 56 | +}); |
| 57 | +``` |
| 58 | + |
| 59 | +Also, wrap your Remix root, with Sentry's `ErrorBoundary` component to catch React component errors, and `withSentryRouteTracing` to get parameterized router transactions. |
| 60 | + |
| 61 | +```ts |
| 62 | +// root.tsx |
| 63 | + |
| 64 | +import { |
| 65 | + Links, |
| 66 | + LiveReload, |
| 67 | + Meta, |
| 68 | + Outlet, |
| 69 | + Scripts |
| 70 | + ScrollRestoration, |
| 71 | +} from "@remix-run/react"; |
| 72 | + |
| 73 | +import { ErrorBoundary, withSentryRouteTracing } from "@sentry/remix"; |
| 74 | + |
| 75 | +function App() { |
| 76 | + return ( |
| 77 | + <ErrorBoundary> |
| 78 | + <html> |
| 79 | + <head> |
| 80 | + <Meta /> |
| 81 | + <Links /> |
| 82 | + </head> |
| 83 | + <body> |
| 84 | + <Outlet /> |
| 85 | + <ScrollRestoration /> |
| 86 | + <Scripts /> |
| 87 | + <LiveReload /> |
| 88 | + </body> |
| 89 | + </html> |
| 90 | + </ErrorBoundary> |
| 91 | + ); |
| 92 | +} |
| 93 | + |
| 94 | +export default withSentryRouteTracing(App); |
| 95 | +``` |
| 96 | + |
| 97 | +To set context information or send manual events, use the exported functions of `@sentry/remix`. |
| 98 | + |
| 99 | +```ts |
| 100 | +import * as Sentry from '@sentry/remix'; |
| 101 | + |
| 102 | +// Set user information, as well as tags and further extras |
| 103 | +Sentry.configureScope(scope => { |
| 104 | + scope.setExtra('battery', 0.7); |
| 105 | + scope.setTag('user_mode', 'admin'); |
| 106 | + scope.setUser({ id: '4711' }); |
| 107 | + // scope.clear(); |
| 108 | +}); |
| 109 | + |
| 110 | +// Add a breadcrumb for future events |
| 111 | +Sentry.addBreadcrumb({ |
| 112 | + message: 'My Breadcrumb', |
| 113 | + // ... |
| 114 | +}); |
| 115 | + |
| 116 | +// Capture exceptions, messages or manual events |
| 117 | +Sentry.captureMessage('Hello, world!'); |
| 118 | +Sentry.captureException(new Error('Good bye')); |
| 119 | +Sentry.captureEvent({ |
| 120 | + message: 'Manual', |
| 121 | + stacktrace: [ |
| 122 | + // ... |
| 123 | + ], |
| 124 | +}); |
| 125 | +``` |
| 126 | + |
| 127 | +## Sourcemaps and Releases |
| 128 | + |
| 129 | +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 `--sourcemap` option. |
| 130 | + |
| 131 | +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`. |
| 132 | + |
| 133 | +For more advanced configuration, [directly use `sentry-cli` to upload source maps.](https://github.com/getsentry/sentry-cli). |
0 commit comments