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

chore(mac): add breadcrumbs for Sentry #12939

Merged
merged 11 commits into from
Jan 28, 2025
Merged

Conversation

sgschantz
Copy link
Contributor

@sgschantz sgschantz commented Jan 17, 2025

Add additional context (breadcrumbs and new custom tags) to help understand the cause of Sentry issues.

Also change the mechanism to force a crash being reported to Sentry and adds a command to cause a captureMessage call to Sentry.

To enable the Sentry tests, set the flag in UserDefaults by exectuting the following command in terminal:
defaults write keyman.inputmethod.Keyman KMForceSentryError 1

Then with the SIL Euro Latin keyboard type one of the following two characters in the Stickies app:
{ - to generate a crash event
[ - to generate a message capture event

Fixes #11623

@keymanapp-test-bot skip

can now force crashes or send messages by typing a
single character when sentry testing is enabled
in the UserDefaults
@sgschantz sgschantz added the mac/ label Jan 17, 2025
@sgschantz sgschantz added this to the A18S20 milestone Jan 17, 2025
@sgschantz sgschantz self-assigned this Jan 17, 2025
@keymanapp-test-bot
Copy link

keymanapp-test-bot bot commented Jan 17, 2025

User Test Results

Test specification and instructions

User tests are not required

Test Artifacts

@github-actions github-actions bot added the chore label Jan 17, 2025
@sgschantz sgschantz marked this pull request as ready for review January 22, 2025 05:53
@sgschantz sgschantz requested a review from SabineSIL as a code owner January 22, 2025 05:53
[self.activeKeyboards addObject:partialPath];
[self saveActiveKeyboards];
}
else if (checkBox.state == NSOffState) {
os_log_debug([KMLogs uiLog], "Disabling active keyboard: %{public}@", kmxFilePath);
os_log_debug([KMLogs uiLog], "disabling active keyboard: %{public}@", kmxFileName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be easier if addUserBreadCrumb happened inside os_log_debug()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

os_log_debug is a macOS API, so I can't combine there. I'd like to combine Sentry and macOS logging in a single call, but I am also instructed not to wrap the macOS API call because it tracks the location. So if I leave it in place, I would only be wrapping Sentry (which I am essentially doing to simplify it) and that still leaves two function calls from the location I want to log.

Comment on lines +213 to +224
/**
* Determine whether to force sentry events.
* When true, then typing certain characters will cause Sentry events or crashes to occur.
*
* To enable, set the flag in UserDefaults
* `defaults write keyman.inputmethod.Keyman KMForceSentryError 1`
* Also, use the SIL Euro Latin keyboard and type in the Stickies app
*/
- (BOOL)canForceSentryEvents {
NSString* const testKeyboardName = @"sil_euro_latin.kmx";
NSString* const testClientApplicationId = @"com.apple.Stickies";
BOOL canForce = NO;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you include this change in the PR description? (Makes the developer testing more visible).

Ideally, this could have been separated from the Sentry breadcrumbs PR so it shows in HISTORY.md.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

@@ -0,0 +1,29 @@
/*
* Keyman is copyright (C) SIL International. MIT License.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit on new source files to use "SIL Global" instead of "SIL International"

Comment on lines 64 to 87
+ (void)addBreadCrumb:(NSString *)category message:(NSString *)messageText {
SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc] init];
crumb.level = kSentryLevelInfo;
crumb.category = category;
crumb.message = messageText;
[SentrySDK addBreadcrumb:crumb];
}

+ (void)addDebugBreadCrumb:(NSString *)category message:(NSString *)messageText {
SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc] init];
crumb.level = kSentryLevelDebug;
crumb.category = category;
crumb.message = messageText;
[SentrySDK addBreadcrumb:crumb];
}

+ (void)addUserBreadCrumb:(NSString *)category message:(NSString *)messageText {
SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc] init];
crumb.type = @"user";
crumb.level = kSentryLevelInfo;
crumb.category = category;
crumb.message = messageText;
[SentrySDK addBreadcrumb:crumb];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be cleaner to refactor these into a single function (with a level and an optional type parameters)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take a look at simplifying this. I'm applying an interesting cross section of arguments, and I'd rather have multiple different functions with fewer parameters because that would easier to read in the client code. I should still be able to eliminate duplication in the wrapper at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added comments and removed one method not being used, but I think the three functions available are sufficient and would be cleaner from the caller's perspective than creating a variadic function. Also, the duplication is pretty minimal and probably not worth complicating the code to reduce it.

[self.deleteAlertView setMessageText:[NSString localizedStringWithFormat:deleteKeyboardMessage, keyboardName]];
} else {
keyboardName = [info objectForKey:kKMKeyboardNameKey];
[self.deleteAlertView setMessageText:[NSString localizedStringWithFormat:deleteKeyboardMessage, keyboardName]];
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is identical to l.421, can they be pulled out of the if/else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, thanks for spotting that!

@@ -9,6 +9,7 @@
#import "KMDownloadKBWindowController.h"
#import "KMInputMethodAppDelegate.h"
#import "KMLogs.h"
#import "KMSentryHelper.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, I'll remove

Comment on lines +14 to +21
NSString * const kApiComplianceTagName = @"apiCompliance";
NSString * const kArchitectureTagName = @"architecture";
NSString * const kOskVisibleTagName = @"oskVisible";
NSString * const kClientAppIdTagName = @"clientAppId";
NSString * const kKeyboardTagName = @"keyboard";
NSString * const kHasAccessibilityTagName = @"accessibilityEnabled";
NSString * const kActiveKeyboardCountTagName = @"activeKeyboardCount";
NSString * const kLifecycleStateTagName = @"lifecycleState";
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these get sent to Sentry?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, all are sent to Sentry with the setTagValue API

Copy link
Contributor

@darcywong00 darcywong00 left a comment

Choose a reason for hiding this comment

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

lgtm

@sgschantz sgschantz merged commit 8972040 into master Jan 28, 2025
5 checks passed
@sgschantz sgschantz deleted the chore/mac/11623-add-breadcrumbs branch January 28, 2025 05:09
@keyman-server
Copy link
Collaborator

Changes in this pull request will be available for download in Keyman version 18.0.179-alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

chore(mac): add Sentry breadcrumbs
3 participants