feat(instrumentation): Add FirstDraw spans to activity instrumentation #1281
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.
fixes #1143
What is this change?
This PR adds instrumentation to track the initial draw time of Android activities. A new
FirstDraw
span is created as a child of the activity creation span (e.g.,AppStart
orCreated
), measuring the time from activity creation until the first frame is rendered on screen.The implementation:
ViewTreeObserver.OnDrawListener
to detect when the first draw occursWhat are the points of contention?
1. Screen view complexity attributes
Two new attributes are added to the
FirstDraw
span to capture screen complexity:screen.view.nodes
(long): Total count of all View nodes in the view hierarchyscreen.view.depth
(long): Maximum depth of the view hierarchyWe believe these metrics will add some value if users try to debug long
FirstDraw
spans. Feedback here would be appreciated, though!2. FirstDraw value
FirstDraw
spans aren't a perfect signal for when Activities become 'interactable'. Rather, this can help users identify issues with the UI pipeline. For that, users would have to manually instrument spans or events that fire off when the app or activity enters a state where the end user can actually start interacting with the app.3. FirstDraw span lifecycle
FirstDraw
spans are children of theCreated
spans. However,FirstDraw
span can end long after the parent span has ended. This can create a confusing tracing experience, but we probably don't want to change the definition of the existingCreated
span.Does it make sense to keep FirstDraw as a child of Created?
How was this tested?
Tested some scenarios with the demo app (API versions 28 and 30) to validate the correctness of the instrumentation. If you have any ideas how this could be better tested, feel free to opine!
Raw trace: https://www.codebin.cc/code/cmg9yjmxb0001jz037mtuj2v0:HXhjtG6XV3Vhfh8Ewy6r1S6KfapJtmgM1S1beucxBmpG