javascript.tsx 5.1 KB

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