react.tsx 7.9 KB

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