javascript.tsx 8.7 KB

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