feat: Automatic trace instrumentation for MAUI#5138
feat: Automatic trace instrumentation for MAUI#5138jamescrosswell wants to merge 46 commits intomainfrom
Conversation
…inished transactions
Resolves 5116: - #5116
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. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5138 +/- ##
==========================================
+ Coverage 74.04% 76.94% +2.89%
==========================================
Files 501 413 -88
Lines 18107 15366 -2741
Branches 3523 3047 -476
==========================================
- Hits 13408 11823 -1585
+ Misses 3838 2820 -1018
+ Partials 861 723 -138 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Removing this tests for two reasons:
- It's in the wrong place... this is testing the TransactionTracer, not the SentryTransaction
- The behaviour has changed with this PR... we only automatically capture transactions on IdleTimeout now if they have child spans. So a simple button click wouldn't create an auto-transaction but a button click that triggered a navigation event or which made ah HTTP request would.
Tests for all of that stuff instrumented in test/Sentry.Tests/TransactionTracerTests.cs
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d17a61e. Configure here.
d17a61e to
a529783
Compare

Resolves #5116
Description
Adds automatic tracing support in Sentry.Maui applications.
This initial PR is fairly lean and adds only adds tracing for button clicks and Shell navigation events. So if you click on a button or an image button that results in a Shell navigation, this will be captured automatically as a transaction, which is useful to identify performance problems with application navigation.
Trivial button clicks (with no child spans) wil be filtered automatically and not captured.
The plan is to expand on this functionality to also automatically create traces for Scroll events and capture things like Mobile Vitals at startup:
Sample
An example of the output from

Sentry.Samples.Mauiwhen opening and closing theSubmitFeedbackmodal:Note
Tracing for button clicks only works if the buttons have some id associated with them (
x:Name)... for example:sentry-dotnet/samples/Sentry.Samples.Maui/SubmitFeedback.xaml
Lines 20 to 21 in bc1c8ab
Resolves: #5109
Implementation
Tracing for UI applications is a little bit complex.
Typically very little work will be done on the main UI thread, to avoid freezing/blocking this. So a UI interaction like a button click might navigate to a new view, a spinner icon animation kicks off and, technically, at that point, the navigation is completed. In reality the app may be implementing some kind of progressive display and loading of portions of that display is still taking place in the background (getting some stuff from a database to load up in the main panel, pulling access control credentials from a remote source to determine what actions should be available on the menu etc.).
The solution we have then is to start a new transaction with an idle timer on it:
This won't be accurate 100% of the time, but it should be a pretty good approximation most of the time.