react.tsx 6.3 KB

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