Skip to content
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

feat: Track timezone changes as breadcrumbs #1930

Merged
merged 34 commits into from Jul 6, 2022

Conversation

kevinrenskers
Copy link
Contributor

@kevinrenskers kevinrenskers commented Jul 4, 2022

📜 Description

When the timezone changes, the system sends a notification. We track this event as a breadcrumb.

💡 Motivation and Context

Close #1763

💚 How did you test it?

Unit test. Also ran the sample app, changed my device's timezone, and confirmed that a breadcrumb was posted to Sentry: https://sentry.io/organizations/sentry-sdks/issues/2895893229/?project=5428557#breadcrumbs

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • Review from the native team if needed
  • No breaking changes

🔮 Next steps

@github-actions
Copy link

github-actions bot commented Jul 4, 2022

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 2571228

@kevinrenskers
Copy link
Contributor Author

This currently is very very simple: it just sends a breadcrumb with the action kCFTimeZoneSystemTimeZoneDidChangeNotification. Do we want to log the old and the new timezone as well?

Also the issue says "Ideally we persist previous runs breadcrumbs so steps from a previous run can help diagnose issues related to time changing." but I am not sure what is meant by that.

@philipphofmann
Copy link
Member

This currently is very very simple: it just sends a breadcrumb with the action kCFTimeZoneSystemTimeZoneDidChangeNotification. Do we want to log the old and the new timezone as well?

What would be important to you as a developer?

Also the issue says "Ideally we persist previous runs breadcrumbs so steps from a previous run can help diagnose issues related to time changing." but I am not sure what is meant by that.

I added a comment #1763 (comment).

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First glance. Thanks for tackling this, @kevinrenskers.

CHANGELOG.md Outdated Show resolved Hide resolved
Sentry.xcodeproj/project.pbxproj Outdated Show resolved Hide resolved
kevinrenskers and others added 9 commits July 4, 2022 15:42
* master:
  build(deps): bump fastlane from 2.206.2 to 2.207.0 (#1937)
  fixing sample not compiling (#1935)
  style: Configure the root of the project to use four spaces for indentation (#1934)
  meta: Add LOGAF scale to Contributing (#1933)
  meta: Mention draft PRs in Contributing (#1932)
  meta: Add sut to contributing (#1931)
Provide a default value to deal with test crashes, until we can properly fix the tests
@kevinrenskers kevinrenskers marked this pull request as ready for review July 5, 2022 09:30
@kevinrenskers
Copy link
Contributor Author

kevinrenskers commented Jul 5, 2022

The feature works perfectly fine in the sample apps. Initially the timezone is nil, so we store it, no breadcrumb gets sent. From then on, every time the app starts it can detect timezone changes, and while the app is alive it'll also react to timezone changes, and sent breadcrumbs.

However, the test is problematic. First of all, because updating the app state doesn't work when there is no app state stored on disk yet. And there are other weird things going on with the file manager and the app state manager. Dhiogo can say more about that I think. I made the test pass consistently by adding a default value in SentrySystemEventBreadcrumbs on line 219, but that really shouldn't be necessary.

Also, this code only runs on iOS because the app state manager doesn't compile for macOS. Ideally this feature should work on macOS.

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done, not bad for not using ObjC for 6 years 😁👏 . Let's have a chat about how to test this at our meeting today.

Sources/Sentry/include/SentryAppState.h Outdated Show resolved Hide resolved
@@ -42,6 +43,8 @@ SENTRY_NO_INIT

@property (nonatomic, assign) BOOL isANROngoing;

@property (nonatomic, copy) NSNumber *_Nullable timezoneOffset;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: We use three different data types. In the constructor, timezoneOffset is NSTimeInterval, here it is NSNumber and [NSTimeZone localTimeZone].secondsFromGMT] is NSInteger. Can we please align these. I would suggest to use NSInteger everywhere and renaming this to secondsFromGMT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, the NSTimeInterval was from a different property I used for a while, that's easily changed to NSInteger.

But changing the NSNumber to NSInteger.. can NSInteger be null? I really need to refresh my knowledge of optionals in Obj-C 😅 I made it an NSNumber specifically because of the optionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and renaming this to secondsFromGMT

I think timezoneOffset is a lot more clear. secondsFromGMT doesn't really tell you that this about a timezone thing.

Sources/Sentry/SentryAppStateManager.m Outdated Show resolved Hide resolved
Tests/SentryTests/Helper/SentryAppStateTests.swift Outdated Show resolved Hide resolved
Sources/Sentry/SentrySystemEventBreadcrumbs.m Outdated Show resolved Hide resolved
Sources/Sentry/SentrySystemEventBreadcrumbs.m Outdated Show resolved Hide resolved
Sources/Sentry/SentrySystemEventBreadcrumbs.m Outdated Show resolved Hide resolved
Sources/Sentry/SentrySystemEventBreadcrumbs.m Outdated Show resolved Hide resolved
@philipphofmann
Copy link
Member

Also, this code only runs on iOS because the app state manager doesn't compile for macOS. Ideally this feature should work on macOS.

I would be fine with this tradeoff for now.

@kevinrenskers
Copy link
Contributor Author

Ok, got further along but testTimezoneChangeBreadcrumb is still problematic. It now always succeeds when I run it in isolation, but it fails when I run the entire SentrySystemEventBreadcrumbsTest class.

The idea is that I want to clear the stored timezone offset (from the filemanager), so that we always start with a clean slate. Then our mocked current date provider will say the timezone offset is 0, we initialize the SentrySystemEventBreadcrumbs (which will write the offset to disk), then we change the offset to another number and post the notification.

That all works in isolation, but not when running all the tests. Any ideas?

@kevinrenskers kevinrenskers force-pushed the feat/timezone-change-breadcrumbs branch from d4e51ad to 8ce9385 Compare July 6, 2022 08:37
@kevinrenskers
Copy link
Contributor Author

Tests are fixed, and more tests are added. I think this is ready for review now!

@kevinrenskers
Copy link
Contributor Author

Getting a random SentryANRTrackerTests failure in the Catalyst on Xcode 12 tests.

@philipphofmann
Copy link
Member

Getting a random SentryANRTrackerTests failure in the Catalyst on Xcode 12 tests.

Don't worry about these in this PR. It seems they are flaky and we should fix them.

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, just a few missing tests for SentryFileManager.

Sources/Sentry/SentryFileManager.m Show resolved Hide resolved
Sources/Sentry/SentryFileManager.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryFileManager.m Show resolved Hide resolved
Sources/Sentry/SentrySystemEventBreadcrumbs.m Show resolved Hide resolved
Sources/Sentry/SentrySystemEventBreadcrumbs.m Show resolved Hide resolved
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@kevinrenskers kevinrenskers merged commit 53e3805 into master Jul 6, 2022
@kevinrenskers kevinrenskers deleted the feat/timezone-change-breadcrumbs branch July 6, 2022 11:12
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.

Create a breadcrumb when system timezone changes
4 participants