vue.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. PlatformOption,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  12. import {
  13. getCrashReportJavaScriptInstallStep,
  14. getCrashReportModalConfigDescription,
  15. getCrashReportModalIntroduction,
  16. getFeedbackConfigureDescription,
  17. getFeedbackSDKSetupSnippet,
  18. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  19. import {getJSMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  20. import {getProfilingDocumentHeaderConfigurationStep} from 'sentry/components/onboarding/gettingStartedDoc/utils/profilingOnboarding';
  21. import {
  22. getReplayConfigOptions,
  23. getReplayConfigureDescription,
  24. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  25. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  26. import {t, tct} from 'sentry/locale';
  27. export enum VueVersion {
  28. VUE3 = 'vue3',
  29. VUE2 = 'vue2',
  30. }
  31. type PlatformOptionKey = 'siblingOption';
  32. const platformOptions: Record<PlatformOptionKey, PlatformOption> = {
  33. siblingOption: {
  34. label: t('Vue Version'),
  35. items: [
  36. {
  37. label: t('Vue 3'),
  38. value: VueVersion.VUE3,
  39. },
  40. {
  41. label: t('Vue 2'),
  42. value: VueVersion.VUE2,
  43. },
  44. ],
  45. },
  46. };
  47. type PlatformOptions = typeof platformOptions;
  48. type Params = DocsParams<PlatformOptions>;
  49. const getSentryInitLayout = (params: Params, siblingOption: string): string => {
  50. return `Sentry.init({
  51. ${siblingOption === VueVersion.VUE2 ? 'Vue,' : 'app,'}
  52. dsn: "${params.dsn}",
  53. integrations: [${
  54. params.isPerformanceSelected
  55. ? `
  56. Sentry.browserTracingIntegration(),`
  57. : ''
  58. }${
  59. params.isReplaySelected
  60. ? `
  61. Sentry.replayIntegration(${getReplayConfigOptions(params.replayOptions)}),`
  62. : ''
  63. }${
  64. params.isProfilingSelected
  65. ? `
  66. Sentry.browserProfilingIntegration(),`
  67. : ''
  68. }
  69. ],${
  70. params.isPerformanceSelected
  71. ? `
  72. // Performance Monitoring
  73. tracesSampleRate: 1.0, // Capture 100% of the transactions
  74. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  75. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],`
  76. : ''
  77. }${
  78. params.isReplaySelected
  79. ? `
  80. // Session Replay
  81. 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.
  82. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  83. : ''
  84. }${
  85. params.isProfilingSelected
  86. ? `
  87. // Profiling
  88. profilesSampleRate: 1.0, // Profile 100% of the transactions. This value is relative to tracesSampleRate`
  89. : ''
  90. }
  91. });`;
  92. };
  93. const getInstallConfig = () => [
  94. {
  95. language: 'bash',
  96. code: [
  97. {
  98. label: 'npm',
  99. value: 'npm',
  100. language: 'bash',
  101. code: `npm install --save @sentry/vue`,
  102. },
  103. {
  104. label: 'yarn',
  105. value: 'yarn',
  106. language: 'bash',
  107. code: `yarn add @sentry/vue`,
  108. },
  109. ],
  110. },
  111. ];
  112. const getNextStep = (
  113. params: Params
  114. ): {
  115. description: string;
  116. id: string;
  117. link: string;
  118. name: string;
  119. }[] => {
  120. let nextStepDocs = [...nextSteps];
  121. if (params.isPerformanceSelected) {
  122. nextStepDocs = nextStepDocs.filter(
  123. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  124. );
  125. }
  126. if (params.isReplaySelected) {
  127. nextStepDocs = nextStepDocs.filter(
  128. step => step.id !== ProductSolution.SESSION_REPLAY
  129. );
  130. }
  131. return nextStepDocs;
  132. };
  133. const onboarding: OnboardingConfig<PlatformOptions> = {
  134. install: () => [
  135. {
  136. type: StepType.INSTALL,
  137. description: (
  138. <p>
  139. {tct(
  140. `Install the Sentry Vue SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn], alongside the Sentry Vue SDK:`,
  141. {
  142. codeYarn: <code />,
  143. codeNpm: <code />,
  144. }
  145. )}
  146. </p>
  147. ),
  148. configurations: getInstallConfig(),
  149. },
  150. ],
  151. configure: params => [
  152. {
  153. type: StepType.CONFIGURE,
  154. description: t(
  155. "Initialize Sentry as early as possible in your application's lifecycle."
  156. ),
  157. configurations: getSetupConfiguration(params),
  158. },
  159. ...(params.isProfilingSelected
  160. ? [getProfilingDocumentHeaderConfigurationStep()]
  161. : []),
  162. getUploadSourceMapsStep({
  163. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/vue/sourcemaps/',
  164. ...params,
  165. }),
  166. ],
  167. verify: () => [
  168. {
  169. type: StepType.VERIFY,
  170. description: t(
  171. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  172. ),
  173. configurations: [
  174. {
  175. language: 'javascript',
  176. code: `myUndefinedFunction();`,
  177. },
  178. ],
  179. },
  180. ],
  181. nextSteps: params => getNextStep(params),
  182. };
  183. export const nextSteps = [
  184. {
  185. id: 'vue-features',
  186. name: t('Vue Features'),
  187. description: t('Learn about our first class integration with the Vue framework.'),
  188. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/features/',
  189. },
  190. {
  191. id: 'performance-monitoring',
  192. name: t('Performance Monitoring'),
  193. description: t(
  194. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  195. ),
  196. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/tracing/',
  197. },
  198. {
  199. id: 'session-replay',
  200. name: t('Session Replay'),
  201. description: t(
  202. '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.'
  203. ),
  204. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/session-replay/',
  205. },
  206. ];
  207. function getSiblingImportsSetupConfiguration(siblingOption: string): string {
  208. switch (siblingOption) {
  209. case VueVersion.VUE3:
  210. return `import {createApp} from "vue";
  211. import {createRouter} from "vue-router";`;
  212. case VueVersion.VUE2:
  213. default:
  214. return `import Vue from "vue";
  215. import Router from "vue-router";`;
  216. }
  217. }
  218. function getSiblingSuffix(siblingOption: string): string {
  219. switch (siblingOption) {
  220. case VueVersion.VUE3:
  221. return `app.use(router);
  222. app.mount("#app");`;
  223. case VueVersion.VUE2:
  224. default:
  225. return `new Vue({
  226. router,
  227. render: (h) => h(App),
  228. }).$mount("#app");`;
  229. }
  230. }
  231. function getVueConstSetup(siblingOption: string): string {
  232. switch (siblingOption) {
  233. case VueVersion.VUE3:
  234. return `
  235. const app = createApp({
  236. // ...
  237. });
  238. const router = createRouter({
  239. // ...
  240. });
  241. `;
  242. case VueVersion.VUE2:
  243. return `
  244. Vue.use(Router);
  245. const router = new Router({
  246. // ...
  247. });
  248. `;
  249. default:
  250. return '';
  251. }
  252. }
  253. function getSetupConfiguration(params: Params) {
  254. const siblingOption = params.platformOptions.siblingOption;
  255. const sentryInitLayout = getSentryInitLayout(params, siblingOption);
  256. const configuration = [
  257. {
  258. language: 'javascript',
  259. code: `${getSiblingImportsSetupConfiguration(siblingOption)}
  260. import * as Sentry from "@sentry/vue";
  261. ${getVueConstSetup(siblingOption)}
  262. ${sentryInitLayout}
  263. ${getSiblingSuffix(siblingOption)}`,
  264. },
  265. ];
  266. return configuration;
  267. }
  268. const replayOnboarding: OnboardingConfig<PlatformOptions> = {
  269. install: () => [
  270. {
  271. type: StepType.INSTALL,
  272. description: tct(
  273. 'You need a minimum version 7.27.0 of [code:@sentry/vue] in order to use Session Replay. You do not need to install any additional packages.',
  274. {
  275. code: <code />,
  276. }
  277. ),
  278. configurations: getInstallConfig(),
  279. },
  280. ],
  281. configure: params => [
  282. {
  283. type: StepType.CONFIGURE,
  284. description: getReplayConfigureDescription({
  285. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/session-replay/',
  286. }),
  287. configurations: getSetupConfiguration(params),
  288. additionalInfo: <TracePropagationMessage />,
  289. },
  290. ],
  291. verify: () => [],
  292. nextSteps: () => [],
  293. };
  294. const feedbackOnboarding: OnboardingConfig<PlatformOptions> = {
  295. install: () => [
  296. {
  297. type: StepType.INSTALL,
  298. description: tct(
  299. 'For the User Feedback integration to work, you must have the Sentry browser SDK package, or an equivalent framework SDK (e.g. [code:@sentry/vue]) installed, minimum version 7.85.0.',
  300. {
  301. code: <code />,
  302. }
  303. ),
  304. configurations: getInstallConfig(),
  305. },
  306. ],
  307. configure: (params: Params) => [
  308. {
  309. type: StepType.CONFIGURE,
  310. description: getFeedbackConfigureDescription({
  311. linkConfig:
  312. 'https://docs.sentry.io/platforms/javascript/guides/vue/user-feedback/configuration/',
  313. linkButton:
  314. 'https://docs.sentry.io/platforms/javascript/guides/vue/user-feedback/configuration/#bring-your-own-button',
  315. }),
  316. configurations: [
  317. {
  318. code: [
  319. {
  320. label: 'JavaScript',
  321. value: 'javascript',
  322. language: 'javascript',
  323. code: getFeedbackSDKSetupSnippet({
  324. importStatement: `import * as Sentry from "@sentry/vue";`,
  325. dsn: params.dsn,
  326. feedbackOptions: params.feedbackOptions,
  327. }),
  328. },
  329. ],
  330. },
  331. ],
  332. additionalInfo: crashReportCallout({
  333. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/user-feedback/#crash-report-modal',
  334. }),
  335. },
  336. ],
  337. verify: () => [],
  338. nextSteps: () => [],
  339. };
  340. const crashReportOnboarding: OnboardingConfig<PlatformOptions> = {
  341. introduction: () => getCrashReportModalIntroduction(),
  342. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  343. configure: () => [
  344. {
  345. type: StepType.CONFIGURE,
  346. description: getCrashReportModalConfigDescription({
  347. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/user-feedback/configuration/#crash-report-modal',
  348. }),
  349. additionalInfo: widgetCallout({
  350. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/user-feedback/#user-feedback-widget',
  351. }),
  352. },
  353. ],
  354. verify: () => [],
  355. nextSteps: () => [],
  356. };
  357. const docs: Docs<PlatformOptions> = {
  358. onboarding,
  359. platformOptions,
  360. feedbackOnboardingNpm: feedbackOnboarding,
  361. replayOnboardingNpm: replayOnboarding,
  362. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  363. crashReportOnboarding,
  364. };
  365. export default docs;