javascript.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. new Sentry.BrowserTracing({
  25. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  26. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],
  27. }),`
  28. : ''
  29. }${
  30. params.isReplaySelected
  31. ? `
  32. new Sentry.Replay(${getReplayConfigOptions(params.replayOptions)}),`
  33. : ''
  34. }
  35. ],${
  36. params.isPerformanceSelected
  37. ? `
  38. // Performance Monitoring
  39. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  40. : ''
  41. }${
  42. params.isReplaySelected
  43. ? `
  44. // Session Replay
  45. 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.
  46. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  47. : ''
  48. }
  49. });
  50. `;
  51. const getVerifyJSSnippet = () => `
  52. myUndefinedFunction();`;
  53. const getInstallConfig = () => [
  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. const onboarding: OnboardingConfig = {
  73. install: () => [
  74. {
  75. type: StepType.INSTALL,
  76. description: t(
  77. 'Sentry captures data by using an SDK within your application’s runtime.'
  78. ),
  79. configurations: getInstallConfig(),
  80. },
  81. ],
  82. configure: (params: Params) => [
  83. {
  84. type: StepType.CONFIGURE,
  85. description: t(
  86. "Initialize Sentry as early as possible in your application's lifecycle."
  87. ),
  88. configurations: [
  89. {
  90. code: [
  91. {
  92. label: 'JavaScript',
  93. value: 'javascript',
  94. language: 'javascript',
  95. code: getSdkSetupSnippet(params),
  96. },
  97. ],
  98. },
  99. ],
  100. },
  101. getUploadSourceMapsStep({
  102. guideLink: 'https://docs.sentry.io/platforms/javascript/sourcemaps/',
  103. }),
  104. ],
  105. verify: () => [
  106. {
  107. type: StepType.VERIFY,
  108. description: t(
  109. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  110. ),
  111. configurations: [
  112. {
  113. code: [
  114. {
  115. label: 'Javascript',
  116. value: 'javascript',
  117. language: 'javascript',
  118. code: getVerifyJSSnippet(),
  119. },
  120. ],
  121. },
  122. ],
  123. },
  124. ],
  125. nextSteps: () => [
  126. {
  127. id: 'performance-monitoring',
  128. name: t('Performance Monitoring'),
  129. description: t(
  130. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  131. ),
  132. link: 'https://docs.sentry.io/platforms/javascript/performance/',
  133. },
  134. {
  135. id: 'session-replay',
  136. name: t('Session Replay'),
  137. description: t(
  138. '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.'
  139. ),
  140. link: 'https://docs.sentry.io/platforms/javascript/session-replay/',
  141. },
  142. ],
  143. };
  144. const replayOnboarding: OnboardingConfig = {
  145. install: () => [
  146. {
  147. type: StepType.INSTALL,
  148. description: tct(
  149. '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.',
  150. {
  151. code: <code />,
  152. }
  153. ),
  154. configurations: getInstallConfig(),
  155. },
  156. ],
  157. configure: (params: Params) => [
  158. {
  159. type: StepType.CONFIGURE,
  160. description: getReplayConfigureDescription({
  161. link: 'https://docs.sentry.io/platforms/javascript/session-replay/',
  162. }),
  163. configurations: [
  164. {
  165. code: [
  166. {
  167. label: 'JavaScript',
  168. value: 'javascript',
  169. language: 'javascript',
  170. code: getSdkSetupSnippet(params),
  171. },
  172. ],
  173. },
  174. ],
  175. additionalInfo: tracePropagationMessage,
  176. },
  177. ],
  178. verify: () => [],
  179. nextSteps: () => [],
  180. };
  181. const docs: Docs = {
  182. onboarding,
  183. replayOnboardingNpm: replayOnboarding,
  184. replayOnboardingJsLoader,
  185. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  186. };
  187. export default docs;