react.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import {
  3. Docs,
  4. DocsParams,
  5. OnboardingConfig,
  6. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  7. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  8. import {t, tct} from 'sentry/locale';
  9. type Params = DocsParams;
  10. const getSdkSetupSnippet = (params: Params) => `
  11. //...
  12. import * as Sentry from "@sentry/react";
  13. Sentry.init({
  14. dsn: "${params.dsn}",
  15. integrations: [${
  16. params.isPerformanceSelected
  17. ? `
  18. new Sentry.BrowserTracing({
  19. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  20. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],
  21. }),`
  22. : ''
  23. }${
  24. params.isReplaySelected
  25. ? `
  26. new Sentry.Replay(),`
  27. : ''
  28. }
  29. ],${
  30. params.isPerformanceSelected
  31. ? `
  32. // Performance Monitoring
  33. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  34. : ''
  35. }${
  36. params.isReplaySelected
  37. ? `
  38. // Session Replay
  39. 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.
  40. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  41. : ''
  42. }
  43. });
  44. const container = document.getElementById(“app”);
  45. const root = createRoot(container);
  46. root.render(<App />);
  47. `;
  48. const getVerifyReactSnippet = () => `
  49. return <button onClick={() => methodDoesNotExist()}>Break the world</button>;
  50. `;
  51. const onboarding: OnboardingConfig = {
  52. install: () => [
  53. {
  54. type: StepType.INSTALL,
  55. configurations: [
  56. {
  57. description: tct(
  58. 'Add the Sentry SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn]:',
  59. {
  60. codeYarn: <code />,
  61. codeNpm: <code />,
  62. }
  63. ),
  64. language: 'bash',
  65. code: [
  66. {
  67. label: 'npm',
  68. value: 'npm',
  69. language: 'bash',
  70. code: 'npm install --save @sentry/react',
  71. },
  72. {
  73. label: 'yarn',
  74. value: 'yarn',
  75. language: 'bash',
  76. code: 'yarn add @sentry/react',
  77. },
  78. ],
  79. },
  80. ],
  81. },
  82. ],
  83. configure: (params: Params) => [
  84. {
  85. type: StepType.CONFIGURE,
  86. description: t(
  87. "Initialize Sentry as early as possible in your application's lifecycle."
  88. ),
  89. configurations: [
  90. {
  91. code: [
  92. {
  93. label: 'JavaScript',
  94. value: 'javascript',
  95. language: 'javascript',
  96. code: getSdkSetupSnippet(params),
  97. },
  98. ],
  99. },
  100. ],
  101. },
  102. getUploadSourceMapsStep({
  103. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/react/sourcemaps/',
  104. }),
  105. ],
  106. verify: () => [
  107. {
  108. type: StepType.VERIFY,
  109. description: t(
  110. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  111. ),
  112. configurations: [
  113. {
  114. code: [
  115. {
  116. label: 'React',
  117. value: 'react',
  118. language: 'javascript',
  119. code: getVerifyReactSnippet(),
  120. },
  121. ],
  122. },
  123. ],
  124. },
  125. ],
  126. nextSteps: () => [
  127. {
  128. id: 'react-features',
  129. name: t('React Features'),
  130. description: t('Learn about our first class integration with the React framework.'),
  131. link: 'https://docs.sentry.io/platforms/javascript/guides/react/features/',
  132. },
  133. {
  134. id: 'react-router',
  135. name: t('React Router'),
  136. description: t(
  137. 'Configure routing, so Sentry can generate parameterized transaction names for a better overview in Performance Monitoring.'
  138. ),
  139. link: 'https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/',
  140. },
  141. {
  142. id: 'performance-monitoring',
  143. name: t('Performance Monitoring'),
  144. description: t(
  145. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  146. ),
  147. link: 'https://docs.sentry.io/platforms/javascript/guides/react/performance/',
  148. },
  149. {
  150. id: 'session-replay',
  151. name: t('Session Replay'),
  152. description: t(
  153. '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.'
  154. ),
  155. link: 'https://docs.sentry.io/platforms/javascript/guides/react/session-replay/',
  156. },
  157. ],
  158. };
  159. const docs: Docs = {
  160. onboarding,
  161. };
  162. export default docs;