feat: Auto-create traces for MAUI navigation events#5111
feat: Auto-create traces for MAUI navigation events#5111jamescrosswell wants to merge 11 commits intomainfrom
Conversation
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Features ✨
Fixes 🐛
Dependencies ⬆️Deps
Other
🤖 This preview updates automatically when you update the PR. |
| /// Starts a transaction that will automatically finish after <paramref name="idleTimeout"/> if not | ||
| /// finished explicitly first. | ||
| /// </summary> | ||
| public ITransactionTracer StartTransaction(ITransactionContext context, TimeSpan? idleTimeout); |
There was a problem hiding this comment.
Technically it'd be a breaking change if we added this method to the public IHub interface. Potentially in v7 we could consider making this public and getting rid of the IHubInternal interface.
|
|
||
| // Tracks the active auto-finishing navigation transaction so we can explicitly finish it early | ||
| // (e.g. when the next navigation begins) before the idle timeout would fire. | ||
| private ITransactionTracer? _currentTransaction; |
There was a problem hiding this comment.
Race condition: _currentTransaction field accessed without synchronization in singleton service
The _currentTransaction field is added to a singleton MauiEventsBinder and accessed from multiple event handlers (OnShellOnNavigating, OnApplicationOnModalPushed, OnApplicationOnModalPopped, OnWindowOnStopped) without thread synchronization. These handlers can fire concurrently from different navigation events. The StartNavigationTransaction method has a TOCTOU race where it checks _currentTransaction is { IsFinished: false } and then conditionally finishes or resets it - another thread could modify _currentTransaction between 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
Resolves: #5109
Out of scope
The Android and Cocoa SDKs instrument traces for navigation, gesture and scroll events. This PR does so only for navigation events.
See #5116 for details: