Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support middleware injected by OpenTelemetry Express Instrumentation plugin #4351

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/server-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down