vue.tsx 6.2 KB

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