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

Configuring plugin before routes breaks all my tests #12

Closed
2 tasks done
dormesica opened this issue Jan 27, 2025 · 6 comments · Fixed by #13
Closed
2 tasks done

Configuring plugin before routes breaks all my tests #12

dormesica opened this issue Jan 27, 2025 · 6 comments · Fixed by #13
Assignees
Labels
bug Something isn't working

Comments

@dormesica
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

Hi

I am trying to integrate Otel to my Fastify server. I tried following the requirement from the documentation and set up the plugin right after creating the Fastify instance.

It must be configured before defining routes and other plugins in order to cover the most of your Fastify server.

However, doing so broke all my routes (all tests are failing) many of them return 404.
If I configure the plugin after registering routes it seems to work somewhat okay (endpoint work, I see traces but I don't all my hooks being traced).

Does anyone have any idea why this is happening?
If there is more info I can provide to help diagnose this issue please let me know 🙂

@metcoder95
Copy link
Member

Hi! Can you provide an Minimum Reproducible Example to support you better?

@dormesica
Copy link
Author

dormesica commented Jan 28, 2025

Hi @metcoder95

I think I confused something before. It looks to me like when registering the Otel plugin right after the server initialization and before any hook/route definition some of the hooks are getting executed when they should be.

I've created this small repo as an example. If you ran the tests you should get a 404 error thrown from this preHandler hook. If we comment out the plugin registration in app.js line 82 and restore the registration on line 108, the tests pass.

@metcoder95
Copy link
Member

I can see what is happening; I've been playing with it a bit and it seems the plugin mixes the child with the parent context while handling the decoration patches.

Already working on a fix

@metcoder95 metcoder95 self-assigned this Jan 29, 2025
@metcoder95 metcoder95 added the bug Something isn't working label Jan 29, 2025
@Eomm
Copy link
Member

Eomm commented Jan 29, 2025

Note sure if it is related, but here: https://github.com/Eomm/fastify-overview/blob/main/index.js I tracked routes and plugins if it can help with the solution 👍🏼

@metcoder95
Copy link
Member

Thanks a lot, applied a fix; will open a PR soon 👍

@dormesica
Copy link
Author

Thanks @metcoder95
It seems to have fixed the bug 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants