-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add React Router v6 instrumentation docs. #5037
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
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cbb747c
Add React Router v6 instrumentation docs.
onurtemizkan b336868
Apply suggestions from code review
onurtemizkan 95b43dc
Update src/platforms/javascript/guides/react/configuration/integratio…
onurtemizkan 6fb88b9
Add missing `from`.
onurtemizkan 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 |
---|---|---|
|
@@ -15,7 +15,67 @@ The React Router integration is designed to work with our Tracing SDK, `@sentry/ | |
|
||
</Alert> | ||
|
||
We support integrations for React Router 3, 4 and 5. | ||
We support integrations for React Router 3, 4, 5 and 6. | ||
|
||
## React Router v6 | ||
_(Available in version 7 and above)_ | ||
|
||
To use React Router v6 with Sentry, you need to: | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
1. Initialize `Sentry.reactRouterV6Instrumentation` as your routing instrumentation, and provide functions it needs to enable performance tracing. | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
You need to provide: | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- `useEffect` hook from `react` | ||
- `useLocation` and `useNavigationType` hooks from `react-router-dom` | ||
- `createRoutesFromChildren` and `matchRoutes` functions from `react-router-dom` or `react-router` packages. | ||
|
||
2. Wrap [`Routes`](https://reactrouter.com/docs/en/v6/api#routes-and-route) using `Sentry.withSentryReactRouterV6Routing` to create a higher order component, which will enable Sentry to reach your router context. | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Example usage: | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript | ||
import React from 'react'; | ||
import ReactDOM from "react-dom"; | ||
import { | ||
Routes, | ||
BrowserRouter, | ||
useLocation, | ||
useNavigationType, | ||
createRoutesFromChildren, | ||
matchRoutes, | ||
} from "react-router-dom"; | ||
import * as Sentry from "@sentry/react"; | ||
import { BrowserTracing } "@sentry/tracing"; | ||
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. Was testing the documentation and found there is missing 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. Thanks @BentoumiTech! |
||
|
||
Sentry.init({ | ||
integrations: [ | ||
new BrowserTracing({ | ||
routingInstrumentation: Sentry.reactRouterV6Instrumentation( | ||
React.useEffect, | ||
useLocation, | ||
useNavigationType, | ||
createRoutesFromChildren, | ||
matchRoutes, | ||
), | ||
}), | ||
], | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
const SentryRoutes = Sentry.withSentryReactRouterV6Routing(Routes) | ||
|
||
ReactDOM.render( | ||
<BrowserRouter> | ||
<SentryRoutes> | ||
<Route path="/" element={<div>Home</div>} /> | ||
</SentryRoutes> | ||
</BrowserRouter>, | ||
); | ||
``` | ||
|
||
Now, Sentry should be generating `pageload`/`navigation` transactions, with parameterized transaction names (ex. /teams/:teamid/user/:userid), where applicable. | ||
onurtemizkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
## React Router v4/v5 | ||
|
||
|
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.