vue.tsx 7.9 KB

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