vue.tsx 6.2 KB

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