diff --git a/sdk_contrib/fastify/lib/hooks/on-request.hook.js b/sdk_contrib/fastify/lib/hooks/on-request.hook.js index 2f215e55..7bbaa9e9 100644 --- a/sdk_contrib/fastify/lib/hooks/on-request.hook.js +++ b/sdk_contrib/fastify/lib/hooks/on-request.hook.js @@ -16,6 +16,7 @@ module.exports = function onRequestHook(request, reply, done) { ns.run(() => { AWSXRay.setSegment(segment); + done(); }); } else { request.log.info('Manual mode, skipping segment'); @@ -25,7 +26,7 @@ module.exports = function onRequestHook(request, reply, done) { } else { request.log.warn('Request already has a segment, skipping'); } - } - done(); + done(); + } }; diff --git a/sdk_contrib/fastify/lib/plugin.js b/sdk_contrib/fastify/lib/plugin.js index 8edc2083..e89cbf55 100644 --- a/sdk_contrib/fastify/lib/plugin.js +++ b/sdk_contrib/fastify/lib/plugin.js @@ -1,11 +1,12 @@ // @ts-check +const fp = require('fastify-plugin').default; const configureAWSXRaySync = require('./private/configure-aws-x-ray-sync'); const onRequestHook = require('./hooks/on-request.hook'); const onResponseHook = require('./hooks/on-response.hook'); const onErrorHook = require('./hooks/on-error.hook'); /** @type {import('fastify').FastifyPluginAsync} */ -const xRayFastifyPlugin = async (fastify, opts) => { +const xRayFastifyPlugin = fp(async (fastify, opts) => { configureAWSXRaySync(fastify, opts); fastify.decorateRequest('segment', null); @@ -13,7 +14,7 @@ const xRayFastifyPlugin = async (fastify, opts) => { .addHook('onRequest', onRequestHook) .addHook('onResponse', onResponseHook) .addHook('onError', onErrorHook); -}; +}); module.exports = xRayFastifyPlugin;