This commit is contained in:
Aurélien 2021-09-22 09:46:09 -07:00 committed by GitHub
commit 9750088b64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -228,8 +228,10 @@ proto._findLayerByHandler = function(handler) {
const isNewRelic = this._router.stack[k].handle['__NR_original'] === handler;
const isAppDynamics = this._router.stack[k].handle['__appdynamicsProxyInfo__'] &&
this._router.stack[k].handle['__appdynamicsProxyInfo__']['orig'] === handler;
const isShimmer = this._router.stack[k].handle['__wrapped'] &&
this._router.stack[k].handle['__original'] === handler;
if (isOriginal || isNewRelic || isAppDynamics) {
if (isOriginal || isNewRelic || isAppDynamics || isShimmer) {
return this._router.stack[k];
} else {
// Aggressively check if the original handler has been wrapped

View File

@ -145,6 +145,27 @@ describe('app', function() {
done();
});
});
it('allows handlers to be wrapped by shimmer (ex: opentelemetry) on express stack',
function(done) {
const myHandler = namedHandler('my-handler');
const wrappedHandler = function(req, res, next) {
myHandler(req, res, next);
};
wrappedHandler['__wrapped'] = true;
wrappedHandler['__original'] = myHandler;
app.middleware('routes:before', wrappedHandler);
const found = app._findLayerByHandler(myHandler);
expect(found).to.be.an('object');
expect(found).have.property('phase', 'routes:before');
executeMiddlewareHandlers(app, function(err) {
if (err) return done(err);
expect(steps).to.eql(['my-handler']);
done();
});
});
it('allows handlers to be wrapped as a property on express stack',
function(done) {