/
react.tsx
299 lines (287 loc) · 9.07 KB
/
react.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import crashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/crashReportCallout';
import widgetCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/widgetCallout';
import TracePropagationMessage from 'sentry/components/onboarding/gettingStartedDoc/replay/tracePropagationMessage';
import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
import type {
Docs,
DocsParams,
OnboardingConfig,
} from 'sentry/components/onboarding/gettingStartedDoc/types';
import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
import {
getCrashReportJavaScriptInstallStep,
getCrashReportModalConfigDescription,
getCrashReportModalIntroduction,
getFeedbackConfigOptions,
getFeedbackConfigureDescription,
} from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
import {getJSMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
import {
getReplayConfigOptions,
getReplayConfigureDescription,
} from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
import {t, tct} from 'sentry/locale';
type Params = DocsParams;
const getSdkSetupSnippet = (params: Params) => `
//...
import * as Sentry from "@sentry/react";
Sentry.init({
dsn: "${params.dsn}",
integrations: [${
params.isPerformanceSelected
? `
Sentry.browserTracingIntegration(),`
: ''
}${
params.isFeedbackSelected
? `
Sentry.feedbackIntegration({
// Additional SDK configuration goes in here, for example:
colorScheme: "system",
${getFeedbackConfigOptions(params.feedbackOptions)}}),`
: ''
}${
params.isReplaySelected
? `
Sentry.replayIntegration(${getReplayConfigOptions(params.replayOptions)}),`
: ''
}
],${
params.isPerformanceSelected
? `
// Performance Monitoring
tracesSampleRate: 1.0, // Capture 100% of the transactions
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],`
: ''
}${
params.isReplaySelected
? `
// Session Replay
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
: ''
}
});
const container = document.getElementById(“app”);
const root = createRoot(container);
root.render(<App />);
`;
const getVerifyReactSnippet = () => `
return <button onClick={() => methodDoesNotExist()}>Break the world</button>;
`;
const getInstallConfig = () => [
{
language: 'bash',
code: [
{
label: 'npm',
value: 'npm',
language: 'bash',
code: 'npm install --save @sentry/react',
},
{
label: 'yarn',
value: 'yarn',
language: 'bash',
code: 'yarn add @sentry/react',
},
],
},
];
const onboarding: OnboardingConfig = {
install: () => [
{
type: StepType.INSTALL,
description: tct(
'Add the Sentry SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn]:',
{
codeYarn: <code />,
codeNpm: <code />,
}
),
configurations: getInstallConfig(),
},
],
configure: (params: Params) => [
{
type: StepType.CONFIGURE,
description: t(
"Initialize Sentry as early as possible in your application's lifecycle."
),
configurations: [
{
code: [
{
label: 'JavaScript',
value: 'javascript',
language: 'javascript',
code: getSdkSetupSnippet(params),
},
],
},
],
},
getUploadSourceMapsStep({
guideLink: 'https://docs.sentry.io/platforms/javascript/guides/react/sourcemaps/',
}),
],
verify: () => [
{
type: StepType.VERIFY,
description: t(
"This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
),
configurations: [
{
code: [
{
label: 'React',
value: 'react',
language: 'javascript',
code: getVerifyReactSnippet(),
},
],
},
],
},
],
nextSteps: () => [
{
id: 'react-features',
name: t('React Features'),
description: t('Learn about our first class integration with the React framework.'),
link: 'https://docs.sentry.io/platforms/javascript/guides/react/features/',
},
{
id: 'react-router',
name: t('React Router'),
description: t(
'Configure routing, so Sentry can generate parameterized transaction names for a better overview in Performance Monitoring.'
),
link: 'https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/',
},
{
id: 'performance-monitoring',
name: t('Performance Monitoring'),
description: t(
'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
),
link: 'https://docs.sentry.io/platforms/javascript/guides/react/performance/',
},
{
id: 'session-replay',
name: t('Session Replay'),
description: t(
'Get to the root cause of an error or latency issue faster by seeing all the technical details related to that issue in one visual replay on your web application.'
),
link: 'https://docs.sentry.io/platforms/javascript/guides/react/session-replay/',
},
],
};
const replayOnboarding: OnboardingConfig = {
install: () => [
{
type: StepType.INSTALL,
description: tct(
'Add the Sentry SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn]. You need a minimum version 7.27.0 of [code:@sentry/react] in order to use Session Replay. You do not need to install any additional packages.',
{
code: <code />,
codeYarn: <code />,
codeNpm: <code />,
}
),
configurations: getInstallConfig(),
},
],
configure: (params: Params) => [
{
type: StepType.CONFIGURE,
description: getReplayConfigureDescription({
link: 'https://docs.sentry.io/platforms/javascript/guides/react/session-replay/',
}),
configurations: [
{
code: [
{
label: 'JavaScript',
value: 'javascript',
language: 'javascript',
code: getSdkSetupSnippet(params),
},
],
additionalInfo: <TracePropagationMessage />,
},
],
},
],
verify: () => [],
nextSteps: () => [],
};
const feedbackOnboarding: OnboardingConfig = {
install: () => [
{
type: StepType.INSTALL,
description: tct(
'For the User Feedback integration to work, you must have the Sentry browser SDK package, or an equivalent framework SDK (e.g. [code:@sentry/react]) installed, minimum version 7.85.0.',
{
code: <code />,
}
),
configurations: getInstallConfig(),
},
],
configure: (params: Params) => [
{
type: StepType.CONFIGURE,
description: getFeedbackConfigureDescription({
linkConfig:
'https://docs.sentry.io/platforms/javascript/guides/react/user-feedback/configuration/',
linkButton:
'https://docs.sentry.io/platforms/javascript/guides/react/user-feedback/configuration/#bring-your-own-button',
}),
configurations: [
{
code: [
{
label: 'JavaScript',
value: 'javascript',
language: 'javascript',
code: getSdkSetupSnippet(params),
},
],
},
],
additionalInfo: crashReportCallout({
link: 'https://docs.sentry.io/platforms/javascript/guides/react/user-feedback/#crash-report-modal',
}),
},
],
verify: () => [],
nextSteps: () => [],
};
const crashReportOnboarding: OnboardingConfig = {
introduction: () => getCrashReportModalIntroduction(),
install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
configure: () => [
{
type: StepType.CONFIGURE,
description: getCrashReportModalConfigDescription({
link: 'https://docs.sentry.io/platforms/javascript/guides/react/user-feedback/configuration/#crash-report-modal',
}),
additionalInfo: widgetCallout({
link: 'https://docs.sentry.io/platforms/javascript/guides/react/user-feedback/#user-feedback-widget',
}),
},
],
verify: () => [],
nextSteps: () => [],
};
const docs: Docs = {
onboarding,
feedbackOnboardingNpm: feedbackOnboarding,
replayOnboardingNpm: replayOnboarding,
customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
crashReportOnboarding,
};
export default docs;