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

Track non-fatal issues via analytics if consent provided #1503

Merged
merged 2 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions MatrixSDK/Utils/MXAnalyticsDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ NS_ASSUME_NONNULL_BEGIN
isReply:(BOOL)isReply
startsThread:(BOOL)startsThread;

#pragma mark - Health metrics

/**
Report a non-fatal issue, i.e. an internal error that did not result in a crash

@param issue the description of the issue that occured
@param details a dictionary of additional context-dependent details about the issue
*/
- (void)trackNonFatalIssue:(NSString *)issue
details:(nullable NSDictionary <NSString *, id> *)details;

@end

NS_ASSUME_NONNULL_END
Expand Down
6 changes: 5 additions & 1 deletion MatrixSDK/Utils/MXLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@
}

#define MXLogFailure(message, ...) { \
[MXLogObjcWrapper logFailure:[NSString stringWithFormat: message, ##__VA_ARGS__] file:@__FILE__ function:[NSString stringWithFormat:@"%s", __FUNCTION__] line:__LINE__]; \
[MXLogObjcWrapper logFailure:[NSString stringWithFormat: message, ##__VA_ARGS__] details:nil file:@__FILE__ function:[NSString stringWithFormat:@"%s", __FUNCTION__] line:__LINE__]; \
}

#define MXLogFailureWithDetails(message, dictionary) { \
[MXLogObjcWrapper logFailure:message details:dictionary file:@__FILE__ function:[NSString stringWithFormat:@"%s", __FUNCTION__] line:__LINE__]; \
}
11 changes: 8 additions & 3 deletions MatrixSDK/Utils/MXLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,24 @@ private var logger: SwiftyBeaver.Type = {
logger.error(message, file, function, line: line)
}

public static func failure(_ message: @autoclosure () -> Any, _
file: String = #file, _ function: String = #function, line: Int = #line, context: Any? = nil) {
public static func failure(_ message: @autoclosure () -> Any,
details: @autoclosure () -> [String: Any]? = nil,
_ file: String = #file, _ function: String = #function, line: Int = #line, context: Any? = nil) {
logger.error(message(), file, function, line: line, context: context)
#if DEBUG
assertionFailure("\(message())")
#else
MXSDKOptions.sharedInstance().analyticsDelegate?.trackNonFatalIssue("\(message())", details: details())
#endif
}

@available(swift, obsoleted: 5.4)
@objc public static func logFailure(_ message: String, file: String, function: String, line: Int) {
@objc public static func logFailure(_ message: String, details: [String: Any]? = nil, file: String, function: String, line: Int) {
logger.error(message, file, function, line: line)
#if DEBUG
assertionFailure(message)
#else
MXSDKOptions.sharedInstance().analyticsDelegate?.trackNonFatalIssue(message, details: details)
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Utils/MXLogObjcWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN

+ (void)logError:(NSString *)message file:(NSString *)file function:(NSString *)function line:(NSUInteger)line;

+ (void)logFailure:(NSString *)message file:(NSString *)file function:(NSString *)function line:(NSUInteger)line;
+ (void)logFailure:(NSString *)message details:(nullable NSDictionary<NSString *, id> *)details file:(NSString *)file function:(NSString *)function line:(NSUInteger)line;

@end

Expand Down
4 changes: 2 additions & 2 deletions MatrixSDK/Utils/MXLogObjcWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ + (void)logError:(NSString *)message file:(NSString *)file function:(NSString *)
[MXLog logError:message file:file function:function line:line];
}

+ (void)logFailure:(NSString *)message file:(NSString *)file function:(NSString *)function line:(NSUInteger)line
+ (void)logFailure:(NSString *)message details:(nullable NSDictionary<NSString *, id> *)details file:(NSString *)file function:(NSString *)function line:(NSUInteger)line
{
[MXLog logFailure:message file:file function:function line:line];
[MXLog logFailure:message details:details file:file function:function line:line];
}

@end
1 change: 1 addition & 0 deletions changelog.d/pr-1503.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Analytics: Track non-fatal issues if consent provided