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

aws-xray-sdk-fastify: Hooks have no effect unless fastify-plugin is used #702

Closed
iwaiktos opened this issue Dec 15, 2024 · 0 comments · Fixed by #703
Closed

aws-xray-sdk-fastify: Hooks have no effect unless fastify-plugin is used #702

iwaiktos opened this issue Dec 15, 2024 · 0 comments · Fixed by #703

Comments

@iwaiktos
Copy link
Contributor

In sdk_contrib/fastify/lib/plugin.js:

const xRayFastifyPlugin = async (fastify, opts) => {
  configureAWSXRaySync(fastify, opts);

  fastify.decorateRequest('segment', null);
  fastify
    .addHook('onRequest', onRequestHook)
    .addHook('onResponse', onResponseHook)
    .addHook('onError', onErrorHook);  // (A)
};

(A) request/response/error hooks are added to fastify context.

But this "fastify" is xRayFastifyPlugin's inside (encapsulated) context, so the hooks have no effect outside of the plugin.

Using fastify-plugin will fix this issue, I guess.

const fp = require('fastify-plugin');

(snip)

const xRayFastifyPlugin = fp(async (fastify, opts) => {
  configureAWSXRaySync(fastify, opts);

  fastify.decorateRequest('segment', null);
  fastify
    .addHook('onRequest', onRequestHook)
    .addHook('onResponse', onResponseHook)
    .addHook('onError', onErrorHook);  // (A)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant