vue.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t} from 'sentry/locale';
  7. // Configuration Start
  8. const replayIntegration = `
  9. new Sentry.Replay(),
  10. `;
  11. const replayOtherConfig = `
  12. // Session Replay
  13. 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.
  14. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
  15. `;
  16. const performanceIntegration = `
  17. new Sentry.BrowserTracing({
  18. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  19. tracePropagationTargets: ["localhost", "https:yourserver.io/api/"],
  20. routingInstrumentation: Sentry.vueRouterInstrumentation(router),
  21. }),
  22. `;
  23. const performanceOtherConfig = `
  24. // Performance Monitoring
  25. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!
  26. `;
  27. export const steps = ({
  28. sentryInitContent,
  29. }: {
  30. sentryInitContent?: string;
  31. } = {}): LayoutProps['steps'] => [
  32. {
  33. type: StepType.INSTALL,
  34. description: t(
  35. 'Sentry captures data by using an SDK within your application’s runtime.'
  36. ),
  37. configurations: [
  38. {
  39. language: 'bash',
  40. code: `
  41. # Using yarn
  42. yarn add @sentry/vue
  43. # Using npm
  44. npm install --save @sentry/vue
  45. `,
  46. },
  47. ],
  48. },
  49. {
  50. type: StepType.CONFIGURE,
  51. description: t(
  52. "Initialize Sentry as early as possible in your application's lifecycle."
  53. ),
  54. configurations: [
  55. {
  56. description: <h5>V2</h5>,
  57. language: 'javascript',
  58. code: `
  59. import { createApp } from "vue";
  60. import { createRouter } from "vue-router";
  61. import * as Sentry from "@sentry/vue";
  62. const app = createApp({
  63. // ...
  64. });
  65. const router = createRouter({
  66. // ...
  67. });
  68. Sentry.init({
  69. app,
  70. ${sentryInitContent}
  71. });
  72. app.use(router);
  73. app.mount("#app");
  74. `,
  75. },
  76. {
  77. description: <h5>V3</h5>,
  78. language: 'javascript',
  79. code: `
  80. import Vue from "vue";
  81. import Router from "vue-router";
  82. import * as Sentry from "@sentry/vue";
  83. Vue.use(Router);
  84. const router = new Router({
  85. // ...
  86. });
  87. Sentry.init({
  88. Vue,
  89. ${sentryInitContent}
  90. });
  91. // ...
  92. new Vue({
  93. router,
  94. render: (h) => h(App),
  95. }).$mount("#app");
  96. `,
  97. },
  98. ],
  99. },
  100. getUploadSourceMapsStep(
  101. 'https://docs.sentry.io/platforms/javascript/guides/vue/sourcemaps/'
  102. ),
  103. {
  104. type: StepType.VERIFY,
  105. description: t(
  106. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  107. ),
  108. configurations: [
  109. {
  110. language: 'javascript',
  111. code: 'myUndefinedFunction();',
  112. },
  113. ],
  114. },
  115. ];
  116. export const nextSteps = [
  117. {
  118. id: 'source-maps',
  119. name: t('Source Maps'),
  120. description: t('Learn how to enable readable stack traces in your Sentry errors.'),
  121. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/sourcemaps/',
  122. },
  123. {
  124. id: 'vue-features',
  125. name: t('Vue Features'),
  126. description: t('Learn about our first class integration with the Vue framework.'),
  127. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/features/',
  128. },
  129. {
  130. id: 'performance-monitoring',
  131. name: t('Performance Monitoring'),
  132. description: t(
  133. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  134. ),
  135. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/performance/',
  136. },
  137. {
  138. id: 'session-replay',
  139. name: t('Session Replay'),
  140. description: t(
  141. '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.'
  142. ),
  143. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/session-replay/',
  144. },
  145. ];
  146. // Configuration End
  147. export function GettingStartedWithVue({
  148. dsn,
  149. activeProductSelection = [],
  150. ...props
  151. }: ModuleProps) {
  152. const integrations: string[] = [];
  153. const otherConfigs: string[] = [];
  154. let nextStepDocs = [...nextSteps];
  155. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  156. integrations.push(performanceIntegration.trim());
  157. otherConfigs.push(performanceOtherConfig.trim());
  158. nextStepDocs = nextStepDocs.filter(
  159. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  160. );
  161. }
  162. if (activeProductSelection.includes(ProductSolution.SESSION_REPLAY)) {
  163. integrations.push(replayIntegration.trim());
  164. otherConfigs.push(replayOtherConfig.trim());
  165. nextStepDocs = nextStepDocs.filter(
  166. step => step.id !== ProductSolution.SESSION_REPLAY
  167. );
  168. }
  169. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  170. if (integrations.length > 0) {
  171. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  172. }
  173. if (otherConfigs.length > 0) {
  174. sentryInitContent = sentryInitContent.concat(otherConfigs);
  175. }
  176. return (
  177. <Layout
  178. steps={steps({
  179. sentryInitContent: sentryInitContent.join('\n'),
  180. })}
  181. nextSteps={nextStepDocs}
  182. {...props}
  183. />
  184. );
  185. }
  186. export default GettingStartedWithVue;