react.tsx 9.1 KB

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