Skip to content

Rewrite NewRelicTrace to support fiber stops/starts#5240

Merged
rmosolgo merged 6 commits intomasterfrom
better-nr-trace
Feb 18, 2025
Merged

Rewrite NewRelicTrace to support fiber stops/starts#5240
rmosolgo merged 6 commits intomasterfrom
better-nr-trace

Conversation

@rmosolgo
Copy link
Copy Markdown
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant