vue.tsx 7.9 KB

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