Problems with middleware for tracing
See original GitHub issue_Originally posted by @julienp in https://github.com/prisma/prisma/issues/3107#issuecomment-663972312_
Great feature! I was hoping to use this to add tracing spans for prisma queries with a middleware similar to this:
const _tracer = ...
export async function prismaTracerMiddleware(params, next) {
const span _tracer.startSpan("prisma-query")
const result = await next(params)
span.finish()
return result
}
Tracing libraries such as elastic-apm-node use async_hooks to establish parent-child relations between spans, however it looks like the middleware functions don’t seem to run inside an asynchronous resource.
Using this middleware
export async function asyncContextMiddleware(params, next) {
console.log({
executionAsyncId: executionAsyncId(),
triggerAsyncId: triggerAsyncId(),
})
return next(params)
}
I can see that executionAsyncId
and triggerAsyncId
are always 0. I am not sure what needs to happen to properly propagate the execution context here. The node documentation has some remarks for running in workers, but I do not know the details on how queries are executed in prisma.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Using Execution Tracing to Diagnose Problems
This chapter describes how to enable and use execution tracing for Oracle Service Bus services in Fusion Middleware Control. It includes the following ......
Read more >Distributed Traces, Application Performance Monitoring
Middleware distributed tracing connects front and back-end data, ... Empower your support team to identify & resolve front- and back-end issues quickly.
Read more >Missing trace data | New Relic Documentation
Problems with trace details · Middleware doesn't recognize proprietary New Relic header · An intermediary is missing or isn't passing trace context.
Read more >middleware - Go Packages
Handler applies tracing on the request and ensures that we collect metadata from a request-response cycle. This includes uri and method of ...
Read more >A CTO's strategy towards OpenTracing | by Alois Reitbauer
The first problem is on the way to be resolved within the next year. There is a W3C working group forming that will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the explanation @janpio now I get it. I did exactly that - create a span around the client with a timeout to validate that the spans are nested. And they are:
Therefore I close this issue 🙂
To confirm the problem @abhiaiyer91 described:
you would probably manually start a trace for some other code (so put a span around it). Then that span and the span created via the middleware should appear in the same transaction (instead of creating 2 independent transactions).