react.tsx 5.9 KB

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