in packages/rum-angular/src/apm.service.ts [61:111]
observe() {
let transaction
this.router.events.subscribe(event => {
const eventName = event.toString()
if (eventName.indexOf('NavigationStart') >= 0) {
const name = (event as NavigationStart).url
transaction = this.apm.startTransaction(name, 'route-change', {
managed: true,
canReuse: true
})
} else if (eventName.indexOf('NavigationError') >= 0) {
transaction && transaction.detectFinish()
} else if (eventName.indexOf('NavigationEnd') >= 0) {
if (!transaction) {
return
}
/**
* The below logic must be placed in NavigationEnd since
* the we depend on the current route state to get the path
*
* Even If there are any redirects, the router state path
* will be matched with the correct url on navigation end
*
* Traverse the activated route tree to figure out the nested
* route path
*/
const route = this.router.routerState.root.firstChild
if (route) {
let child = route
let path = '/' + child.routeConfig.path
while (child) {
child = child.firstChild
if (child && child.routeConfig) {
const currentPath = child.routeConfig.path
/**
* Ignore empty path's in the route config
*/
if (currentPath) {
path += '/' + currentPath
}
}
}
transaction.name = path
}
afterFrame(() => transaction.detectFinish())
}
})
}