vue.tsx 9.6 KB

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