javascript.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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/browser
  50. # Using npm
  51. npm install --save @sentry/browser
  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. import * as Sentry from "@sentry/browser";
  66. Sentry.init({
  67. ${sentryInitContent}
  68. });
  69. `,
  70. },
  71. ],
  72. },
  73. getUploadSourceMapsStep({
  74. guideLink: 'https://docs.sentry.io/platforms/javascript/sourcemaps/',
  75. ...props,
  76. }),
  77. {
  78. type: StepType.VERIFY,
  79. description: t(
  80. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  81. ),
  82. configurations: [
  83. {
  84. language: 'javascript',
  85. code: 'myUndefinedFunction();',
  86. },
  87. ],
  88. },
  89. ];
  90. export const nextSteps = [
  91. {
  92. id: 'performance-monitoring',
  93. name: t('Performance Monitoring'),
  94. description: t(
  95. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  96. ),
  97. link: 'https://docs.sentry.io/platforms/javascript/performance/',
  98. },
  99. {
  100. id: 'session-replay',
  101. name: t('Session Replay'),
  102. description: t(
  103. '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.'
  104. ),
  105. link: 'https://docs.sentry.io/platforms/javascript/session-replay/',
  106. },
  107. ];
  108. // Configuration End
  109. export function GettingStartedWithJavaScript({
  110. dsn,
  111. activeProductSelection = [],
  112. organization,
  113. newOrg,
  114. platformKey,
  115. projectId,
  116. }: ModuleProps) {
  117. const integrations: string[] = [];
  118. const otherConfigs: string[] = [];
  119. let nextStepDocs = [...nextSteps];
  120. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  121. integrations.push(performanceIntegration.trim());
  122. otherConfigs.push(performanceOtherConfig.trim());
  123. nextStepDocs = nextStepDocs.filter(
  124. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  125. );
  126. }
  127. if (activeProductSelection.includes(ProductSolution.SESSION_REPLAY)) {
  128. integrations.push(replayIntegration.trim());
  129. otherConfigs.push(replayOtherConfig.trim());
  130. nextStepDocs = nextStepDocs.filter(
  131. step => step.id !== ProductSolution.SESSION_REPLAY
  132. );
  133. }
  134. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  135. if (integrations.length > 0) {
  136. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  137. }
  138. if (otherConfigs.length > 0) {
  139. sentryInitContent = sentryInitContent.concat(otherConfigs);
  140. }
  141. return (
  142. <Layout
  143. steps={steps({
  144. sentryInitContent: sentryInitContent.join('\n'),
  145. organization,
  146. newOrg,
  147. platformKey,
  148. projectId,
  149. })}
  150. nextSteps={nextStepDocs}
  151. platformKey={platformKey}
  152. newOrg={newOrg}
  153. />
  154. );
  155. }
  156. export default GettingStartedWithJavaScript;