javascript.tsx 5.1 KB

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