@@ -25,61 +25,68 @@ import {getNodeAgentMonitoringOnboarding} from 'sentry/utils/gettingStartedDocs/
25
25
26
26
type Params = DocsParams ;
27
27
28
- const getClientSetupSnippet = ( params : Params ) => `
29
- import * as Sentry from "@sentry/react-router";
30
- import { startTransition, StrictMode } from "react";
31
- import { hydrateRoot } from "react-dom/client";
32
- import { HydratedRouter } from "react-router/dom";
28
+ const getClientSetupSnippet = ( params : Params ) => {
29
+ const logsSnippet = params . isLogsSelected
30
+ ? `
31
+ // Enable logs to be sent to Sentry
32
+ enableLogs: true,`
33
+ : '' ;
33
34
34
- Sentry.init({
35
- dsn: "${ params . dsn . public } ",
35
+ const performanceSnippet = params . isPerformanceSelected
36
+ ? `
37
+ tracesSampleRate: 1.0, // Capture 100% of the transactions
38
+ // Set \`tracePropagationTargets\` to declare which URL(s) should have trace propagation enabled
39
+ tracePropagationTargets: [/^\\//, /^https:\\/\\/yourserver\\.io\\/api/],`
40
+ : '' ;
36
41
37
- // Adds request headers and IP for users, for more info visit:
38
- // https://docs.sentry.io/platforms/javascript/guides/react-router/configuration/options/#sendDefaultPii
39
- sendDefaultPii: true,
42
+ const replaySnippet = params . isReplaySelected
43
+ ? `
44
+ replaysSessionSampleRate: 0.1, // Capture 10% of all sessions
45
+ replaysOnErrorSampleRate: 1.0, // Capture 100% of sessions with an error`
46
+ : '' ;
40
47
41
- integrations: [${
42
- params . isPerformanceSelected
43
- ? `
44
- // Performance
45
- Sentry.reactRouterTracingIntegration(),`
46
- : ''
47
- } ${
48
- params . isReplaySelected
49
- ? `
48
+ const integrationsList = [ ] ;
49
+
50
+ if ( params . isPerformanceSelected ) {
51
+ integrationsList . push ( `
52
+ // Tracing
53
+ Sentry.reactRouterTracingIntegration(),` ) ;
54
+ }
55
+
56
+ if ( params . isReplaySelected ) {
57
+ integrationsList . push ( `
50
58
// Session Replay
51
- Sentry.replayIntegration(${ getReplayConfigOptions ( params . replayOptions ) } ),`
52
- : ''
53
- } ${
54
- params . isFeedbackSelected
55
- ? `
59
+ Sentry.replayIntegration(${ getReplayConfigOptions ( params . replayOptions ) } ),` ) ;
60
+ }
61
+
62
+ if ( params . isFeedbackSelected ) {
63
+ integrationsList . push ( `
56
64
// User Feedback
57
65
Sentry.feedbackIntegration({
58
66
// Additional SDK configuration goes in here, for example:
59
67
colorScheme: "system",
60
68
${ getFeedbackConfigOptions ( params . feedbackOptions ) }
61
- }),`
62
- : ''
69
+ }),` ) ;
63
70
}
64
- ],${
65
- params . isPerformanceSelected
66
- ? `
67
-
68
- tracesSampleRate: 1.0, // Capture 100% of the transactions
69
71
70
- // Set \`tracePropagationTargets\` to declare which URL(s) should have trace propagation enabled
71
- tracePropagationTargets: [/^\\//, /^https:\\/\\/yourserver\\.io\\/api/],`
72
- : ''
73
- } ${
74
- params . isReplaySelected
72
+ const integrationsCode =
73
+ integrationsList . length > 0
75
74
? `
75
+ integrations: [${ integrationsList . join ( '' ) }
76
+ ],`
77
+ : '' ;
76
78
77
- // Capture Replay for 10% of all sessions,
78
- // plus 100% of sessions with an error
79
- replaysSessionSampleRate: 0.1,
80
- replaysOnErrorSampleRate: 1.0,`
81
- : ''
82
- }
79
+ return `
80
+ import * as Sentry from "@sentry/react-router";
81
+ import { startTransition, StrictMode } from "react";
82
+ import { hydrateRoot } from "react-dom/client";
83
+ import { HydratedRouter } from "react-router/dom";
84
+
85
+ Sentry.init({
86
+ dsn: "${ params . dsn . public } ",
87
+ // Adds request headers and IP for users, for more info visit:
88
+ // https://docs.sentry.io/platforms/javascript/guides/react-router/configuration/options/#sendDefaultPii
89
+ sendDefaultPii: true,${ integrationsCode } ${ logsSnippet } ${ performanceSnippet } ${ replaySnippet }
83
90
});
84
91
85
92
startTransition(() => {
@@ -90,6 +97,7 @@ startTransition(() => {
90
97
</StrictMode>
91
98
);
92
99
});` ;
100
+ } ;
93
101
94
102
const getRootErrorBoundarySnippet = ( ) => `
95
103
import * as Sentry from "@sentry/react-router";
@@ -127,37 +135,53 @@ export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
127
135
);
128
136
}` ;
129
137
130
- const getServerSetupSnippet = ( params : Params ) => `
131
- import * as Sentry from "@sentry/react-router";${
132
- params . isProfilingSelected
138
+ const getServerSetupSnippet = ( params : Params ) => {
139
+ const logsSnippet = params . isLogsSelected
140
+ ? `
141
+ // Enable logs to be sent to Sentry
142
+ enableLogs: true,`
143
+ : '' ;
144
+
145
+ const performanceSnippet = params . isPerformanceSelected
146
+ ? `
147
+ tracesSampleRate: 1.0, // Capture 100% of the transactions`
148
+ : '' ;
149
+
150
+ const profilingSnippet = params . isProfilingSelected
151
+ ? `
152
+ profilesSampleRate: 1.0, // profile every transaction`
153
+ : '' ;
154
+
155
+ const profilingImport = params . isProfilingSelected
133
156
? `
134
157
import { nodeProfilingIntegration } from '@sentry/profiling-node';`
135
- : ''
136
- }
158
+ : '' ;
159
+
160
+ const integrationsList = [ ] ;
161
+
162
+ if ( params . isProfilingSelected ) {
163
+ integrationsList . push ( `
164
+ // Profiling
165
+ nodeProfilingIntegration(),` ) ;
166
+ }
167
+
168
+ const integrationsCode =
169
+ integrationsList . length > 0
170
+ ? `
171
+ integrations: [${ integrationsList . join ( '' ) }
172
+ ],`
173
+ : '' ;
174
+
175
+ return `
176
+ import * as Sentry from "@sentry/react-router";${ profilingImport }
137
177
138
178
Sentry.init({
139
179
dsn: "${ params . dsn . public } ",
140
-
141
180
// Adds request headers and IP for users, for more info visit:
142
181
// https://docs.sentry.io/platforms/javascript/guides/react-router/configuration/options/#sendDefaultPii
143
- sendDefaultPii: true,${
144
- params . isProfilingSelected
145
- ? `
146
-
147
- integrations: [nodeProfilingIntegration()],`
148
- : ''
149
- } ${
150
- params . isPerformanceSelected
151
- ? `
152
- tracesSampleRate: 1.0, // Capture 100% of the transactions`
153
- : ''
154
- } ${
155
- params . isProfilingSelected
156
- ? `
157
- profilesSampleRate: 1.0, // profile every transaction`
158
- : ''
159
- }
182
+ sendDefaultPii: true,${ integrationsCode } ${ logsSnippet } ${ performanceSnippet } ${ profilingSnippet }
160
183
});` ;
184
+ } ;
161
185
162
186
const getServerEntrySnippet = ( ) => `
163
187
import * as Sentry from '@sentry/react-router';
@@ -178,21 +202,30 @@ export const handleError: HandleErrorFunction = (error, { request }) => {
178
202
// React Router may abort some interrupted requests, don't log those
179
203
if (!request.signal.aborted) {
180
204
Sentry.captureException(error);
181
- // optionally log the error so you can see it
205
+ // optionally log the error to the console so you can see it
182
206
console.error(error);
183
207
}
184
208
};` ;
185
209
186
- const getVerifySnippet = ( ) => `
210
+ const getVerifySnippet = ( params : Params ) => {
211
+ const logsCode = params . isLogsSelected
212
+ ? `
213
+ // Send a log before throwing the error
214
+ Sentry.logger.info("User triggered test error", {
215
+ 'action': 'test_loader_error',
216
+ });`
217
+ : '' ;
218
+ return `
187
219
import type { Route } from "./+types/error-page";
188
220
189
- export async function loader() {
221
+ export async function loader() {${ logsCode }
190
222
throw new Error("Sentry Test Error");
191
223
}
192
224
193
225
export default function ErrorPage() {
194
226
return <div>This page will throw an error!</div>;
195
227
}` ;
228
+ } ;
196
229
197
230
const getPackageJsonScriptsSnippet = ( ) => `
198
231
{
@@ -297,7 +330,7 @@ const onboarding: OnboardingConfig = {
297
330
} ,
298
331
{
299
332
description : tct (
300
- 'Initialize the Sentry React Router SDK in your [code:entry.client.tsx] file:' ,
333
+ 'Initialize the Sentry React Router SDK in your [code:entry.client.tsx] file, above where you call [code:hydrateRoot] :' ,
301
334
{ code : < code /> }
302
335
) ,
303
336
title : t ( 'Client Setup' ) ,
@@ -369,7 +402,7 @@ const onboarding: OnboardingConfig = {
369
402
collapsible : true ,
370
403
} ,
371
404
] ,
372
- verify : ( ) => [
405
+ verify : params => [
373
406
{
374
407
type : StepType . VERIFY ,
375
408
description : t (
@@ -378,7 +411,7 @@ const onboarding: OnboardingConfig = {
378
411
configurations : [
379
412
{
380
413
language : 'tsx' ,
381
- code : getVerifySnippet ( ) ,
414
+ code : getVerifySnippet ( params ) ,
382
415
} ,
383
416
] ,
384
417
} ,
0 commit comments