Skip to content

Commit 5c89ac4

Browse files
docs(js): React Quick Start guide for Tracing (#13186)
* React Quick Start guide for Error Monitoring feature only * update section on error boundary * make Step 4 optional * update React QS guide for Tracing * merge with error monitoring and fine-tune
1 parent caca9aa commit 5c89ac4

File tree

1 file changed

+42
-22
lines changed
  • docs/platforms/javascript/guides/react

1 file changed

+42
-22
lines changed

docs/platforms/javascript/guides/react/index.mdx

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,20 @@ pnpm add @sentry/react
5050

5151
## Step 2: Configure
5252

53-
Sentry supports multiple versions of React Router. To learn how to configure them, read the <PlatformLink to="/configuration/integrations/react-router/">React Router Integration</PlatformLink> docs.
54-
5553
### Initialize the Sentry SDK
5654

5755
To import and initialize Sentry, create a file in your project's root directory, for example, `instrument.js`, and add the following code:
5856

59-
```javascript {filename:instrument.js} {"onboardingOptions": {"performance": "1, 3-8, 13-21, 24-30", "session-replay": "22, 33-39"}}
60-
import { useEffect } from "react";
57+
```javascript {filename:instrument.js} {"onboardingOptions": {"performance": "6-9, 12-20", "session-replay": "10, 21-27"}}
6158
import * as Sentry from "@sentry/react";
62-
import {
63-
createRoutesFromChildren,
64-
matchRoutes,
65-
useLocation,
66-
useNavigationType,
67-
} from "react-router-dom";
6859

6960
Sentry.init({
7061
dsn: "___PUBLIC_DSN___",
7162
integrations: [
72-
// See docs for support of different versions of variation of react router
63+
// If you're using react router, use the integration for your react router version instead.
64+
// Learn more at
7365
// https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/
74-
Sentry.reactRouterV6BrowserTracingIntegration({
75-
useEffect,
76-
useLocation,
77-
useNavigationType,
78-
createRoutesFromChildren,
79-
matchRoutes,
80-
}),
66+
Sentry.browserTracingIntegration(),
8167
Sentry.replayIntegration(),
8268
],
8369

@@ -160,9 +146,14 @@ import * as Sentry from "@sentry/react";
160146
</Alert>
161147

162148
<OnboardingOption optionId="performance">
163-
## Step 4: Set Up React Router (Optional)
149+
## Step 4: Set Up React Router
150+
If you're using `react-router` in your application, you need to set up the Sentry integration for your specific React Router version to trace `navigation` events.\
151+
Select your React Router version to start instrumenting your routing:
164152

165-
The React Router integration is designed to work with our tracing package. Learn more about set up for our [React Router Integration](configuration/integrations/react-router/).
153+
- [React Router v7 (library mode)](features/react-router/v7)
154+
- [React Router v6](features/react-router/v6)
155+
- [Older React Router versions](features/react-router)
156+
- [TanStack Router](features/tanstack-router)
166157

167158
## Step 5: Capture Redux State Data (Optional)
168159

@@ -194,7 +185,9 @@ To capture Redux state data, use `Sentry.createReduxEnhancer` when initializing
194185

195186
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
196187

197-
Add the following test button to one of your pages, which will trigger an error that Sentry will capture when you click it:
188+
### Issues
189+
190+
To verify that Sentry captures errors and creates issues in your Sentry project, add the following test button to one of your pages, which will trigger an error that Sentry will capture when you click it:
198191

199192
```javascript
200193
<button
@@ -207,10 +200,37 @@ Add the following test button to one of your pages, which will trigger an error
207200
</button>
208201
```
209202

210-
Open the page in a browser (for most React applications, this will be at localhost) and click the button to trigger a frontend error.
203+
<OnboardingOption optionId="performance" hideForThisOption>
204+
Open the page in a browser (for most React applications, this will be at
205+
localhost) and click the button to trigger a frontend error.
206+
</OnboardingOption>
211207

212208
<PlatformContent includePath="getting-started-browser-sandbox-warning" />
213209

210+
<OnboardingOption optionId="performance">
211+
### Tracing
212+
213+
To test your tracing configuration, update the previous code snippet to start a performance trace to measure the time it takes for the execution of your code:
214+
215+
```javascript
216+
<button
217+
type="button"
218+
onClick={() => {
219+
Sentry.startSpan({ op: "test", name: "Example Frontend Span" }, () => {
220+
setTimeout(() => {
221+
throw new Error("Sentry Test Error");
222+
}, 99);
223+
});
224+
}}
225+
>
226+
Break the world
227+
</button>
228+
```
229+
230+
Open the page in a browser (for most React applications, this will be at localhost) and click the button to trigger a frontend error and performance trace.
231+
232+
</OnboardingOption>
233+
214234
### View Captured Data in Sentry
215235

216236
Now, head over to your project on [Sentry.io](https://sentry.io/) to view the collected data (it takes a couple of moments for the data to appear).

0 commit comments

Comments
 (0)