import { captureException } from '@sentry/browser' ; import { Transaction , TransactionContext } from '@sentry/types' ; export type VueRouterInstrumentation = < T extends Transaction > ( startTransaction : ( context : TransactionContext ) => T | undefined , startTransactionOnPageLoad ? : boolean , startTransactionOnLocationChange ? : boolean ) => void ; type Route = { params : any ; query : any ; name ? : any ; path : any ; matched : any [ ] ; } ; interface VueRouter { onError : ( fn : ( err : Error ) => void ) => void ; beforeEach : ( fn : ( to : Route , from : Route , next : ( ) => void ) => void ) => void ; } param router export function vueRouterInstrumentation ( router ) { return ( startTransaction , startTransactionOnPageLoad = true , startTransactionOnLocationChange = true ) => { router . onError ( error => captureException ( error ) ) ; router . beforeEach ( ( to , from , next ) => { const isPageLoadNavigation = from . name == null && from . matched . length === 0 ; const tags = { 'routing.instrumentation' : 'vue-router' , } ; const data = { params : to . params , query : to . query , } ; if ( startTransactionOnPageLoad && isPageLoadNavigation ) { startTransaction ( { name : to . name || to . path , op : 'pageload' , tags , data , } ) ; } if ( startTransactionOnLocationChange && ! isPageLoadNavigation ) { startTransaction ( { name : to . name || ( to . matched [ 0 ] && to . matched [ 0 ] . path ) || to . path , op : 'navigation' , tags , data , } ) ; } next ( ) ; } ) ; } ; }