Skip to content

Commit

Permalink
utilize esm proxy symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr committed Apr 24, 2024
1 parent 1d5402a commit 4fcb399
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/instrumentation/fastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 4fcb399

Please sign in to comment.