question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
timsuchanekcommented, Aug 1, 2020

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: image

Therefore I close this issue 🙂

0reactions
janpiocommented, Aug 1, 2020

To confirm the problem @abhiaiyer91 described:

What we see is all spans become transactions. There is no parent associated to them

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found