vue.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. import {Fragment} from 'react';
  2. import crashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/crashReportCallout';
  3. import widgetCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/widgetCallout';
  4. import TracePropagationMessage from 'sentry/components/onboarding/gettingStartedDoc/replay/tracePropagationMessage';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import type {
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. PlatformOption,
  11. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  12. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  13. import {
  14. getCrashReportJavaScriptInstallStep,
  15. getCrashReportModalConfigDescription,
  16. getCrashReportModalIntroduction,
  17. getFeedbackConfigureDescription,
  18. getFeedbackSDKSetupSnippet,
  19. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  20. import {getJSMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  21. import {
  22. getProfilingDocumentHeaderConfigurationStep,
  23. MaybeBrowserProfilingBetaWarning,
  24. } from 'sentry/components/onboarding/gettingStartedDoc/utils/profilingOnboarding';
  25. import {
  26. getReplayConfigOptions,
  27. getReplayConfigureDescription,
  28. getReplayVerifyStep,
  29. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  30. import {featureFlagOnboarding} from 'sentry/gettingStartedDocs/javascript/javascript';
  31. import {t, tct} from 'sentry/locale';
  32. export enum VueVersion {
  33. VUE3 = 'vue3',
  34. VUE2 = 'vue2',
  35. }
  36. type PlatformOptionKey = 'siblingOption';
  37. const platformOptions: Record<PlatformOptionKey, PlatformOption> = {
  38. siblingOption: {
  39. label: t('Vue Version'),
  40. items: [
  41. {
  42. label: t('Vue 3'),
  43. value: VueVersion.VUE3,
  44. },
  45. {
  46. label: t('Vue 2'),
  47. value: VueVersion.VUE2,
  48. },
  49. ],
  50. },
  51. };
  52. type PlatformOptions = typeof platformOptions;
  53. type Params = DocsParams<PlatformOptions>;
  54. const getSentryInitLayout = (params: Params, siblingOption: string): string => {
  55. return `Sentry.init({
  56. ${siblingOption === VueVersion.VUE2 ? 'Vue,' : 'app,'}
  57. dsn: "${params.dsn.public}",
  58. integrations: [${
  59. params.isPerformanceSelected
  60. ? `
  61. Sentry.browserTracingIntegration({ router }),`
  62. : ''
  63. }${
  64. params.isReplaySelected
  65. ? `
  66. Sentry.replayIntegration(${getReplayConfigOptions(params.replayOptions)}),`
  67. : ''
  68. }${
  69. params.isProfilingSelected
  70. ? `
  71. Sentry.browserProfilingIntegration(),`
  72. : ''
  73. }
  74. ],${
  75. params.isPerformanceSelected
  76. ? `
  77. // Tracing
  78. tracesSampleRate: 1.0, // Capture 100% of the transactions
  79. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  80. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],`
  81. : ''
  82. }${
  83. params.isReplaySelected
  84. ? `
  85. // Session Replay
  86. 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.
  87. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  88. : ''
  89. }${
  90. params.isProfilingSelected
  91. ? `
  92. // Profiling
  93. profilesSampleRate: 1.0, // Profile 100% of the transactions. This value is relative to tracesSampleRate`
  94. : ''
  95. }
  96. });`;
  97. };
  98. const getInstallConfig = () => [
  99. {
  100. language: 'bash',
  101. code: [
  102. {
  103. label: 'npm',
  104. value: 'npm',
  105. language: 'bash',
  106. code: `npm install --save @sentry/vue`,
  107. },
  108. {
  109. label: 'yarn',
  110. value: 'yarn',
  111. language: 'bash',
  112. code: `yarn add @sentry/vue`,
  113. },
  114. ],
  115. },
  116. ];
  117. const onboarding: OnboardingConfig<PlatformOptions> = {
  118. introduction: params => (
  119. <Fragment>
  120. <MaybeBrowserProfilingBetaWarning {...params} />
  121. <p>
  122. {tct('In this quick guide you’ll use [strong:npm] or [strong:yarn] to set up:', {
  123. strong: <strong />,
  124. })}
  125. </p>
  126. </Fragment>
  127. ),
  128. install: () => [
  129. {
  130. type: StepType.INSTALL,
  131. description: (
  132. <p>
  133. {tct(
  134. `Install the Sentry Vue SDK as a dependency using [code:npm] or [code:yarn], alongside the Sentry Vue SDK:`,
  135. {
  136. code: <code />,
  137. }
  138. )}
  139. </p>
  140. ),
  141. configurations: getInstallConfig(),
  142. },
  143. ],
  144. configure: params => [
  145. {
  146. type: StepType.CONFIGURE,
  147. description: tct(
  148. "Initialize Sentry as early as possible in your application's lifecycle, usually your Vue app's entry point ([code:main.ts/js]).",
  149. {code: <code />}
  150. ),
  151. configurations: getSetupConfiguration(params),
  152. },
  153. getUploadSourceMapsStep({
  154. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/vue/sourcemaps/',
  155. ...params,
  156. }),
  157. ],
  158. verify: () => [
  159. {
  160. type: StepType.VERIFY,
  161. description: t(
  162. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  163. ),
  164. configurations: [
  165. {
  166. language: 'javascript',
  167. code: `myUndefinedFunction();`,
  168. },
  169. ],
  170. },
  171. ],
  172. nextSteps: () => [
  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. };
  181. function getSiblingImportsSetupConfiguration(siblingOption: string): string {
  182. switch (siblingOption) {
  183. case VueVersion.VUE3:
  184. return `import {createApp} from "vue";
  185. import {createRouter} from "vue-router";
  186. import router from "./router";
  187. `;
  188. case VueVersion.VUE2:
  189. default:
  190. return `import Vue from "vue";
  191. import Router from "vue-router";`;
  192. }
  193. }
  194. function getSiblingSuffix(siblingOption: string): string {
  195. switch (siblingOption) {
  196. case VueVersion.VUE3:
  197. return `app.use(router);
  198. app.mount("#app");`;
  199. case VueVersion.VUE2:
  200. default:
  201. return `new Vue({
  202. router,
  203. render: (h) => h(App),
  204. }).$mount("#app");`;
  205. }
  206. }
  207. function getVueConstSetup(siblingOption: string): string {
  208. switch (siblingOption) {
  209. case VueVersion.VUE3:
  210. return `
  211. const app = createApp({
  212. // ...
  213. });
  214. `;
  215. case VueVersion.VUE2:
  216. return `
  217. Vue.use(Router);
  218. const router = new Router({
  219. // ...
  220. });
  221. `;
  222. default:
  223. return '';
  224. }
  225. }
  226. function getSetupConfiguration(params: Params) {
  227. const siblingOption = params.platformOptions.siblingOption;
  228. const sentryInitLayout = getSentryInitLayout(params, siblingOption);
  229. const configuration = [
  230. {
  231. language: 'javascript',
  232. code: `${getSiblingImportsSetupConfiguration(siblingOption)}
  233. import * as Sentry from "@sentry/vue";
  234. ${getVueConstSetup(siblingOption)}
  235. ${sentryInitLayout}
  236. ${getSiblingSuffix(siblingOption)}`,
  237. },
  238. ...(params.isProfilingSelected
  239. ? [getProfilingDocumentHeaderConfigurationStep()]
  240. : []),
  241. ];
  242. return configuration;
  243. }
  244. const replayOnboarding: OnboardingConfig<PlatformOptions> = {
  245. install: () => [
  246. {
  247. type: StepType.INSTALL,
  248. description: tct(
  249. 'You need a minimum version 7.27.0 of [code:@sentry/vue] in order to use Session Replay. You do not need to install any additional packages.',
  250. {
  251. code: <code />,
  252. }
  253. ),
  254. configurations: getInstallConfig(),
  255. },
  256. ],
  257. configure: params => [
  258. {
  259. type: StepType.CONFIGURE,
  260. description: getReplayConfigureDescription({
  261. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/session-replay/',
  262. }),
  263. configurations: getSetupConfiguration(params),
  264. additionalInfo: <TracePropagationMessage />,
  265. },
  266. ],
  267. verify: getReplayVerifyStep(),
  268. nextSteps: () => [],
  269. };
  270. const feedbackOnboarding: OnboardingConfig<PlatformOptions> = {
  271. install: () => [
  272. {
  273. type: StepType.INSTALL,
  274. description: tct(
  275. 'For the User Feedback integration to work, you must have the Sentry browser SDK package, or an equivalent framework SDK (e.g. [code:@sentry/vue]) installed, minimum version 7.85.0.',
  276. {
  277. code: <code />,
  278. }
  279. ),
  280. configurations: getInstallConfig(),
  281. },
  282. ],
  283. configure: (params: Params) => [
  284. {
  285. type: StepType.CONFIGURE,
  286. description: getFeedbackConfigureDescription({
  287. linkConfig:
  288. 'https://docs.sentry.io/platforms/javascript/guides/vue/user-feedback/configuration/',
  289. linkButton:
  290. 'https://docs.sentry.io/platforms/javascript/guides/vue/user-feedback/configuration/#bring-your-own-button',
  291. }),
  292. configurations: [
  293. {
  294. code: [
  295. {
  296. label: 'JavaScript',
  297. value: 'javascript',
  298. language: 'javascript',
  299. code: getFeedbackSDKSetupSnippet({
  300. importStatement: `import * as Sentry from "@sentry/vue";`,
  301. dsn: params.dsn.public,
  302. feedbackOptions: params.feedbackOptions,
  303. }),
  304. },
  305. ],
  306. },
  307. ],
  308. additionalInfo: crashReportCallout({
  309. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/user-feedback/#crash-report-modal',
  310. }),
  311. },
  312. ],
  313. verify: () => [],
  314. nextSteps: () => [],
  315. };
  316. const crashReportOnboarding: OnboardingConfig<PlatformOptions> = {
  317. introduction: () => getCrashReportModalIntroduction(),
  318. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  319. configure: () => [
  320. {
  321. type: StepType.CONFIGURE,
  322. description: getCrashReportModalConfigDescription({
  323. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/user-feedback/configuration/#crash-report-modal',
  324. }),
  325. additionalInfo: widgetCallout({
  326. link: 'https://docs.sentry.io/platforms/javascript/guides/vue/user-feedback/#user-feedback-widget',
  327. }),
  328. },
  329. ],
  330. verify: () => [],
  331. nextSteps: () => [],
  332. };
  333. const profilingOnboarding: OnboardingConfig<PlatformOptions> = {
  334. ...onboarding,
  335. introduction: params => <MaybeBrowserProfilingBetaWarning {...params} />,
  336. };
  337. const docs: Docs<PlatformOptions> = {
  338. onboarding,
  339. platformOptions,
  340. feedbackOnboardingNpm: feedbackOnboarding,
  341. replayOnboarding,
  342. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  343. crashReportOnboarding,
  344. profilingOnboarding,
  345. featureFlagOnboarding: featureFlagOnboarding,
  346. };
  347. export default docs;