javascript.tsx 9.0 KB

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