Declaring any preHandler
hook breaks @opentelemetry/instrumentation-fastify
#2355
Labels
bug
Something isn't working
pkg:instrumentation-fastify
priority:p2
Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect
What version of OpenTelemetry are you using?
What version of Node are you using?
Node 18.17.1
What did you do?
Debugging a full project, I wasn't able to add attributes to span inside a fastify request handler, because the span returned from
trace.getActiveSpan()
was already ended.What did you expect to see?
Adding any number of hooks should be okay; when one calls
trace.getActiveSpan()
in a request handler, the span should not be ended yet to allow for adding attributes.What did you see instead?
If ANY
preHandler
to fastify (even a no-op), callingtrace.getActiveSpan()
in a request handler will return an already ended span, preventing you from adding attributes.It seems that for some reason, add other
preHandler
hook to fastify will cause the spans that should be auto-instrumented to end prematurely, before the handler actually runs.I'm not totally sure why, but I'm guessing it has something to do with the fact the instrumentation seems to expect the handler to always run after the auto-instrumentation's own
preHandler
hook...I'm thinking declaring another hook adds a follow up to the first, which ends the span once it completes, instead of actually wrapping the handler.It also wraps
addHook
, which might be trying to prevent this behaviour, but it doesn't seem to work.opentelemetry-js-contrib/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts
Line 193 in 6e8989d
Additional context
Sorry for the wall, but here's a small reproducible example using the Node SDK + Basic fastify setup:
The text was updated successfully, but these errors were encountered: