Skip to content

Fix duplicative Screen size changed breadcrumbs#888

Merged
marandaneto merged 10 commits into
getsentry:mainfrom
lavinov-mercury:main
Jul 21, 2022
Merged

Fix duplicative Screen size changed breadcrumbs#888
marandaneto merged 10 commits into
getsentry:mainfrom
lavinov-mercury:main

Conversation

@lavinov-mercury

@lavinov-mercury lavinov-mercury commented Jun 16, 2022

Copy link
Copy Markdown
Contributor

📜 Description

This PR adds private var to save last sent metrics breadcrumb & prevent sending new breadcrumbs if data didn't change.
I'm not sure if mutable var is fine here, however, it works & passes all tests (including new ones). Any proposals on better ways to implement this are welcome 😄
I've also updated link to onMetricsChanged docs, as current one seems to be outdated

💡 Motivation and Context

There are tons of repetitive & absolutely useless Screen size changed events in our project. Funniest thing here is that size didn't change actually. One of the reasons for that is that didChangeMetrics also reacts on viewInsets changes, which means that it fires on keyboard opening and closing. And it's 30+ events on my iOS device for each keyboard appearance. So, it would be nice to add new breadcrumbs only when reporting values really changes.

💚 How did you test it?

I've changed related test & added new ones, checked that tests are still passing. Also i've checked it with the example app with new Sentry project. I changed app orientation several times, then caused error and checked appeared issue in Sentry. Then i've added TextField to open & close keyboard, caused one more error & checked new Sentry event. In both cases Screen size changed only when it was expected.

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

@ueman

ueman commented Jun 16, 2022

Copy link
Copy Markdown
Collaborator

This sounds like potential fix for a variant of this issue #400

@marandaneto

Copy link
Copy Markdown
Contributor

I understand that Screen size changed all the time is annoying and noisy, but it's what the OS/framework triggers anyway.
I'd be fine adding a enableWindowMetricBreadcrumbs flag but I'd rather prefer the debouncing in another PR, because it can be reused across different sources of duplication.
I'd rather prefer a debouncing algorithm that works generically instead of a local var which requires the implementation everywhere, how does that sound?

@lavinov-mercury

Copy link
Copy Markdown
Contributor Author

@marandaneto I'm not sure that debouncing is right solution here. It's also incorrect, that each time client sends event to Sentry means that framework reports about screen size change.
According to the Flutter docs, onMetricsChanged method can be called whenever the devicePixelRatio, physicalSize, padding, viewInsets, PlatformDispatcher.views, or systemGestureInsets values change (docs). As you can see, there are few more values that has no relation to screen size and can trigger event on update. As i mentioned in the description, i have 30+ events each time user opens a keyboard, while screen size, obviously, persists the same (it's viewInsets changes when keyboard opens).

However, i agree, that variable + if statement doesn't look like an enterprise solution, i'm going to spend some time to refactor it to something more generic & easy to reuse, but i still believe that this solution should aim to send only distinct events, not debounced.

@lavinov-mercury

Copy link
Copy Markdown
Contributor Author

@marandaneto @brustolin I've refactored this to use stream controller with distinct to avoid duplicates

Comment thread flutter/lib/src/widgets_binding_observer.dart
Comment thread flutter/lib/src/widgets_binding_observer.dart
@marandaneto

Copy link
Copy Markdown
Contributor

@lavinov-mercury thanks, I'll review it early next week.

@lavinov-mercury lavinov-mercury changed the title Fix duplicative metrics breadcrumbs Fix duplicative Screen size changed breadcrumbs Jul 11, 2022
Comment thread flutter/lib/src/widgets_binding_observer.dart
@marandaneto

Copy link
Copy Markdown
Contributor

@lavinov-mercury missing changelog entry.
Thanks for doing this.

@lavinov-mercury

Copy link
Copy Markdown
Contributor Author

@marandaneto I've updated changelog, could you please check, if it's done right?

@marandaneto

Copy link
Copy Markdown
Contributor

@marandaneto I've updated changelog, could you please check, if it's done right?

All good, thanks.
CI is going to fail due to #938 but its a different issue.

@codecov-commenter

codecov-commenter commented Jul 20, 2022

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.81%. Comparing base (bdc6e0f) to head (f3acb7b).
Report is 1336 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #888   +/-   ##
=======================================
  Coverage   89.81%   89.81%           
=======================================
  Files         104      104           
  Lines        3211     3211           
=======================================
  Hits         2884     2884           
  Misses        327      327           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marandaneto
marandaneto enabled auto-merge (squash) July 20, 2022 12:24
@lavinov-mercury

Copy link
Copy Markdown
Contributor Author

@marandaneto Hi! It failed to merge as branch became outdated again, could you please start workflows?

@marandaneto
marandaneto merged commit 5a35e4a into getsentry:main Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants