-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(node): Only add span listeners for instrumentation when used #15802
Conversation
90d77ae
to
ee30339
Compare
size-limit report 📦
|
@@ -119,6 +125,12 @@ export const prismaIntegration = defineIntegration( | |||
instrumentPrisma({ prismaInstrumentation }); | |||
}, | |||
setup(client) { | |||
// If no tracing helper exists, we skip any work here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not perfect as possibly prisma could be set up later than setup(client)
is being called, but it was the best I could come up with here 🤔 it seems to work in tests at least!
} | ||
|
||
return event; | ||
instrumentation = instrumentVercelAi(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should convert this to use instrumentWhenWrapped
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this - technically, this implementation is better and safer, as it does not rely on patching the method etc. Since we control the instrumentation class here 🤔
Related to #15725 (comment), this PR is an idea to avoid registering
on('spanStart')
hooks for all the node libraries that do not have proper hooks, unless they are used.Today, for OTEL instrumentation that does not provide span hooks, we fall back to
client.on('spanStart')
to enhance/mutate spans emitted by the instrumentation. This PR improved this by only registering thespanStart
client hook if we detect that the OTEL instrumentation is actually wrapping something. This avoids us calling a bunch of span callbacks each time a span is started, when it is not even needed.For this, a new
instrumentWhenWrapped
utility is added which can be passed an instrumentation. This works by monkey-patching_wrap
on the instrumentation, and ensuring a callback is only called conditionally.Note: For some (e.g. connect, fastify) we register
spanStart
in the error handler, which is even better, so there we do not need this logic.