-
Notifications
You must be signed in to change notification settings - Fork 602
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
How to pause a span when its Fiber yields? #3026
Comments
Hi @rmosolgo ! Thank you for opening this issue and providing a great overview of your thoughts. I can see where you’re coming from with how time is represented here, but the concept of 'pausing' a span isn’t how they were designed to work. Spans are meant to account for total elapsed time, which includes both the time spent actively working and any time spent waiting for external resources or dependencies. Pausing a span would break the idea of continuity and its ability to really represent the full lifecycle of an operation as spans weren’t designed to model "active" versus "idle" time. As far as existing options in the agent go, you could use custom instrumentation to split spans in two, one recording the time before We’re going to keep this issue open as a reminder to discuss internally. In the meantime, we’d love to hear if other community members have thoughts about this. |
Thanks for getting back to me, @hannahramadan. That makes sense about spans being start-and-finish -- I can't say I've seen any other instrumentation tools with any concept of "pausing." I think it was on the tip of my tongue since Ruby's Fibers work that way. Another possibility I've been considering is to adopt |
Hi @rmosolgo, thanks for your understanding. If you (or any other community members) find solutions to this problem with existing custom instrumentation APIs, we'd love to hear about them! |
Is your feature request related to a problem? Please describe.
Hi! In GraphQL-Ruby, field execution is instrumented. But, the field can call
Fiber.yield
to make itself wait for some other work to be done. (The other work isGraphQL::Dataloader
.) When that work is done, the field's Fiber is resumed and GraphQL execution continues.In practice, we end up with several Fibers paused while their fields wait for data. Once the data is available, those Fibers are resumed (one-at-a-time) and field execution completes.
The problem is that the field's span in NewRelic includes the time where it was actually paused (because of
Fiber.yield
). So although clock time was actually passing, Ruby wasn't doing anything with that Fiber.Then, in the UI, it looks like these GraphQL fields are taking a loooong time (longer than the request duration, actually) -- but it's because the waiting time is counted for each span that's waiting.
Feature Description
I'd like a way to improve the tracing so that I can "pause" the span when a Fiber yields. Or some other way to eliminate this "double-counting" of wait time?
Describe Alternatives
We could do nothing. In that case, whenever we adopt Dataloader, we get a big (nonsensical) spike in segment time:
We'd have to learn to ignore that input 😿
We could not use Fibers in the code. That's also a possibility -- The GraphQL-Batch library doesn't use fibers -- but honestly, it has the same problem with tracing, but it manifests differently because GraphQL-Batch uses Promises instead of
Fiber.yield
.Are there existing options in the NewRelic agent that I could use to improve tracing in this case?
Additional context
Here's a simplified example of what GraphQL-Ruby does:
Tracing work with Fiber.yield
Priority
Really Want 😊
The text was updated successfully, but these errors were encountered: