javascript.tsx 6.8 KB

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