vue.tsx 7.3 KB

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