I have activated Google Cloud Tracer with nodejs & express, works well in automatic mode, registers calls to the api correctly.
I try to create a trace manually, to know the execution time of intermediate steps.
controller (req, res) {
tracer.runInRootSpan({ name: 'dnd-task' }, (rootSpan) => {
//promise
myPromise(rootSpan)
.then((data) => {
rootSpan.endSpan()
res.ok(data)
})
.catch((err)=>{
rootSpan.endSpan()
res.send(err)
})
})
}
but Google Cloud Trace only lists 1 or 2 calls, while automatically generated calls show thousands of API calls.
I also read the documentation to try to get the context of express.js middleware, but I didn't find a way to get the context.
from: google-cloud-trace
a root span is automatically started whenever an incoming request is received (in other words, all middleware already runs within a root span).
Update base on @kjin comment:
inside a controller in express you only need
tracer.createChildSpan({name: 'name'})