vue.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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, reduce in production!
  57. `;
  58. export const steps = ({
  59. sentryInitContent,
  60. vueVersion,
  61. ...props
  62. }: StepProps): LayoutProps['steps'] => [
  63. {
  64. type: StepType.INSTALL,
  65. description: (
  66. <p>
  67. {tct(
  68. 'Add the Sentry SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn]:',
  69. {
  70. codeYarn: <code />,
  71. codeNpm: <code />,
  72. }
  73. )}
  74. </p>
  75. ),
  76. configurations: [
  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. },
  96. {
  97. type: StepType.CONFIGURE,
  98. description: t(
  99. "Initialize Sentry as early as possible in your application's lifecycle."
  100. ),
  101. configurations:
  102. vueVersion === VueVersion.V3
  103. ? [
  104. {
  105. language: 'javascript',
  106. code: `
  107. import { createApp } from "vue";
  108. import { createRouter } from "vue-router";
  109. import * as Sentry from "@sentry/vue";
  110. const app = createApp({
  111. // ...
  112. });
  113. const router = createRouter({
  114. // ...
  115. });
  116. Sentry.init({
  117. app,
  118. ${sentryInitContent}
  119. });
  120. app.use(router);
  121. app.mount("#app");
  122. `,
  123. },
  124. ]
  125. : [
  126. {
  127. language: 'javascript',
  128. code: `
  129. import Vue from "vue";
  130. import Router from "vue-router";
  131. import * as Sentry from "@sentry/vue";
  132. Vue.use(Router);
  133. const router = new Router({
  134. // ...
  135. });
  136. Sentry.init({
  137. Vue,
  138. ${sentryInitContent}
  139. });
  140. // ...
  141. new Vue({
  142. router,
  143. render: (h) => h(App),
  144. }).$mount("#app");
  145. `,
  146. },
  147. ],
  148. },
  149. getUploadSourceMapsStep({
  150. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/vue/sourcemaps/',
  151. ...props,
  152. }),
  153. {
  154. type: StepType.VERIFY,
  155. description: t(
  156. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  157. ),
  158. configurations: [
  159. {
  160. language: 'javascript',
  161. code: 'myUndefinedFunction();',
  162. },
  163. ],
  164. },
  165. ];
  166. export const nextSteps = [
  167. {
  168. id: 'source-maps',
  169. name: t('Source Maps'),
  170. description: t('Learn how to enable readable stack traces in your Sentry errors.'),
  171. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/sourcemaps/',
  172. },
  173. {
  174. id: 'vue-features',
  175. name: t('Vue Features'),
  176. description: t('Learn about our first class integration with the Vue framework.'),
  177. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/features/',
  178. },
  179. {
  180. id: 'performance-monitoring',
  181. name: t('Performance Monitoring'),
  182. description: t(
  183. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  184. ),
  185. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/performance/',
  186. },
  187. {
  188. id: 'session-replay',
  189. name: t('Session Replay'),
  190. description: t(
  191. '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.'
  192. ),
  193. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/session-replay/',
  194. },
  195. ];
  196. // Configuration End
  197. export function GettingStartedWithVue({
  198. dsn,
  199. activeProductSelection = [],
  200. organization,
  201. newOrg,
  202. platformKey,
  203. projectId,
  204. ...props
  205. }: ModuleProps) {
  206. const optionValues = useUrlPlatformOptions(platformOptions);
  207. const integrations: string[] = [];
  208. const otherConfigs: string[] = [];
  209. let nextStepDocs = [...nextSteps];
  210. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  211. integrations.push(performanceIntegration.trim());
  212. otherConfigs.push(performanceOtherConfig.trim());
  213. nextStepDocs = nextStepDocs.filter(
  214. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  215. );
  216. }
  217. if (activeProductSelection.includes(ProductSolution.SESSION_REPLAY)) {
  218. integrations.push(replayIntegration.trim());
  219. otherConfigs.push(replayOtherConfig.trim());
  220. nextStepDocs = nextStepDocs.filter(
  221. step => step.id !== ProductSolution.SESSION_REPLAY
  222. );
  223. }
  224. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  225. if (integrations.length > 0) {
  226. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  227. }
  228. if (otherConfigs.length > 0) {
  229. sentryInitContent = sentryInitContent.concat(otherConfigs);
  230. }
  231. return (
  232. <Layout
  233. steps={steps({
  234. sentryInitContent: sentryInitContent.join('\n'),
  235. vueVersion: optionValues.vueVersion as VueVersion,
  236. organization,
  237. newOrg,
  238. platformKey,
  239. projectId,
  240. })}
  241. nextSteps={nextStepDocs}
  242. newOrg={newOrg}
  243. platformKey={platformKey}
  244. platformOptions={platformOptions}
  245. {...props}
  246. />
  247. );
  248. }
  249. export default GettingStartedWithVue;