react.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {PlatformKey} from 'sentry/data/platformCategories';
  7. import {t} from 'sentry/locale';
  8. import type {Organization} from 'sentry/types';
  9. type StepProps = {
  10. newOrg: boolean;
  11. organization: Organization;
  12. platformKey: PlatformKey;
  13. projectId: string;
  14. sentryInitContent: string;
  15. };
  16. // Configuration Start
  17. const replayIntegration = `
  18. new Sentry.Replay(),
  19. `;
  20. const replayOtherConfig = `
  21. // Session Replay
  22. 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.
  23. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
  24. `;
  25. const performanceIntegration = `
  26. new Sentry.BrowserTracing({
  27. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  28. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],
  29. }),
  30. `;
  31. const performanceOtherConfig = `
  32. // Performance Monitoring
  33. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!
  34. `;
  35. export const steps = ({
  36. sentryInitContent,
  37. ...props
  38. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  39. {
  40. type: StepType.INSTALL,
  41. description: t(
  42. 'Sentry captures data by using an SDK within your application’s runtime.'
  43. ),
  44. configurations: [
  45. {
  46. language: 'bash',
  47. code: `
  48. # Using yarn
  49. yarn add @sentry/react
  50. # Using npm
  51. npm install --save @sentry/react
  52. `,
  53. },
  54. ],
  55. },
  56. {
  57. type: StepType.CONFIGURE,
  58. description: t(
  59. "Initialize Sentry as early as possible in your application's lifecycle."
  60. ),
  61. configurations: [
  62. {
  63. language: 'javascript',
  64. code: `
  65. //...
  66. import * as Sentry from "@sentry/react";
  67. Sentry.init({
  68. ${sentryInitContent}
  69. });
  70. const container = document.getElementById(“app”);
  71. const root = createRoot(container);
  72. root.render(<App />);
  73. `,
  74. },
  75. ],
  76. },
  77. getUploadSourceMapsStep({
  78. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/react/sourcemaps/',
  79. ...props,
  80. }),
  81. {
  82. type: StepType.VERIFY,
  83. description: t(
  84. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  85. ),
  86. configurations: [
  87. {
  88. language: 'javascript',
  89. code: `
  90. return <button onClick={() => methodDoesNotExist()}>Break the world</button>;
  91. `,
  92. },
  93. ],
  94. },
  95. ];
  96. export const nextSteps = [
  97. {
  98. id: 'react-features',
  99. name: t('React Features'),
  100. description: t('Learn about our first class integration with the React framework.'),
  101. link: 'https://docs.sentry.io/platforms/javascript/guides/react/features/',
  102. },
  103. {
  104. id: 'react-router',
  105. name: t('React Router'),
  106. description: t(
  107. 'Configure routing, so Sentry can generate parameterized transaction names for a better overview in Performance Monitoring.'
  108. ),
  109. link: 'https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/',
  110. },
  111. {
  112. id: 'performance-monitoring',
  113. name: t('Performance Monitoring'),
  114. description: t(
  115. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  116. ),
  117. link: 'https://docs.sentry.io/platforms/javascript/guides/react/performance/',
  118. },
  119. {
  120. id: 'session-replay',
  121. name: t('Session Replay'),
  122. description: t(
  123. '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.'
  124. ),
  125. link: 'https://docs.sentry.io/platforms/javascript/guides/react/session-replay/',
  126. },
  127. ];
  128. // Configuration End
  129. export function GettingStartedWithReact({
  130. dsn,
  131. activeProductSelection = [],
  132. organization,
  133. newOrg,
  134. platformKey,
  135. projectId,
  136. }: ModuleProps) {
  137. const integrations: string[] = [];
  138. const otherConfigs: string[] = [];
  139. let nextStepDocs = [...nextSteps];
  140. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  141. integrations.push(performanceIntegration.trim());
  142. otherConfigs.push(performanceOtherConfig.trim());
  143. nextStepDocs = nextStepDocs.filter(
  144. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  145. );
  146. }
  147. if (activeProductSelection.includes(ProductSolution.SESSION_REPLAY)) {
  148. integrations.push(replayIntegration.trim());
  149. otherConfigs.push(replayOtherConfig.trim());
  150. nextStepDocs = nextStepDocs.filter(
  151. step => step.id !== ProductSolution.SESSION_REPLAY
  152. );
  153. }
  154. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  155. if (integrations.length > 0) {
  156. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  157. }
  158. if (otherConfigs.length > 0) {
  159. sentryInitContent = sentryInitContent.concat(otherConfigs);
  160. }
  161. return (
  162. <Layout
  163. steps={steps({
  164. sentryInitContent: sentryInitContent.join('\n'),
  165. organization,
  166. newOrg,
  167. platformKey,
  168. projectId,
  169. })}
  170. nextSteps={nextStepDocs}
  171. newOrg={newOrg}
  172. platformKey={platformKey}
  173. />
  174. );
  175. }
  176. export default GettingStartedWithReact;