-
-
Notifications
You must be signed in to change notification settings - Fork 230
feat: Auto-create traces for MAUI navigation events #5111
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
Draft
jamescrosswell
wants to merge
11
commits into
main
Choose a base branch
from
maui-transactions-5109
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8d40272
feat: Auto-create traces for MAUI navigation events
jamescrosswell 4041119
Format code
getsentry-bot 09760b3
Discard UI event transactions without child spans
jamescrosswell 3a8c8f0
missing verify files
jamescrosswell 86a36db
Clean up duplicate tests
jamescrosswell e02ac47
Fix scope issue for detecting manual transactions
jamescrosswell e0145f4
Fix race conditions
jamescrosswell 67c36c3
Fix no transactions being created when user has a transaction on the …
jamescrosswell 2b71e0c
Address test gaps
jamescrosswell 430ec80
Matched tests with Android implementation
jamescrosswell 54b3d45
Review feedback
jamescrosswell 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| namespace Sentry.Infrastructure; | ||
|
|
||
| /// <summary> | ||
| /// Abstraction over a one-shot timer, to allow deterministic testing. | ||
| /// </summary> | ||
| internal interface ISentryTimer : IDisposable | ||
| { | ||
| /// <summary> | ||
| /// Starts (or restarts) the timer to fire after <paramref name="timeout"/>. | ||
| /// </summary> | ||
| void Start(TimeSpan timeout); | ||
|
|
||
| /// <summary> | ||
| /// Cancels any pending fire. Has no effect if the timer is already cancelled. | ||
| /// </summary> | ||
| void Cancel(); | ||
| } |
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,22 @@ | ||
| namespace Sentry.Infrastructure; | ||
|
|
||
| /// <summary> | ||
| /// Production <see cref="ISentryTimer"/> backed by <see cref="System.Threading.Timer"/>. | ||
| /// </summary> | ||
| internal sealed class SystemTimer : ISentryTimer | ||
| { | ||
| private readonly Timer _timer; | ||
|
|
||
| public SystemTimer(Action callback) | ||
| { | ||
| _timer = new Timer(_ => callback(), null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); | ||
| } | ||
|
|
||
| public void Start(TimeSpan timeout) => | ||
| _timer.Change(timeout, Timeout.InfiniteTimeSpan); | ||
|
|
||
| public void Cancel() => | ||
| _timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); | ||
|
|
||
| public void Dispose() => _timer.Dispose(); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| namespace Sentry.Internal; | ||
|
|
||
| /// <summary> | ||
| /// Internal hub interface exposing additional overloads not part of the public <see cref="IHub"/> contract. | ||
| /// Implemented by <see cref="Hub"/>, <see cref="Extensibility.DisabledHub"/>, and | ||
| /// <see cref="Extensibility.HubAdapter"/>. | ||
| /// </summary> | ||
| internal interface IHubInternal : IHub | ||
| { | ||
| /// <summary> | ||
| /// Starts a transaction that will automatically finish after <paramref name="idleTimeout"/> if not | ||
| /// finished explicitly first. | ||
| /// </summary> | ||
| public ITransactionTracer StartTransaction(ITransactionContext context, TimeSpan? idleTimeout); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically it'd be a breaking change if we added this method to the public |
||
| } | ||
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
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.
Race condition: _currentTransaction field accessed without synchronization in singleton service
The
_currentTransactionfield is added to a singletonMauiEventsBinderand accessed from multiple event handlers (OnShellOnNavigating,OnApplicationOnModalPushed,OnApplicationOnModalPopped,OnWindowOnStopped) without thread synchronization. These handlers can fire concurrently from different navigation events. TheStartNavigationTransactionmethod has a TOCTOU race where it checks_currentTransaction is { IsFinished: false }and then conditionally finishes or resets it - another thread could modify_currentTransactionbetween the check and the subsequent operations.Verification
Read the full MauiEventsBinder.cs to trace all usages of _currentTransaction. Confirmed it's registered as singleton via SentryMauiAppBuilderExtensions.cs line 79. Found multiple event handlers modifying this field: StartNavigationTransaction (lines 327-366), OnApplicationOnModalPopped (lines 388-392), OnWindowOnStopped (lines 407-411). The StartNavigationTransaction method has check-then-act logic without locks (lines 330-334, 337, 364).
Identified by Warden
find-bugs·HKG-HRW