diff --git a/lib/instrumentation/fastify.js b/lib/instrumentation/fastify.js index 0041ad3314..733d6b540a 100644 --- a/lib/instrumentation/fastify.js +++ b/lib/instrumentation/fastify.js @@ -11,6 +11,7 @@ const { buildMiddlewareSpecForMiddlewareFunction } = require('./fastify/spec-builders') const { MiddlewareMounterSpec } = require('../shim/specs') +const symbols = require('../symbols') /** * These are the events that occur during a fastify @@ -95,14 +96,11 @@ module.exports = function initialize(agent, fastify, moduleName, shim) { */ const wrappedExport = shim.wrapExport(fastify, function wrapFastifyModule(shim, fn) { return function wrappedFastifyModule() { - let _fn = fn - if (Object.prototype.toString.call(fn) === '[object Object]') { - // The passed in `fn` is a proxy object returned by import-in-the-middle. - // So we need to pop the original export off it. - _fn = fn.fastify + if (fn[symbols.nrEsmProxy] === true) { + fn = fn.fastify } // call original function get get fastify object (which is singleton-ish) - const fastifyForWrapping = _fn.apply(this, arguments) + const fastifyForWrapping = fn.apply(this, arguments) setupRouteHandler(shim, fastifyForWrapping)