vue.tsx 7.3 KB

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