-
-
Notifications
You must be signed in to change notification settings - Fork 376
fix: in_foreground and is_active app context #7188
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
Conversation
Fix the mismatch of the app context in foreground between fatal and non-fatal events. Also, fix the breadcrumbs to correctly add in_foreground and in background crumbs, and add new active crumbs for more info for the user. Fixes GH-6178
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛
🤖 This preview updates automatically when you update the PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7188 +/- ##
=============================================
+ Coverage 85.099% 85.113% +0.013%
=============================================
Files 473 475 +2
Lines 28557 28589 +32
Branches 12462 12474 +12
=============================================
+ Hits 24302 24333 +31
+ Misses 4210 4208 -2
- Partials 45 48 +3
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Add test coverage for the new is_active field in SentryCrashReportConverter: - testAppContextIsActiveTrue_IsTrue: verifies is_active is true from crash report - testAppContextIsActiveFalse_FromCrashReport: verifies is_active is false from crash report - testAppContextIsActiveFalse_IsFalse: verifies manually set false value - testAppContextIsActiveNil_IsNil: verifies nil handling Also update existing tests to expect both in_foreground and is_active fields.
…r protocol - Extract app state logic from SentryClient.m (lines 714-739) to Swift - Create SentryEventContextEnricher protocol with SentryDefaultEventContextEnricher implementation - Add in_foreground and is_active fields based on UIApplicationState - Support all platforms (UIKit: enrichment, non-UIKit: no-op) - Fix retain cycle with [weak self] in applicationStateProvider closure - Handle nil application state with warning log - Add comprehensive unit tests for all app states and edge cases - Add tests for is_active field in SentryCrashReportConverter - Add TestEventContextEnricher helper for test reusability Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- Move eventContextEnricher property from SentryClient+Private.h to class extension in SentryClient.m - Make property truly internal, not exposed in any header - Remove protocol forward declaration from private header
- Rename method to be more specific about enriching with app state - Update protocol documentation to clarify it adds in_foreground and is_active - Update all call sites and tests to use new method name
…ntext - Avoid nullable default pattern (?? [:]) - Make it explicit when creating new app context vs using existing one
- Change func enrichWithAppState(_ context: [String: Any]?) to non-optional parameter
- SentryClient.m always passes non-nil context (event.context ?: @{})
- Remove nil handling in enricher implementation
- Update test to verify empty dict is passed when context is nil
…oject - Replace if-else with nil coalescing operator for appContext - Add SentryDefaultEventContextEnricherTests.swift to Xcode project - Add TestEventContextEnricher.swift to Xcode project - Both test files now properly included in build targets
- Check if context["app"] exists but is not a dictionary - Log warning when app context has invalid type - Return context unchanged when app context type is invalid - Update test to verify unchanged context and proper warning behavior
…entStates - Test was redundant with individual state tests - Each call created a fresh enricher instance (no stateful behavior tested) - Coverage already provided by testEnrichEventContext_WhenActive/Inactive/Background
Changed non-UIKit platform tests from extension to class definition. On macOS, the main test class is not defined (UIKit platforms only), so the extension failed to compile. Now macOS has its own class definition with platform-specific tests. Fixes compilation error on macOS.
Changed from separate class definitions per platform to single class with platform-specific tests inside #if directives. This approach is cleaner and prevents duplication of the class definition. - UIKit platform tests (iOS, tvOS, visionOS) in first #if block - Non-UIKit platform tests (macOS) in second #if block
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| a424cf3 | 1231.36 ms | 1259.62 ms | 28.25 ms |
| 58a9225 | 1211.40 ms | 1238.88 ms | 27.48 ms |
| 013fd4d | 1216.02 ms | 1242.16 ms | 26.14 ms |
| 387fbe4 | 1226.19 ms | 1251.98 ms | 25.79 ms |
| 84bc307 | 1211.52 ms | 1237.09 ms | 25.56 ms |
| ffe0649 | 1213.35 ms | 1248.64 ms | 35.29 ms |
| 4e4af90 | 1222.89 ms | 1252.15 ms | 29.26 ms |
| 7714225 | 1213.24 ms | 1252.28 ms | 39.04 ms |
| 29b6704 | 1216.31 ms | 1251.91 ms | 35.60 ms |
| bed2eb7 | 1215.88 ms | 1247.14 ms | 31.27 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| a424cf3 | 24.14 KiB | 1.06 MiB | 1.04 MiB |
| 58a9225 | 24.14 KiB | 1.06 MiB | 1.04 MiB |
| 013fd4d | 24.14 KiB | 1.04 MiB | 1.02 MiB |
| 387fbe4 | 24.14 KiB | 1.07 MiB | 1.04 MiB |
| 84bc307 | 24.14 KiB | 1.08 MiB | 1.06 MiB |
| ffe0649 | 24.14 KiB | 1.06 MiB | 1.04 MiB |
| 4e4af90 | 24.14 KiB | 1.08 MiB | 1.06 MiB |
| 7714225 | 24.14 KiB | 1.07 MiB | 1.05 MiB |
| 29b6704 | 24.14 KiB | 1.06 MiB | 1.04 MiB |
| bed2eb7 | 24.14 KiB | 1.07 MiB | 1.04 MiB |
philprime
left a comment
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.
LGTM with one feedback comment
Enables running specific test classes during development, speeding up iterations when using agents for refactoring. This allows targeted testing of affected areas without running the full test suite.
We received the feedback in #7316 that it was easy to miss that we fixed a bug which now requires `sendDefaultPii` to be set to `true` for user attributes to be set. This adds an alert to the changelog which I will also copy to the GitHub release notes
) * refactor: Convert `SentryPerfromanceTrackingIntegration` to Swift * Merge fixes * Fix visionOS tests * Remove SentryDependencyContainer dependency * Fix project missing files * Fix UITest * Refactor UIViewController swizzling + add more tests * Use same loop than ObjC (just in case) * Minor improvements * Remove `Dynamic` use * Apply PR feedback * Remove URL and use file path * Fix typo
📜 Description
This PR aligns the
in_foregroundapp context behaviour for both handled and unhandled events and also adds ais_activeproperty to the app context.getsentry/sentry#107047 will correctly format is_active in the issue details view.
Next steps:
💡 Motivation and Context
First step for GH-6178
💚 How did you test it?
Unit tests and simulator
📝 Checklist
You have to check all boxes before merging:
sendDefaultPIIis enabled.