javascript.tsx 8.6 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 {getProfilingDocumentHeaderConfigurationStep} from 'sentry/components/onboarding/gettingStartedDoc/utils/profilingOnboarding';
  20. import {
  21. getReplayConfigOptions,
  22. getReplayConfigureDescription,
  23. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  24. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  25. import {t, tct} from 'sentry/locale';
  26. type Params = DocsParams;
  27. const getSdkSetupSnippet = (params: Params) => `
  28. import * as Sentry from "@sentry/browser";
  29. Sentry.init({
  30. dsn: "${params.dsn}",
  31. integrations: [${
  32. params.isPerformanceSelected
  33. ? `
  34. Sentry.browserTracingIntegration(),`
  35. : ''
  36. }${
  37. params.isProfilingSelected
  38. ? `
  39. Sentry.browserProfilingIntegration(),`
  40. : ''
  41. }${
  42. params.isFeedbackSelected
  43. ? `
  44. Sentry.feedbackIntegration({
  45. // Additional SDK configuration goes in here, for example:
  46. colorScheme: "system",
  47. ${getFeedbackConfigOptions(params.feedbackOptions)}}),`
  48. : ''
  49. }${
  50. params.isReplaySelected
  51. ? `
  52. Sentry.replayIntegration(${getReplayConfigOptions(params.replayOptions)}),`
  53. : ''
  54. }
  55. ],${
  56. params.isPerformanceSelected
  57. ? `
  58. // Performance Monitoring
  59. tracesSampleRate: 1.0, // Capture 100% of the transactions
  60. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  61. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],`
  62. : ''
  63. }${
  64. params.isReplaySelected
  65. ? `
  66. // Session Replay
  67. 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.
  68. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  69. : ''
  70. }${
  71. params.isProfilingSelected
  72. ? `
  73. // Profiling
  74. profilesSampleRate: 1.0, // Profile 100% of the transactions. This value is relative to tracesSampleRate`
  75. : ''
  76. }
  77. });
  78. `;
  79. const getVerifyJSSnippet = () => `
  80. myUndefinedFunction();`;
  81. const getInstallConfig = () => [
  82. {
  83. language: 'bash',
  84. code: [
  85. {
  86. label: 'npm',
  87. value: 'npm',
  88. language: 'bash',
  89. code: 'npm install --save @sentry/browser',
  90. },
  91. {
  92. label: 'yarn',
  93. value: 'yarn',
  94. language: 'bash',
  95. code: 'yarn add @sentry/browser',
  96. },
  97. ],
  98. },
  99. ];
  100. const onboarding: OnboardingConfig = {
  101. install: () => [
  102. {
  103. type: StepType.INSTALL,
  104. description: t(
  105. 'Sentry captures data by using an SDK within your application’s runtime.'
  106. ),
  107. configurations: getInstallConfig(),
  108. },
  109. ],
  110. configure: (params: Params) => [
  111. {
  112. type: StepType.CONFIGURE,
  113. description: t(
  114. "Initialize Sentry as early as possible in your application's lifecycle."
  115. ),
  116. configurations: [
  117. {
  118. code: [
  119. {
  120. label: 'JavaScript',
  121. value: 'javascript',
  122. language: 'javascript',
  123. code: getSdkSetupSnippet(params),
  124. },
  125. ],
  126. },
  127. ],
  128. },
  129. ...(params.isProfilingSelected
  130. ? [getProfilingDocumentHeaderConfigurationStep()]
  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;