Skip to content

Commit 04a0bef

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 3368fb0 commit 04a0bef

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
@@ -31,11 +31,13 @@ import {
3131
import { FUNCTION, ROUTER } from '@sentry/conventions/op';
3232
import type { Integration, Span } from '@sentry/core';
3333
import {
34+
createCachedRouteProvider,
3435
debug,
3536
hasSpanStreamingEnabled,
3637
NAVIGATION_SPAN_NAME_FALLBACK,
3738
parseStringToURLObject,
3839
ROUTER_SPAN_NAME_FALLBACK,
40+
setRouteProvider,
3941
stripUrlQueryAndFragment,
4042
timestampInSeconds,
4143
filterCollectedUrl,
@@ -49,6 +51,11 @@ import { runOutsideAngular } from './zone';
4951

5052
let instrumentationInitialized: boolean;
5153

54+
// The parameterized route only exists on Angular's `ResolveEnd` event, resolved from the router
55+
// state snapshot, so there is no matcher the integration could call. `TraceService` records each
56+
// route as it resolves and the provider answers from that.
57+
const ROUTE_PROVIDER = createCachedRouteProvider();
58+
5259
/**
5360
* A custom browser tracing integration for Angular.
5461
*
@@ -63,10 +70,18 @@ export function browserTracingIntegration(
6370
instrumentationInitialized = true;
6471
}
6572

66-
return originalBrowserTracingIntegration({
73+
const integration = originalBrowserTracingIntegration({
6774
...options,
6875
instrumentNavigation: false,
6976
});
77+
78+
return {
79+
...integration,
80+
setup(client) {
81+
setRouteProvider(ROUTE_PROVIDER, client);
82+
integration.setup?.(client);
83+
},
84+
};
7085
}
7186

7287
/**
@@ -182,6 +197,7 @@ export class TraceService implements OnDestroy {
182197
);
183198

184199
if (route) {
200+
ROUTE_PROVIDER.record(stripUrlQueryAndFragment(event.urlAfterRedirects), route);
185201
getCurrentScope().setTransactionName(route);
186202
}
187203

0 commit comments

Comments
 (0)