Skip to content

tracing: nest rails spans properly

Igor requested to merge igor-tracing-nesting into master

The current OpenTracing/jaeger instrumentation on rails events (action_view, active_record, active_support) does not capture parent/child relationships between spans.

This is a limitation of the rails instrumentation API. Specifically ActiveSupport::Notifications.subscribe appears to only support processing events after they happened.

It turns out that there is an undocumented API that allows hooking into before/after of each event. This works by passing an object with start and finish methods.

By using that API, we can get proper nesting of spans, which makes the traces significantly more valuable, as it allows attributing the source of calls.

Before (flat list of spans):

Screenshot_2020-03-02_at_11.50.59

After (a tree):

Screenshot_2020-03-02_at_11.45.26

Edited by Igor

Merge request reports