-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Conversation
can now force crashes or send messages by typing a single character when sentry testing is enabled in the UserDefaults
User Test ResultsTest specification and instructions User tests are not required Test Artifacts
|
resolves link error when running unit tests
…/github.com/keymanapp/keyman into chore/mac/11623-add-breadcrumbs
[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); |
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.
Would it be easier if addUserBreadCrumb
happened inside os_log_debug()
?
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.
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.
/** | ||
* 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; |
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.
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.
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.
will do
@@ -0,0 +1,29 @@ | |||
/* | |||
* Keyman is copyright (C) SIL International. MIT License. |
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.
Nit on new source files to use "SIL Global" instead of "SIL International"
+ (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]; | ||
} |
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.
Would it be cleaner to refactor these into a single function (with a level and an optional type parameters)?
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.
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.
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.
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]]; |
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.
If this is identical to l.421, can they be pulled out of the if/else?
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.
yes, thanks for spotting that!
@@ -9,6 +9,7 @@ | |||
#import "KMDownloadKBWindowController.h" | |||
#import "KMInputMethodAppDelegate.h" | |||
#import "KMLogs.h" | |||
#import "KMSentryHelper.h" |
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.
Is this used?
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.
nope, I'll remove
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"; |
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.
Do these get sent to Sentry?
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.
yes, all are sent to Sentry with the setTagValue
API
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
Changes in this pull request will be available for download in Keyman version 18.0.179-alpha |
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