react.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. Sentry.init({
  66. ${sentryInitContent}
  67. });
  68. const container = document.getElementById(“app”);
  69. const root = createRoot(container);
  70. root.render(<App />)
  71. `,
  72. },
  73. ],
  74. },
  75. getUploadSourceMapsStep({
  76. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/react/sourcemaps/',
  77. ...props,
  78. }),
  79. {
  80. type: StepType.VERIFY,
  81. description: t(
  82. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  83. ),
  84. configurations: [
  85. {
  86. language: 'javascript',
  87. code: `
  88. return <button onClick={() => methodDoesNotExist()}>Break the world</button>;
  89. `,
  90. },
  91. ],
  92. },
  93. ];
  94. export const nextSteps = [
  95. {
  96. id: 'react-features',
  97. name: t('React Features'),
  98. description: t('Learn about our first class integration with the React framework.'),
  99. link: 'https://docs.sentry.io/platforms/javascript/guides/react/features/',
  100. },
  101. {
  102. id: 'react-router',
  103. name: t('React Router'),
  104. description: t(
  105. 'Configure routing, so Sentry can generate parameterized transaction names for a better overview in Performance Monitoring.'
  106. ),
  107. link: 'https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/',
  108. },
  109. {
  110. id: 'performance-monitoring',
  111. name: t('Performance Monitoring'),
  112. description: t(
  113. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  114. ),
  115. link: 'https://docs.sentry.io/platforms/javascript/guides/react/performance/',
  116. },
  117. {
  118. id: 'session-replay',
  119. name: t('Session Replay'),
  120. description: t(
  121. '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.'
  122. ),
  123. link: 'https://docs.sentry.io/platforms/javascript/guides/react/session-replay/',
  124. },
  125. ];
  126. // Configuration End
  127. export function GettingStartedWithReact({
  128. dsn,
  129. activeProductSelection = [],
  130. organization,
  131. newOrg,
  132. platformKey,
  133. projectId,
  134. }: ModuleProps) {
  135. const integrations: string[] = [];
  136. const otherConfigs: string[] = [];
  137. let nextStepDocs = [...nextSteps];
  138. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  139. integrations.push(performanceIntegration.trim());
  140. otherConfigs.push(performanceOtherConfig.trim());
  141. nextStepDocs = nextStepDocs.filter(
  142. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  143. );
  144. }
  145. if (activeProductSelection.includes(ProductSolution.SESSION_REPLAY)) {
  146. integrations.push(replayIntegration.trim());
  147. otherConfigs.push(replayOtherConfig.trim());
  148. nextStepDocs = nextStepDocs.filter(
  149. step => step.id !== ProductSolution.SESSION_REPLAY
  150. );
  151. }
  152. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  153. if (integrations.length > 0) {
  154. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  155. }
  156. if (otherConfigs.length > 0) {
  157. sentryInitContent = sentryInitContent.concat(otherConfigs);
  158. }
  159. return (
  160. <Layout
  161. steps={steps({
  162. sentryInitContent: sentryInitContent.join('\n'),
  163. organization,
  164. newOrg,
  165. platformKey,
  166. projectId,
  167. })}
  168. nextSteps={nextStepDocs}
  169. newOrg={newOrg}
  170. platformKey={platformKey}
  171. />
  172. );
  173. }
  174. export default GettingStartedWithReact;