dd-trace-js
dd-trace-js copied to clipboard
Hook not altering resource name to include path
Expected behaviour I am expecting the resource to include the URL path alongside the method, e.g. "POST /login" Actual behaviour Only seeing all POST requests to the server grouped together, and all of the internal requests beng made to external services are being traced with the method + path
Steps to reproduce
I am using a fastify server, and the below tracer config:
tracer.use('http', {
client: {
service: "service-name",
hooks: {
request: (span, req, res) => {
(span as Span).setTag('resource.name', `${req?.method} ${req?.path}`)
}
}
}
});
(I have tried using the 'fastify' plugin, and applying a similar hook, but this also results in resources that don't contain the path):
tracer.use('fastify', {
hooks:{
request: (span:any, req, res) => {
span.setTag('resource.name', `${req?.method} ${req?.url}`)
}},
})
Environment
- Node.js version: 14
- Tracer version: ^2.7.0
- Agent version:
- Relevant library versions:
Hi @jmichel-bc! Usually when this happens, it's because tracer.init() was called after fastify was required. tracer.init() needs to happen before any other requires.
By default, our HTTP server instrumentation does not add the path due to high cardinality and since the path may contain sensitive data. When using an instrumented web framework like fastify, we can get the parameterized path from that. Usually this is added without issue, but it might not work in cases where fastify was loaded too early (meaning before tracer.init() was called).
If you want the entire path every time, you could do something like the first config snippet you provided, but you'd need to switch from client to server on the second line.
Hmmm, I have adjusted the code such that the initialised tracer is the first import; still having the same issue with no paths being appeneded to the resource name using the fastify plguin with the hook above!
@jmichel-bc Can you share the import code? It looks from the above snippet that you're using TypeScript, which could be hoisting your imports depending on where you call them. We also provide an example of how to avoid hoisting in our setup docs.
Hmmm, I have adjusted the code such that the initialised tracer is the first import; still having the same issue with no paths being appeneded to the resource name using the fastify plguin with the hook above!
I had a similar issue on my side and I've temporary downgraded to [email protected]
@jmichel-bc Can you share the import code? It looks from the above snippet that you're using TypeScript, which could be hoisting your imports depending on where you call them. We also provide an example of how to avoid hoisting in our setup docs.
Indeed, what you've suggested works, I've followed the documentation and load the tracer with [email protected] before calling the method NestFactory.create and it works on my side.
Looks like this issue is pretty old and the OP didn't reply to Roch's question. Is it still an issue? It looks like things were solved so I'll close it for now. Feel free to ping us and reopen if I'm misunderstanding!