Skip to content

Commit 87428ca

Browse files
committed
change the internal var name for clarity (from PR review)
1 parent 343b949 commit 87428ca

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ export class ExpressInstrumentation extends InstrumentationBase<ExpressInstrumen
6262
'express',
6363
['>=4.0.0 <6'],
6464
moduleExports => {
65-
const isExpressV5 =
65+
const isExpressWithRouterPrototype =
6666
typeof moduleExports?.Router?.prototype?.route === 'function';
67-
const routerProto = isExpressV5
68-
? moduleExports.Router.prototype
69-
: moduleExports.Router;
67+
const routerProto = isExpressWithRouterPrototype
68+
? moduleExports.Router.prototype // Express v5
69+
: moduleExports.Router; // Express v4
7070
// patch express.Router.route
7171
if (isWrapped(routerProto.route)) {
7272
this._unwrap(routerProto, 'route');
@@ -86,15 +86,15 @@ export class ExpressInstrumentation extends InstrumentationBase<ExpressInstrumen
8686
moduleExports.application,
8787
'use',
8888
// eslint-disable-next-line @typescript-eslint/no-explicit-any
89-
this._getAppUsePatch(isExpressV5) as any
89+
this._getAppUsePatch(isExpressWithRouterPrototype) as any
9090
);
9191
return moduleExports;
9292
},
9393
moduleExports => {
9494
if (moduleExports === undefined) return;
95-
const isExpressV5 =
95+
const isExpressWithRouterPrototype =
9696
typeof moduleExports?.Router?.prototype?.route === 'function';
97-
const routerProto = isExpressV5
97+
const routerProto = isExpressWithRouterPrototype
9898
? moduleExports.Router.prototype
9999
: moduleExports.Router;
100100
this._unwrap(routerProto, 'route');
@@ -144,7 +144,7 @@ export class ExpressInstrumentation extends InstrumentationBase<ExpressInstrumen
144144
/**
145145
* Get the patch for Application.use function
146146
*/
147-
private _getAppUsePatch(isExpressV5: boolean) {
147+
private _getAppUsePatch(isExpressWithRouterPrototype: boolean) {
148148
const instrumentation = this;
149149
return function (original: express.Application['use']) {
150150
return function use(
@@ -154,7 +154,9 @@ export class ExpressInstrumentation extends InstrumentationBase<ExpressInstrumen
154154
) {
155155
// If we access app.router in express 4.x we trigger an assertion error.
156156
// This property existed in v3, was removed in v4 and then re-added in v5.
157-
const router = isExpressV5 ? this.router : this._router;
157+
const router = isExpressWithRouterPrototype
158+
? this.router
159+
: this._router;
158160
const route = original.apply(this, args);
159161
if (router) {
160162
const layer = router.stack[router.stack.length - 1];

0 commit comments

Comments
 (0)