Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/angular/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function routingInstrumentation(
customStartTransaction({
name: global.location.pathname,
op: 'pageload',
metadata: { source: 'url' },
});
}
}
Expand Down Expand Up @@ -77,6 +78,7 @@ export class TraceService implements OnDestroy {
activeTransaction = stashedStartTransaction({
name: strippedUrl,
op: 'navigation',
metadata: { source: 'url' },
});
}

Expand Down
47 changes: 47 additions & 0 deletions packages/angular/test/tracing.test.ts
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' },
});
});
});
});