javascript.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import {
  3. Docs,
  4. DocsParams,
  5. OnboardingConfig,
  6. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  7. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  8. import {t} from 'sentry/locale';
  9. type Params = DocsParams;
  10. const getSdkSetupSnippet = (params: Params) => `
  11. import * as Sentry from "@sentry/browser";
  12. Sentry.init({
  13. dsn: "${params.dsn}",
  14. integrations: [${
  15. params.isPerformanceSelected
  16. ? `
  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. }${
  23. params.isReplaySelected
  24. ? `
  25. new Sentry.Replay(),`
  26. : ''
  27. }
  28. ],${
  29. params.isPerformanceSelected
  30. ? `
  31. // Performance Monitoring
  32. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  33. : ''
  34. }${
  35. params.isReplaySelected
  36. ? `
  37. // Session Replay
  38. 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.
  39. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  40. : ''
  41. }
  42. });
  43. `;
  44. const getVerifyJSSnippet = () => `
  45. myUndefinedFunction();`;
  46. const onboarding: OnboardingConfig = {
  47. install: () => [
  48. {
  49. type: StepType.INSTALL,
  50. configurations: [
  51. {
  52. description: t(
  53. 'Sentry captures data by using an SDK within your application’s runtime.'
  54. ),
  55. language: 'bash',
  56. code: [
  57. {
  58. label: 'npm',
  59. value: 'npm',
  60. language: 'bash',
  61. code: 'npm install --save @sentry/browser',
  62. },
  63. {
  64. label: 'yarn',
  65. value: 'yarn',
  66. language: 'bash',
  67. code: 'yarn add @sentry/browser',
  68. },
  69. ],
  70. },
  71. ],
  72. },
  73. ],
  74. configure: (params: Params) => [
  75. {
  76. type: StepType.CONFIGURE,
  77. description: t(
  78. "Initialize Sentry as early as possible in your application's lifecycle."
  79. ),
  80. configurations: [
  81. {
  82. code: [
  83. {
  84. label: 'JavaScript',
  85. value: 'javascript',
  86. language: 'javascript',
  87. code: getSdkSetupSnippet(params),
  88. },
  89. ],
  90. },
  91. ],
  92. },
  93. getUploadSourceMapsStep({
  94. guideLink: 'https://docs.sentry.io/platforms/javascript/sourcemaps/',
  95. }),
  96. ],
  97. verify: () => [
  98. {
  99. type: StepType.VERIFY,
  100. description: t(
  101. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  102. ),
  103. configurations: [
  104. {
  105. code: [
  106. {
  107. label: 'Javascript',
  108. value: 'javascript',
  109. language: 'javascript',
  110. code: getVerifyJSSnippet(),
  111. },
  112. ],
  113. },
  114. ],
  115. },
  116. ],
  117. nextSteps: () => [
  118. {
  119. id: 'performance-monitoring',
  120. name: t('Performance Monitoring'),
  121. description: t(
  122. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  123. ),
  124. link: 'https://docs.sentry.io/platforms/javascript/performance/',
  125. },
  126. {
  127. id: 'session-replay',
  128. name: t('Session Replay'),
  129. description: t(
  130. '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.'
  131. ),
  132. link: 'https://docs.sentry.io/platforms/javascript/session-replay/',
  133. },
  134. ],
  135. };
  136. const docs: Docs = {
  137. onboarding,
  138. };
  139. export default docs;