Skip to content

Commit 72d523d

Browse files
authored
Merge pull request #703 from iwaiktos/fix-fastify-plugin
Fix (aws-xray-sdk-fastify): enable automatic mode and expose hooks
2 parents b63b3f2 + 723597a commit 72d523d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

sdk_contrib/fastify/lib/hooks/on-request.hook.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = function onRequestHook(request, reply, done) {
1616

1717
ns.run(() => {
1818
AWSXRay.setSegment(segment);
19+
done();
1920
});
2021
} else {
2122
request.log.info('Manual mode, skipping segment');
@@ -25,7 +26,7 @@ module.exports = function onRequestHook(request, reply, done) {
2526
} else {
2627
request.log.warn('Request already has a segment, skipping');
2728
}
28-
}
2929

30-
done();
30+
done();
31+
}
3132
};

sdk_contrib/fastify/lib/plugin.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
// @ts-check
2+
const fp = require('fastify-plugin').default;
23
const configureAWSXRaySync = require('./private/configure-aws-x-ray-sync');
34
const onRequestHook = require('./hooks/on-request.hook');
45
const onResponseHook = require('./hooks/on-response.hook');
56
const onErrorHook = require('./hooks/on-error.hook');
67

78
/** @type {import('fastify').FastifyPluginAsync} */
8-
const xRayFastifyPlugin = async (fastify, opts) => {
9+
const xRayFastifyPlugin = fp(async (fastify, opts) => {
910
configureAWSXRaySync(fastify, opts);
1011

1112
fastify.decorateRequest('segment', null);
1213
fastify
1314
.addHook('onRequest', onRequestHook)
1415
.addHook('onResponse', onResponseHook)
1516
.addHook('onError', onErrorHook);
16-
};
17+
});
1718

1819
module.exports = xRayFastifyPlugin;
1920

0 commit comments

Comments
 (0)