Skip to content

Commit d8d190e

Browse files
committed
feat(angular): Register a route provider backed by resolved routes
The parameterized route only exists on Angular's `ResolveEnd` event, resolved from the router state snapshot, so there is no matcher to call. `TraceService` already derives it to rename the span, so it records it on the way through.
1 parent d1b5a9f commit d8d190e

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

packages/angular/src/tracing.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import { CODE_FUNCTION_NAME, SENTRY_OP, URL_FULL, URL_PATH, URL_TEMPLATE } from
2525
import { FUNCTION } from '@sentry/conventions/op';
2626
import type { Integration, Span } from '@sentry/core';
2727
import {
28+
createCachedRouteProvider,
2829
debug,
2930
parseStringToURLObject,
31+
setRouteProvider,
3032
stripUrlQueryAndFragment,
3133
timestampInSeconds,
3234
filterCollectedUrl,
@@ -40,6 +42,11 @@ import { runOutsideAngular } from './zone';
4042

4143
let instrumentationInitialized: boolean;
4244

45+
// The parameterized route only exists on Angular's `ResolveEnd` event, resolved from the router
46+
// state snapshot, so there is no matcher the integration could call. `TraceService` records each
47+
// route as it resolves and the provider answers from that.
48+
const ROUTE_PROVIDER = createCachedRouteProvider();
49+
4350
/**
4451
* A custom browser tracing integration for Angular.
4552
*
@@ -54,10 +61,18 @@ export function browserTracingIntegration(
5461
instrumentationInitialized = true;
5562
}
5663

57-
return originalBrowserTracingIntegration({
64+
const integration = originalBrowserTracingIntegration({
5865
...options,
5966
instrumentNavigation: false,
6067
});
68+
69+
return {
70+
...integration,
71+
setup(client) {
72+
setRouteProvider(ROUTE_PROVIDER, client);
73+
integration.setup?.(client);
74+
},
75+
};
6176
}
6277

6378
/**
@@ -171,6 +186,7 @@ export class TraceService implements OnDestroy {
171186
);
172187

173188
if (route) {
189+
ROUTE_PROVIDER.record(stripUrlQueryAndFragment(event.urlAfterRedirects), route);
174190
getCurrentScope().setTransactionName(route);
175191
}
176192

0 commit comments

Comments
 (0)