javascript.tsx 4.4 KB

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