Improve .inspect support for DetailedTrace, support debug: false #5477
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This improves
DetailedTracein 3 ways:.inspectcall is now customizable. You can subclassDetailedTraceand provide a new implementation fordef inspect_object(object). Arguably this isn't good enough since under the hood it still creates DebugAnnotations. Also note that only instances of non-built-in classes get routed to that method. String, Symbol, true, false, nil, numbers, Hash, Array, Module (others?) all are still handled by the tracer directly..inspectcalls are now outside the spans that they relate to. Previously, time spent buildinginspectstrings would get counted along field execution (maybe also data loader sources, analysis, and validation).use ..., debug: falseor per-query withcontext: { detailed_trace_debug: false }.Before,
.inspectis silently included in field span:After,
.inspectis separate from application code and gets its own span:Basically, those pink parts were previously included in the preceding field execution spans, but now they aren't.
To accomplish this, I had to make sure that, for
TYPE_SLICE_ENDpackets, it captures the timestamp before creating thedebug_annotations: ..., then pass the timestamp into the packet method. I also handledextra_counter_values:this way so that asking Ruby about allocations wouldn't get lumped in with field execution time.TYPE_SLICE_BEGINpackets get this for free because Ruby evaluates the arguments for the method first, including values fordebug_annotations:andcounter_values:, then calls the method with those objects, wheretsgrabs the current timestamp.Also, inspect spans are tagged with the debug field that triggered the inspect. In this example, it was
result:It could also be
arguments,fetch keys, or any ActiveSupport::Notifications payload key.Fixes #5423