From 1b8c621cedc8fd88d09663ea2f4a30f9b2260d55 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 7 Jul 2022 14:27:45 +0200 Subject: [PATCH 1/2] ref(angular): Add transaction source to TracesService and instrumentAngularRouting --- packages/angular/src/tracing.ts | 2 ++ packages/angular/test/tracing.test.ts | 47 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 packages/angular/test/tracing.test.ts diff --git a/packages/angular/src/tracing.ts b/packages/angular/src/tracing.ts index 1a4352e6994a..73bf94c89f73 100644 --- a/packages/angular/src/tracing.ts +++ b/packages/angular/src/tracing.ts @@ -32,6 +32,7 @@ export function routingInstrumentation( customStartTransaction({ name: global.location.pathname, op: 'pageload', + metadata: { source: 'url' }, }); } } @@ -77,6 +78,7 @@ export class TraceService implements OnDestroy { activeTransaction = stashedStartTransaction({ name: strippedUrl, op: 'navigation', + metadata: { source: 'url' }, }); } diff --git a/packages/angular/test/tracing.test.ts b/packages/angular/test/tracing.test.ts new file mode 100644 index 000000000000..aa1bd750e0ab --- /dev/null +++ b/packages/angular/test/tracing.test.ts @@ -0,0 +1,47 @@ +import { instrumentAngularRouting, TraceService } from '../src/index'; + +import { NavigationStart, Router, RouterEvent } from '@angular/router'; +import { Subject } from 'rxjs'; + +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; + let routerEvents$: Subject = 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' }, + }); + }); + }); +}); From debd528dfc35830eec6a7e75666729ba3762fcf2 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 7 Jul 2022 18:50:19 +0200 Subject: [PATCH 2/2] fix linter --- packages/angular/test/tracing.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/angular/test/tracing.test.ts b/packages/angular/test/tracing.test.ts index aa1bd750e0ab..403c9b7c3cf1 100644 --- a/packages/angular/test/tracing.test.ts +++ b/packages/angular/test/tracing.test.ts @@ -1,8 +1,8 @@ -import { instrumentAngularRouting, TraceService } from '../src/index'; - 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', () => { @@ -18,7 +18,7 @@ describe('Angular Tracing', () => { describe('TraceService', () => { let traceService: TraceService; - let routerEvents$: Subject = new Subject(); + const routerEvents$: Subject = new Subject(); beforeAll(() => instrumentAngularRouting(startTransaction)); beforeEach(() => {