How to get nested spans for a request? ```const tr...
# support
d
How to get nested spans for a request?
Copy code
const trace = signozTracer.startSpan(functionName);
const span = trace.addEvent('mongo-getbyid');
I tried the above approach, but I am getting
mongo-getbyid
in events section, instead of in spans below main span. Any advice to manually instrument database performance traces so that I can see it in a request span as well as separately in mongo group for example.
I checked about
tracer*.*startActiveSpan
, but this must be using something like
asynclocalstorage
which I would prefer to avoid.
s
mongo-getbyid
is not a span. You are adding it as an event to the existing span.
Why are you trying to manually instrument? Are you aware that there are libraries to help capture db requests automatically https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node?
d
they use asyncContext APIs, which reduces performance by 50% at least. I have already mentioned that, I am not looking for
node:async
related solutions.
Also I am using uWebSockets.js, which does not have any such instrumentation
s
Follow these docs for manual instrumentation https://opentelemetry.io/docs/languages/js/instrumentation/
d
yeah, I was able to figure it out later.
by marking parent span as active, and passing the context