vue.tsx 11 KB

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