|
| 1 | +import { createApp } from 'vue' |
| 2 | +import { createWebHistory } from 'vue-router' |
| 3 | +import { createRouter } from '@datadog/browser-rum-vue/vue-router-v4' |
| 4 | +import { datadogRum } from '@datadog/browser-rum' |
| 5 | +import { vuePlugin, addVueError } from '@datadog/browser-rum-vue' |
| 6 | +import App from './App.vue' |
| 7 | + |
| 8 | +declare global { |
| 9 | + interface Window { |
| 10 | + RUM_CONFIGURATION?: any |
| 11 | + RUM_CONTEXT?: any |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +const router = createRouter({ |
| 16 | + history: createWebHistory(), |
| 17 | + routes: [ |
| 18 | + { path: '/', component: () => import('./pages/HomePage.vue') }, |
| 19 | + { path: '/user/:id', component: () => import('./pages/UserPage.vue') }, |
| 20 | + { path: '/tracked', component: () => import('./pages/TrackedPage.vue') }, |
| 21 | + { path: '/error', component: () => import('./pages/ErrorPage.vue') }, |
| 22 | + ], |
| 23 | +}) |
| 24 | + |
| 25 | +const params = new URLSearchParams(window.location.search) |
| 26 | +const rumConfig = params.get('rum-config') |
| 27 | +const rumContext = params.get('rum-context') |
| 28 | + |
| 29 | +const config = rumConfig ? JSON.parse(rumConfig) : window.RUM_CONFIGURATION |
| 30 | +const context = rumContext ? JSON.parse(rumContext) : window.RUM_CONTEXT |
| 31 | + |
| 32 | +datadogRum.init({ ...config, plugins: [vuePlugin({ router: true })] }) |
| 33 | + |
| 34 | +if (context) { |
| 35 | + datadogRum.setGlobalContext(context) |
| 36 | +} |
| 37 | + |
| 38 | +const app = createApp(App) |
| 39 | +app.config.errorHandler = addVueError |
| 40 | +app.use(router).mount('#app') |
0 commit comments