react.tsx 9.6 KB

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