You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The diagnostics_channel was landed on v15 and seems fair to think about to include it on fastify core, since that it will help the APM vendors and self-analysis.
@Qard made nice work there and I mentioned here to help us if needed.
For further information, check the PR here and the changelog here.
The stability on the core is still experimental but seems fair to talk about now.
The main thing I'd see APMs wanting to know from fastify is middleware and routing transitions. Having a name for the middleware and method + routing pattern for the routes would be perfect. I'd need to take a closer look to see if there's anything else interesting in there, but that's a good place to start.
Out that could be implemented is by adding a hook in onRoute. That will have all the lifecycle hooks registered for a given route, so you can essentially wrap all of them.
It'd also help to know when a response is sent. Basically, an APM will want to produce a "span" around each middleware or route, so the transitions can be the start of a new span and then the end is either when another transition happens or a response is started.
A plugin seems a better choice since the information needed is available through hooks. In case of the response sent, we have the onSend hook available.
My worry is because the hooks need to be called immediately after the event, to get the elapsed time and metrics around it. At this time, I believe that a plugin is enough.
For now, I would just add transition events and not worry about spans. Spans can be added later, if we eventually decide on an API for that.
For comparison, here's the changes I did for express: pillarjs/router#96. It doesn't have spans, just a single event when the transition happens with (hopefully) sufficient metadata to identify the full routing path. (The routing path thing is complicated in express, which is why that hasn't landed yet...I'll get back to it at some point soon, hopefully...)
Activity
mcollina commentedon Nov 19, 2020
It'd be good to have an official plugin for it. All the critical information should be available for plugins to consume anyway.
AyoubElk commentedon Nov 19, 2020
I'd be interested in working on this plugin. What kind of information do you think would be nice to have published?
mcollina commentedon Nov 19, 2020
Not entirely sure :). Maybe @Qard can help!
Qard commentedon Nov 19, 2020
The main thing I'd see APMs wanting to know from fastify is middleware and routing transitions. Having a name for the middleware and method + routing pattern for the routes would be perfect. I'd need to take a closer look to see if there's anything else interesting in there, but that's a good place to start.
mcollina commentedon Nov 19, 2020
Out that could be implemented is by adding a hook in
onRoute. That will have all the lifecycle hooks registered for a given route, so you can essentially wrap all of them.Qard commentedon Nov 19, 2020
It'd also help to know when a response is sent. Basically, an APM will want to produce a "span" around each middleware or route, so the transitions can be the start of a new span and then the end is either when another transition happens or a response is started.
RafaelGSS commentedon Nov 19, 2020
A plugin seems a better choice since the information needed is available through hooks. In case of the response sent, we have the
onSendhook available.My worry is because the hooks need to be called immediately after the event, to get the elapsed time and metrics around it. At this time, I believe that a plugin is enough.
RafaelGSS commentedon Nov 23, 2020
Base repo created. Tonight, I'll adjust the foundation to create the plugin https://github.com/fastify/fastify-diagnostics-channel.
RafaelGSS commentedon Nov 25, 2020
@Qard Span API block this PR? Otherwise, how do you think that is better to provide the information? I mean, some basic rules as:
Therefore, we have some best pratices to create a channel name or something like that?
Qard commentedon Nov 26, 2020
For now, I would just add transition events and not worry about spans. Spans can be added later, if we eventually decide on an API for that.
For comparison, here's the changes I did for express: pillarjs/router#96. It doesn't have spans, just a single event when the transition happens with (hopefully) sufficient metadata to identify the full routing path. (The routing path thing is complicated in express, which is why that hasn't landed yet...I'll get back to it at some point soon, hopefully...)
RafaelGSS commentedon Dec 16, 2020
PR created: fastify/fastify-diagnostics-channel#3
mcollina commentedon Dec 16, 2020
I think this could be closed for now.