Skip to content
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

Rewrite NewRelicTrace to support fiber stops/starts #5240

Merged
merged 6 commits into from
Feb 18, 2025
Merged

Conversation

rmosolgo
Copy link
Owner

@rmosolgo rmosolgo commented Feb 17, 2025

Basically, using do ... end-type instrumentation can get confused when there's a Fiber.yield inside the block. (Dataloader does this when a field calls .load.) You can end up with situations where the sum of segments adds up to more than the total request time, because Fiber wait time is being added to the time when another Fiber is running. This makes sense-ish from New Relic's standpoint; they can't really know when the application handed over control in a way that "shouldn't count." See discussion at newrelic/newrelic-ruby-agent#3026.

So, what we can do is stop spans when there's a .yield called, then create a new span after the Fiber resumes control. I developed this in PerfettoTrace and I intend to roll it out to the other tracers, too.


I ran a little test app locally to confirm that this addresses the problem. Here's a before-after where the time tracking starts to line up:

image

TODO:

@rmosolgo rmosolgo merged commit 2816885 into master Feb 18, 2025
15 checks passed
@rmosolgo rmosolgo deleted the better-nr-trace branch February 20, 2025 15:44
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant