Skip to content

Commit f89cc69

Browse files
committed
fix: Fix router middleware detection in Express instrumentation
So it's not immune to function name changes which maybe introduced in bundling or other tools instrumentation process
1 parent e88c764 commit f89cc69

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

node/packages/sdk/lib/instrumentation/express/instrument-layer-prototype.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports.install = (layerPrototype) => {
4040
}
4141
expressRouteData = expressSpansMap.get(req);
4242
const { routeSpan, openedSpans } = expressRouteData;
43-
const isRouterMiddleware = !routeSpan && this.name === 'bound dispatch';
43+
const isRouterMiddleware = Boolean(!routeSpan && this.route);
4444
const middlewareSpanName = (() => {
4545
if (routeSpan) {
4646
return `express.middleware.route.${[
@@ -77,7 +77,9 @@ module.exports.install = (layerPrototype) => {
7777
if (!middlewareSpan.endTime) {
7878
expressRouteData.openedSpans.delete(middlewareSpan);
7979
middlewareSpan.close();
80-
if (this.name === 'bound dispatch') delete expressRouteData.routeSpan;
80+
if (this.route) {
81+
delete expressRouteData.routeSpan;
82+
}
8183
}
8284
} catch (error) {
8385
reportError(error);

0 commit comments

Comments
 (0)