-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(angular): Add transaction source for Angular Router (#5382)
Add the transaction name source annotation to the Angular SDK. Since the Angular SDK currently does not parameterize URLs, we only assign `'url'` as the transaction name source. We're revisiting parameterization in Angular in a follow up PR. Additionally, add a two tests to cover this change (might be more relevant once we add parameterization).
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { NavigationStart, Router, RouterEvent } from '@angular/router'; | ||
import { Subject } from 'rxjs'; | ||
|
||
import { instrumentAngularRouting, TraceService } from '../src/index'; | ||
|
||
describe('Angular Tracing', () => { | ||
const startTransaction = jest.fn(); | ||
describe('instrumentAngularRouting', () => { | ||
it('should attach the transaction source on the pageload transaction', () => { | ||
instrumentAngularRouting(startTransaction); | ||
expect(startTransaction).toHaveBeenCalledWith({ | ||
name: '/', | ||
op: 'pageload', | ||
metadata: { source: 'url' }, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('TraceService', () => { | ||
let traceService: TraceService; | ||
const routerEvents$: Subject<RouterEvent> = new Subject(); | ||
|
||
beforeAll(() => instrumentAngularRouting(startTransaction)); | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
|
||
traceService = new TraceService({ | ||
events: routerEvents$, | ||
} as unknown as Router); | ||
}); | ||
|
||
afterEach(() => { | ||
traceService.ngOnDestroy(); | ||
}); | ||
|
||
it('attaches the transaction source on a navigation change', () => { | ||
routerEvents$.next(new NavigationStart(0, 'user/123/credentials')); | ||
|
||
expect(startTransaction).toHaveBeenCalledTimes(1); | ||
expect(startTransaction).toHaveBeenCalledWith({ | ||
name: 'user/123/credentials', | ||
op: 'navigation', | ||
metadata: { source: 'url' }, | ||
}); | ||
}); | ||
}); | ||
}); |