vue.tsx 11 KB

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