javascript.tsx 8.1 KB

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