-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add Remix SDK docs #5247
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
Merged
Merged
Add Remix SDK docs #5247
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c943383
Add Remix SDK docs
onurtemizkan 23cae26
Update `sentry-upload-sourcemaps` doca.
onurtemizkan 1fe9edc
Add notes about DSN and Prisma.
onurtemizkan 5dc791e
Apply suggestions from code review
onurtemizkan a6fea8e
Use Remix links for `Events` / `Breadcrumbs`
onurtemizkan ec4ce46
Update `withSentry` docs.
onurtemizkan a74a3a1
Update src/includes/getting-started-primer/javascript.remix.mdx
AbhiPrasad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
You can pass an `Error` object to `captureException()` to get it captured as event. It's also possible to pass non-`Error` objects and strings, but be aware that the resulting events in Sentry may be missing a stacktrace. | ||
|
||
```typescript | ||
import * as Sentry from "@sentry/remix"; | ||
|
||
try { | ||
aFunctionThatMightFail(); | ||
} catch (err) { | ||
Sentry.captureException(err); | ||
} | ||
``` |
120 changes: 120 additions & 0 deletions
120
src/includes/getting-started-config/javascript.remix.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
To use this SDK, initialize Sentry in your Remix entry points for both the client and server. | ||
|
||
```typescript {filename: entry.client.tsx} | ||
import { useLocation, useMatches } from "@remix-run/react"; | ||
import * as Sentry from "@sentry/remix"; | ||
import { useEffect } from "react"; | ||
|
||
Sentry.init({ | ||
dsn: "__DSN__", | ||
tracesSampleRate: 1, | ||
integrations: [ | ||
new Sentry.BrowserTracing({ | ||
routingInstrumentation: Sentry.remixRouterInstrumentation( | ||
vladanpaunovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
useEffect, | ||
useLocation, | ||
useMatches, | ||
), | ||
}), | ||
], | ||
// ... | ||
}); | ||
``` | ||
|
||
Initialize Sentry in your entry point for the server, to capture exceptions and get performance metrics for your [`action`](https://remix.run/docs/en/v1/api/conventions#action) and [`loader`](https://remix.run/docs/en/v1/api/conventions#loader) functions. You can also initialize Sentry's database integrations such as Prisma to get spans for your database calls. | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```typescript {filename: entry.server.tsx} | ||
import { prisma } from "~/db.server"; | ||
|
||
import * as Sentry from "@sentry/remix"; | ||
|
||
Sentry.init({ | ||
dsn: "__DSN__", | ||
tracesSampleRate: 1, | ||
integrations: [new Sentry.Integrations.Prisma({ client: prisma })], | ||
// ... | ||
}); | ||
``` | ||
|
||
vladanpaunovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Also, wrap your Remix root, with Sentry's `ErrorBoundary` component to catch React component errors, and `withSentryRouteTracing` to get parameterized router transactions. | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```typescript {filename: root.tsx} | ||
import { | ||
Links, | ||
LiveReload, | ||
Meta, | ||
Outlet, | ||
Scripts, | ||
ScrollRestoration, | ||
} from "@remix-run/react"; | ||
|
||
import { ErrorBoundary, withSentryRouteTracing } from "@sentry/remix"; | ||
vladanpaunovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function App() { | ||
return ( | ||
<ErrorBoundary> | ||
<html> | ||
<head> | ||
<Meta /> | ||
<Links /> | ||
</head> | ||
<body> | ||
<Outlet /> | ||
<ScrollRestoration /> | ||
<Scripts /> | ||
<LiveReload /> | ||
</body> | ||
</html> | ||
</ErrorBoundary> | ||
); | ||
} | ||
|
||
export default withSentryRouteTracing(App); | ||
``` | ||
|
||
Once you're set up, the SDK will automatically capture unhandled errors and promise rejections, and monitor performance in the client. You can also [manually capture errors](/platforms/javascript/guides/remix/usage). | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Using Sentry DSN from environment variables | ||
vladanpaunovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
To use Sentry DSN from environment variables on Remix client, you need to add it as a global in your `root` loader. | ||
|
||
```typescript {filename: root.tsx} | ||
// ... | ||
|
||
type LoaderData = { | ||
GLOBALS: string; | ||
}; | ||
|
||
export const loader: LoaderFunction = async ({ request }) => { | ||
return json<LoaderData>({ | ||
GLOBALS: JSON.stringify({ | ||
SENTRY_DSN: process.env.SENTRY_DSN, | ||
}), | ||
}); | ||
}; | ||
|
||
function App() { | ||
const { GLOBALS } = useLoaderData() as LoaderData; | ||
|
||
return ( | ||
// ... | ||
); | ||
} | ||
``` | ||
|
||
Then, use it as a global in your `entry.client.tsx` file. | ||
|
||
```typescript {filename: entry.client.tsx} | ||
// ... | ||
|
||
Sentry.init({ | ||
dsn: window.GLOBALS.SENTRY_DSN, | ||
// ... | ||
}); | ||
|
||
declare global { | ||
interface Window { | ||
GLOBALS: Record<string, string | undefined>; | ||
} | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```bash {tabTitle:npm} | ||
npm install --save @sentry/remix | ||
``` | ||
|
||
```bash {tabTitle:yarn} | ||
yarn add @sentry/remix | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Note> | ||
|
||
Sentry's Remix SDK enables automatic reporting of errors and exceptions, as well as the performance metrics for both client and server side operations. | ||
|
||
</Note> | ||
|
||
<Alert level="info" title="Important"> | ||
|
||
This SDK is still in experimental phase and is not yet ready for production use. | ||
|
||
</Alert> | ||
|
||
Sentry's Remix SDK is introduced in version `7.4.0`. | ||
AbhiPrasad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Features: | ||
|
||
- [Error Tracking](/product/issues/) with source maps for both JavaScript and TypeScript | ||
- Events [enriched](/platforms/javascript/enriching-events/context/) with device data | ||
- [Breadcrumbs](/platforms/javascript/enriching-events/breadcrumbs/) created for outgoing HTTP request with XHR and Fetch, and console logs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these not link to the Remix version of these pages? |
||
- [Release health](/product/releases/health/) for tracking crash-free users and sessions | ||
- [Performance Monitoring](/product/performance/) for both the client and server. | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Under the hood, Remix SDK relies on our [React SDK](/platforms/javascript/guides/react/) on the frontend and [Node SDK](/platforms/node) on the backend, which makes all features available in those SDKs also available in this SDK. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Add a button to a frontend component that throws an error: | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```typescript {filename:routes/error.tsx} | ||
<button | ||
type="button" | ||
onClick={() => { | ||
throw new Error("Sentry Frontend Error"); | ||
}} | ||
> | ||
Throw error | ||
</button> | ||
``` | ||
|
||
<Note> | ||
|
||
Errors triggered from within Browser DevTools are sandboxed, so will not trigger an error handler. Place the snippet directly in your code instead. | ||
|
||
</Note> | ||
|
||
And throw an error in a `loader` or `action`: | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```typescript {filename:routes/error.tsx} | ||
export const action: ActionFunction = async ({ request }) => { | ||
throw new Error("Sentry Error"); | ||
}; | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
To generate source maps with your Remix project, you need to call `remix build` with the `--sourcemap` option. | ||
|
||
Please refer to the [Remix CLI docs](https://remix.run/docs/en/v1/other-api/dev#remix-cli) for more information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Integrate your Remix project's source maps with Sentry using these steps: | ||
|
||
### 1: Generate Source Maps | ||
|
||
Remix can be configured to output source maps by Remix CLI. Learn more about how to generate sourcemaps with Remix [here](./generating/). | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### 2: Provide Source Maps to Sentry | ||
|
||
Source maps can be uploaded to Sentry by creating a release. Learn more about how to upload source maps [here](./uploading/). | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<Note> | ||
|
||
By default, if Sentry can't find the uploaded files it needs, it will attempt to download them from the URLs in the stacktrace. To disable this, turn off "Enable JavaScript source fetching" in either your organization's "Security & Privacy" settings or your project's general settings. | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
</Note> |
11 changes: 11 additions & 0 deletions
11
src/includes/sourcemaps/upload/primer/javascript.remix.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
On release, call `sentry-upload-sourcemaps` to upload source maps and create a release. | ||
vladanpaunovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<Alert level="warning"> | ||
|
||
`sentry-upload-sourcemaps` requires a valid `.sentryclirc` file to pick up your project ID, organization ID and token. You can create `.sentryclirc` file with necessary configuration, as documented on this [page](https://docs.sentry.io/product/cli/configuration/). | ||
|
||
</Alert> | ||
|
||
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). | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
title: Remix | ||
sdk: sentry.javascript.remix | ||
fallbackPlatform: javascript | ||
caseStyle: camelCase | ||
supportLevel: production | ||
categories: | ||
- browser | ||
- server |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.