vue.tsx 7.0 KB

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