javascript.tsx 5.1 KB

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