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

add addHook handler to fastify instrumentation #936

Merged
merged 13 commits into from
Oct 7, 2021

Conversation

garbados
Copy link
Contributor

Proposed Release Notes

  • Instrument Fastify routes by wrapping addHook.

Links

Details

As of this writing, this PR does not add additional tests. (I'm working on it...!) Any pointers about testing this would be appreciated, cc @bizob2828

t.test('should wrap request/response hooks', async (t) => {
let ok = false

fastify.addHook('onRequest', (request, reply, done) => {
Copy link
Member

@bizob2828 bizob2828 Sep 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally I would put these kind of tests in the naming suites. I'd abstract away the creation of the fastify server and add hooks for every single request lifecycle event. Then assert the segment names which means it's prob best to name each plugin function instead of arrow functions, but we can chat IRL just ping me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up placing them in their own test file because it seems the hook isn't affected by the differences between v2 and v3. LMK if this is sub-optimal!

@garbados
Copy link
Contributor Author

OK! Hook wrapper updated, tests added. The tests pass but only because there are some lifecycle events that don't get caught, which I then commented out. Specifically:

  • preValidation
  • preHandler
  • preSerialization

I'll dive into this tomorrow but I thought getting this far was a nice milestone for the day.

@garbados
Copy link
Contributor Author

Sooooo as of this morning, those lifecycle events that mysteriously weren't firing yesterday... totally do fire this morning! 🤷‍♀️

I'll push what I have momentarily and then we'll let the CI make its call.

@garbados garbados marked this pull request as ready for review September 30, 2021 17:06
@garbados
Copy link
Contributor Author

Looks like we're good to go for review! Tests pass :D

Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instrumentation looking good, however the versioned tests aren't wired up and are failing for me in v3 and hanging in v2

Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work adding tests for these lifecycle hooks

@bizob2828 bizob2828 merged commit 72b0677 into newrelic:main Oct 7, 2021
@github-actions github-actions bot mentioned this pull request Oct 12, 2021
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 this pull request may close these issues.

Fastify GA: Record all request lifecyle plugins as middleware
2 participants