javascript.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import type {
  3. Docs,
  4. DocsParams,
  5. OnboardingConfig,
  6. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  7. import {
  8. getReplayConfigOptions,
  9. getReplayConfigureDescription,
  10. getUploadSourceMapsStep,
  11. } from 'sentry/components/onboarding/gettingStartedDoc/utils';
  12. import {getJSMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  13. import {tracePropagationMessage} from 'sentry/components/replaysOnboarding/utils';
  14. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  15. import {t, tct} from 'sentry/locale';
  16. type Params = DocsParams;
  17. const getSdkSetupSnippet = (params: Params) => `
  18. import * as Sentry from "@sentry/browser";
  19. Sentry.init({
  20. dsn: "${params.dsn}",
  21. integrations: [${
  22. params.isPerformanceSelected
  23. ? `
  24. Sentry.browserTracingIntegration(),`
  25. : ''
  26. }${
  27. params.isReplaySelected
  28. ? `
  29. Sentry.replayIntegration(${getReplayConfigOptions(params.replayOptions)}),`
  30. : ''
  31. }
  32. ],${
  33. params.isPerformanceSelected
  34. ? `
  35. // Performance Monitoring
  36. tracesSampleRate: 1.0, // Capture 100% of the transactions
  37. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  38. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],`
  39. : ''
  40. }${
  41. params.isReplaySelected
  42. ? `
  43. // Session Replay
  44. 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.
  45. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  46. : ''
  47. }
  48. });
  49. `;
  50. const getVerifyJSSnippet = () => `
  51. myUndefinedFunction();`;
  52. const getInstallConfig = () => [
  53. {
  54. language: 'bash',
  55. code: [
  56. {
  57. label: 'npm',
  58. value: 'npm',
  59. language: 'bash',
  60. code: 'npm install --save @sentry/browser',
  61. },
  62. {
  63. label: 'yarn',
  64. value: 'yarn',
  65. language: 'bash',
  66. code: 'yarn add @sentry/browser',
  67. },
  68. ],
  69. },
  70. ];
  71. const onboarding: OnboardingConfig = {
  72. install: () => [
  73. {
  74. type: StepType.INSTALL,
  75. description: t(
  76. 'Sentry captures data by using an SDK within your application’s runtime.'
  77. ),
  78. configurations: getInstallConfig(),
  79. },
  80. ],
  81. configure: (params: Params) => [
  82. {
  83. type: StepType.CONFIGURE,
  84. description: t(
  85. "Initialize Sentry as early as possible in your application's lifecycle."
  86. ),
  87. configurations: [
  88. {
  89. code: [
  90. {
  91. label: 'JavaScript',
  92. value: 'javascript',
  93. language: 'javascript',
  94. code: getSdkSetupSnippet(params),
  95. },
  96. ],
  97. },
  98. ],
  99. },
  100. getUploadSourceMapsStep({
  101. guideLink: 'https://docs.sentry.io/platforms/javascript/sourcemaps/',
  102. }),
  103. ],
  104. verify: () => [
  105. {
  106. type: StepType.VERIFY,
  107. description: t(
  108. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  109. ),
  110. configurations: [
  111. {
  112. code: [
  113. {
  114. label: 'Javascript',
  115. value: 'javascript',
  116. language: 'javascript',
  117. code: getVerifyJSSnippet(),
  118. },
  119. ],
  120. },
  121. ],
  122. },
  123. ],
  124. nextSteps: () => [
  125. {
  126. id: 'performance-monitoring',
  127. name: t('Performance Monitoring'),
  128. description: t(
  129. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  130. ),
  131. link: 'https://docs.sentry.io/platforms/javascript/performance/',
  132. },
  133. {
  134. id: 'session-replay',
  135. name: t('Session Replay'),
  136. description: t(
  137. '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.'
  138. ),
  139. link: 'https://docs.sentry.io/platforms/javascript/session-replay/',
  140. },
  141. ],
  142. };
  143. const replayOnboarding: OnboardingConfig = {
  144. install: () => [
  145. {
  146. type: StepType.INSTALL,
  147. description: tct(
  148. 'For the Session Replay to work, you must have the Sentry browser SDK package, or an equivalent framework SDK (e.g. [code:@sentry/react]) installed, minimum version 7.27.0.',
  149. {
  150. code: <code />,
  151. }
  152. ),
  153. configurations: getInstallConfig(),
  154. },
  155. ],
  156. configure: (params: Params) => [
  157. {
  158. type: StepType.CONFIGURE,
  159. description: getReplayConfigureDescription({
  160. link: 'https://docs.sentry.io/platforms/javascript/session-replay/',
  161. }),
  162. configurations: [
  163. {
  164. code: [
  165. {
  166. label: 'JavaScript',
  167. value: 'javascript',
  168. language: 'javascript',
  169. code: getSdkSetupSnippet(params),
  170. },
  171. ],
  172. },
  173. ],
  174. additionalInfo: tracePropagationMessage,
  175. },
  176. ],
  177. verify: () => [],
  178. nextSteps: () => [],
  179. };
  180. const docs: Docs = {
  181. onboarding,
  182. replayOnboardingNpm: replayOnboarding,
  183. replayOnboardingJsLoader,
  184. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  185. };
  186. export default docs;