react.tsx 9.9 KB

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