-
-
Notifications
You must be signed in to change notification settings - Fork 284
feat(span-first): Add TTID/TTFD instrumentation #3532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e7d39c8
feat(flutter): Add TimeToDisplayTrackerV2 for streaming TTID/TTFD
buenaflor ab04b07
refactor(flutter): Wire TimeToDisplayTrackerV2 through the system
buenaflor f3b0bcb
refactor(flutter): Improve TimeToDisplayTrackerV2 wiring and add stre…
buenaflor 44dcb96
Update logger and example
buenaflor c0f9d6d
Review
buenaflor 14d6df2
Review
buenaflor 9d03dee
Review
buenaflor 4d81a0f
Fix test
buenaflor 027b043
Review
buenaflor fcaa139
Merge branch 'feat/span-first' into feat/span/ttid-ttfd
buenaflor 414f04c
Update
buenaflor 4a8b74b
Update
buenaflor 7768434
review
buenaflor 478f9ec
review
buenaflor fe07028
Update
buenaflor 5e14510
test(tracing): Add TTFD conditional tests and refactor observer strea…
buenaflor 465c983
refactor(tracing): Use Dart 3 object pattern for TTFD option check
buenaflor 6956632
feat(tracing): Add debug logging for TTFD option check
buenaflor 016e594
fix(test): Enable enableTimeToFullDisplayTracing in SentryDisplayWidg…
buenaflor 191cc16
Analyze
buenaflor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/flutter/lib/src/navigation/time_to_display_tracker_v2.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // ignore_for_file: invalid_use_of_internal_member | ||
|
|
||
| import 'package:meta/meta.dart'; | ||
|
|
||
| import '../../sentry_flutter.dart'; | ||
| import '../frame_callback_handler.dart'; | ||
| import '../utils/internal_logger.dart'; | ||
|
|
||
| @internal | ||
| class TimeToDisplayTrackerV2 { | ||
| final Hub _hub; | ||
| final FrameCallbackHandler _frameCallbackHandler; | ||
| SentrySpanV2? _ttfdSpan; | ||
|
|
||
| TimeToDisplayTrackerV2({ | ||
| Hub? hub, | ||
| FrameCallbackHandler? frameCallbackHandler, | ||
| }) : _hub = hub ?? HubAdapter(), | ||
| _frameCallbackHandler = | ||
| frameCallbackHandler ?? DefaultFrameCallbackHandler(); | ||
|
|
||
| SpanId? get ttfdSpanId => _ttfdSpan?.spanId; | ||
|
|
||
| void trackRoute(String routeName) { | ||
| cancelCurrentRoute(); | ||
|
|
||
| final routeSpan = _hub.startIdleSpan(routeName, attributes: { | ||
| SemanticAttributesConstants.sentryOp: | ||
| SentryAttribute.string(SentrySpanOperations.uiLoad), | ||
| SemanticAttributesConstants.sentryOrigin: SentryAttribute.string( | ||
| SentryTraceOrigins.autoNavigationRouteObserver), | ||
| }); | ||
| final ttidSpan = _hub.startInactiveSpan( | ||
| '$routeName initial display', | ||
| parentSpan: routeSpan, | ||
| attributes: { | ||
| SemanticAttributesConstants.sentryOp: | ||
| SentryAttribute.string(SentrySpanOperations.uiTimeToInitialDisplay), | ||
| SemanticAttributesConstants.sentryOrigin: SentryAttribute.string( | ||
| SentryTraceOrigins.autoNavigationRouteObserver), | ||
| }, | ||
| ); | ||
|
|
||
| if (_hub.options | ||
| case SentryFlutterOptions(enableTimeToFullDisplayTracing: true)) { | ||
| _ttfdSpan = _hub.startInactiveSpan( | ||
| '$routeName full display', | ||
| parentSpan: routeSpan, | ||
| attributes: { | ||
| SemanticAttributesConstants.sentryOp: | ||
| SentryAttribute.string(SentrySpanOperations.uiTimeToFullDisplay), | ||
| SemanticAttributesConstants.sentryOrigin: SentryAttribute.string( | ||
| SentryTraceOrigins.autoNavigationRouteObserver), | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| _frameCallbackHandler.addPostFrameCallback((_) { | ||
| ttidSpan.end(); | ||
| }); | ||
| } | ||
|
|
||
| void reportFullyDisplayed(SpanId spanId) { | ||
| final ttfdSpanId = _ttfdSpan?.spanId; | ||
| if (ttfdSpanId != spanId) { | ||
| internalLogger.debug( | ||
| 'Ignoring reportFullyDisplayed for span $spanId because active TTFD span is $ttfdSpanId.', | ||
| ); | ||
| return; | ||
| } | ||
| _ttfdSpan?.end(); | ||
| _ttfdSpan = null; | ||
| } | ||
|
|
||
| void cancelCurrentRoute() { | ||
| _ttfdSpan = null; | ||
sentry[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Cancel any active idle span (navigation or user interaction) so | ||
| // startIdleSpan can create a fresh one on the next route. | ||
| final activeSpan = _hub.getActiveSpan(); | ||
| if (activeSpan is IdleRecordingSentrySpanV2) { | ||
| activeSpan | ||
| ..status = SentrySpanStatusV2.cancelled | ||
| ..end(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/flutter/test/navigation/fake_time_to_display_tracker_v2.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // ignore_for_file: invalid_use_of_internal_member | ||
|
|
||
| import 'package:sentry_flutter/src/navigation/time_to_display_tracker_v2.dart'; | ||
|
|
||
| class FakeTimeToDisplayTrackerV2 extends TimeToDisplayTrackerV2 { | ||
| final List<String> trackRouteCalls = []; | ||
| int cancelCurrentRouteCalls = 0; | ||
|
|
||
| @override | ||
| void trackRoute(String routeName) { | ||
| trackRouteCalls.add(routeName); | ||
| } | ||
|
|
||
| @override | ||
| void cancelCurrentRoute() { | ||
| cancelCurrentRouteCalls++; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default should be 3 seconds