Streamline analytics properties.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-07-26 14:58:58 -04:00
parent 013bf62f7c
commit f973af5a83
14 changed files with 34 additions and 150 deletions

View file

@ -263,7 +263,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
OWSProdErrorWNSError(@"app_delegate_error_failed_to_register_for_remote_notifications", error);
OWSProdError(@"app_delegate_error_failed_to_register_for_remote_notifications");
#ifdef DEBUG
DDLogWarn(@"%@ We're in debug mode. Faking success for remote registration with a fake push identifier", self.tag);
[PushManager.sharedManager.pushNotificationFutureSource trySetResult:[[NSMutableData dataWithLength:32] copy]];

View file

@ -35,8 +35,7 @@ static NSString *const OWS103EnableVideoCallingMigrationId = @"103";
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(
@"error_enable_video_calling_request_failed", error);
OWSProdError(@"error_enable_video_calling_request_failed");
}
DDLogError(@"%@ failed with error: %@", self.tag, error);
}];

View file

@ -151,7 +151,7 @@
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_update_attributes_request_failed", error);
OWSProdError(@"error_update_attributes_request_failed");
}
success = NO;
DDLogError(@"Updating attributess failed with error: %@", error.description);

View file

@ -160,7 +160,7 @@ NSString *const kNSNotificationName_LocalNumberDidChange = @"kNSNotificationName
remainingRetries:remainingRetries - 1];
} else {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"accounts_error_register_push_tokens_failed", error);
OWSProdError(@"accounts_error_register_push_tokens_failed");
}
failureHandler(error);
}
@ -197,7 +197,7 @@ NSString *const kNSNotificationName_LocalNumberDidChange = @"kNSNotificationName
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"accounts_error_verification_code_request_failed", error);
OWSProdError(@"accounts_error_verification_code_request_failed");
}
DDLogError(@"%@ Failed to request verification code request with error:%@", self.tag, error);
failureBlock(error);
@ -270,7 +270,7 @@ NSString *const kNSNotificationName_LocalNumberDidChange = @"kNSNotificationName
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"accounts_error_verify_account_request_failed", error);
OWSProdError(@"accounts_error_verify_account_request_failed");
}
DDLogWarn(@"%@ Error verifying code: %@", self.tag, error.debugDescription);
switch (error.code) {
@ -326,7 +326,7 @@ NSString *const kNSNotificationName_LocalNumberDidChange = @"kNSNotificationName
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"accounts_error_unregister_account_request_failed", error);
OWSProdError(@"accounts_error_unregister_account_request_failed");
}
DDLogError(@"%@ Failed to unregister with error: %@", self.tag, error);
failureBlock(error);

View file

@ -183,9 +183,9 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
if (modeCopy == RefreshPreKeysMode_SignedAndOneTime) {
OWSProdErrorWNSError(@"error_prekeys_update_failed_signed_and_onetime", error);
OWSProdError(@"error_prekeys_update_failed_signed_and_onetime");
} else {
OWSProdErrorWNSError(@"error_prekeys_update_failed_just_signed", error);
OWSProdError(@"error_prekeys_update_failed_just_signed");
}
}
@ -305,7 +305,7 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_prekeys_current_signed_prekey_request_failed", error);
OWSProdError(@"error_prekeys_current_signed_prekey_request_failed");
}
DDLogWarn(@"%@ Could not retrieve current signed key from the service.", self.tag);
@ -316,7 +316,7 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_prekeys_available_prekeys_request_failed", error);
OWSProdError(@"error_prekeys_available_prekeys_request_failed");
}
DDLogError(@"%@ Failed to retrieve the number of available prekeys.", self.tag);
@ -401,12 +401,11 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
}
}
OWSProdInfoWParams(@"prekeys_deleted_old_signed_prekey", ^{
return (@{
@"generated" : [dateFormatter stringFromDate:signedPrekey.generatedAt],
@"accepted" : @(signedPrekey.wasAcceptedByService),
});
});
if (signedPrekey.wasAcceptedByService) {
OWSProdInfo(@"prekeys_deleted_old_accepted_signed_prekey");
} else {
OWSProdInfo(@"prekeys_deleted_old_unaccepted_signed_prekey");
}
oldSignedPreKeyCount--;
[storageManager removeSignedPreKey:signedPrekey.Id];

View file

@ -206,7 +206,7 @@ NS_ASSUME_NONNULL_BEGIN
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"contacts_error_contacts_intersection_failed", error);
OWSProdError(@"contacts_error_contacts_intersection_failed");
}
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;

View file

@ -187,7 +187,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_attachment_request_failed", error);
OWSProdError(@"error_attachment_request_failed");
}
DDLogError(@"Failed retrieval of attachment with error: %@", error);
if (attachment.serverId < 100) {

View file

@ -539,7 +539,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSError *error;
[attachmentStream writeData:dataCopy error:&error];
if (error) {
OWSProdErrorWNSError(@"message_sender_error_could_not_write_attachment", error);
OWSProdError(@"message_sender_error_could_not_write_attachment");
return failureHandler(error);
}
@ -652,7 +652,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
[self unregisteredRecipient:recipient message:message thread:thread];
}
OWSProdErrorWNSError(@"message_sender_error_could_not_find_contacts_3", error);
OWSProdError(@"message_sender_error_could_not_find_contacts_3");
// No need to repeat trying to find a failure. Apart from repeatedly failing, it would also cause us
// to print redundant error messages.
[error setIsRetryable:NO];
@ -1013,7 +1013,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSDictionary *serializedResponse =
[NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
if (error) {
OWSProdErrorWNSError(@"message_sender_error_could_not_parse_mismatched_devices_json", error);
OWSProdError(@"message_sender_error_could_not_parse_mismatched_devices_json");
[error setIsRetryable:YES];
return failureHandler(error);
}
@ -1217,7 +1217,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"message_sender_error_recipient_prekey_request_failed", error);
OWSProdError(@"message_sender_error_recipient_prekey_request_failed");
}
DDLogError(@"Server replied to PreKeyBundle request with error: %@", error);
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
@ -1290,7 +1290,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSDictionary *jsonDict = [MTLJSONAdapter JSONDictionaryFromModel:messageParams error:&error];
if (error) {
OWSProdErrorWNSError(@"message_send_error_could_not_serialize_message_json", error);
OWSProdError(@"message_send_error_could_not_serialize_message_json");
return nil;
}

View file

@ -42,22 +42,6 @@
NS_ASSUME_NONNULL_BEGIN
#define kOWSAnalyticsParameterEnvelopeIsLegacy @"envelope_is_legacy"
#define kOWSAnalyticsParameterEnvelopeHasContent @"has_content"
#define kOWSAnalyticsParameterEnvelopeType @"envelope_type"
#define kOWSAnalyticsParameterEnvelopeEncryptedLength @"encrypted_length"
#define AnalyticsParametersFromEnvelope(__envelope) \
^{ \
NSData *__encryptedData = __envelope.hasContent ? __envelope.content : __envelope.legacyMessage; \
return (@{ \
kOWSAnalyticsParameterEnvelopeIsLegacy : @(__envelope.hasLegacyMessage), \
kOWSAnalyticsParameterEnvelopeHasContent : @(__envelope.hasContent), \
kOWSAnalyticsParameterEnvelopeType : [self descriptionForEnvelopeType:__envelope], \
kOWSAnalyticsParameterEnvelopeEncryptedLength : @(__encryptedData.length), \
}); \
}
// The debug logs can be more verbose than the analytics events.
//
// In this case `descriptionForEnvelope` is valuable enough to
@ -69,7 +53,7 @@ NS_ASSUME_NONNULL_BEGIN
__LINE__, \
__analyticsEventName, \
[self descriptionForEnvelope:__envelope]); \
OWSProdErrorWParams(__analyticsEventName, AnalyticsParametersFromEnvelope(__envelope)) \
OWSProdError(__analyticsEventName) \
}
@interface TSMessagesManager ()
@ -371,7 +355,7 @@ NS_ASSUME_NONNULL_BEGIN
}
} @catch (NSException *exception) {
DDLogError(@"Received an incorrectly formatted protocol buffer: %@", exception.debugDescription);
OWSProdFailWNSException(@"message_manager_error_invalid_protocol_message", exception);
OWSProdFail(@"message_manager_error_invalid_protocol_message");
}
completion();
@ -410,11 +394,7 @@ NS_ASSUME_NONNULL_BEGIN
NSUInteger kMaxEncryptedDataLength = 250 * 1024;
if (encryptedData.length > kMaxEncryptedDataLength) {
OWSProdErrorWParams(@"message_manager_error_oversize_message", ^{
return (@{
@"message_size" : @([OWSAnalytics orderOfMagnitudeOf:(long)encryptedData.length]),
});
});
OWSProdError(@"message_manager_error_oversize_message");
completion(nil);
return;
}

View file

@ -51,7 +51,7 @@ NSString *const OWSDeviceProvisioningCodeServiceProvisioningCodeKey = @"verifica
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_provisioning_code_request_failed", error);
OWSProdError(@"error_provisioning_code_request_failed");
}
DDLogVerbose(@"ProvisioningCode request failed with error: %@", error);
failureCallback(error);

View file

@ -48,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_provisioning_request_failed", error);
OWSProdError(@"error_provisioning_request_failed");
}
DDLogVerbose(@"Provisioning request failed with error: %@", error);
failureCallback(error);

View file

@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_get_devices_failed", error);
OWSProdError(@"error_get_devices_failed");
}
DDLogVerbose(@"Get devices request failed with error: %@", error);
failureCallback(error);
@ -53,7 +53,7 @@ NS_ASSUME_NONNULL_BEGIN
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_unlink_device_failed", error);
OWSProdError(@"error_unlink_device_failed");
}
DDLogVerbose(@"Get devices request failed with error: %@", error);
failureCallback(error);

View file

@ -86,11 +86,7 @@ static NSString *keychainDBPassAccount = @"TSDatabasePass";
- (nullable Class)unarchiver:(NSKeyedUnarchiver *)unarchiver cannotDecodeObjectOfClassName:(NSString *)name originalClasses:(NSArray<NSString *> *)classNames
{
OWSProdErrorWParams(@"storage_error_could_not_decode_class", ^{
return (@{
@"class_name" : name,
});
});
OWSProdError(@"storage_error_could_not_decode_class");
return [OWSUnknownObject class];
}
@ -187,14 +183,7 @@ static NSString *keychainDBPassAccount = @"TSDatabasePass";
return [unarchiver decodeObjectForKey:@"root"];
} @catch (NSException *exception) {
// Sync log in case we bail.
OWSProdErrorWParams(@"storage_error_deserialization", ^{
return (@{
@"collection" : collection,
kOWSAnalyticsParameterNSExceptionName : exception.name,
kOWSAnalyticsParameterNSExceptionReason : exception.reason,
kOWSAnalyticsParameterNSExceptionClassName : NSStringFromClass([exception class]),
});
});
OWSProdError(@"storage_error_deserialization");
@throw exception;
}
};
@ -264,7 +253,7 @@ static NSString *keychainDBPassAccount = @"TSDatabasePass";
BOOL success = [ressourceURL setResourceValues:resourcesAttrs error:&error];
if (error || !success) {
OWSProdCriticalWNSError(@"storage_error_file_protection", error);
OWSProdCritical(@"storage_error_file_protection");
}
}
@ -383,7 +372,7 @@ static NSString *keychainDBPassAccount = @"TSDatabasePass";
NSError *keySetError;
[SAMKeychain setPassword:newDBPassword forService:keychainService account:keychainDBPassAccount error:&keySetError];
if (keySetError) {
OWSProdCriticalWNSError(@"storage_error_could_not_store_database_password", keySetError);
OWSProdCritical(@"storage_error_could_not_store_database_password");
[self deletePasswordFromKeychain];

View file

@ -44,33 +44,6 @@ typedef NS_ENUM(NSUInteger, OWSAnalyticsSeverity) {
typedef NSDictionary<NSString *, id> *_Nonnull (^OWSProdAssertParametersBlock)();
#define kOWSAnalyticsParameterDescription @"description"
#define kOWSAnalyticsParameterNSErrorDomain @"nserror_domain"
#define kOWSAnalyticsParameterNSErrorCode @"nserror_code"
#define kOWSAnalyticsParameterNSErrorDescription @"nserror_description"
#define kOWSAnalyticsParameterNSExceptionName @"nsexception_name"
#define kOWSAnalyticsParameterNSExceptionReason @"nsexception_reason"
#define kOWSAnalyticsParameterNSExceptionClassName @"nsexception_classname"
// We don't include the error description because it may have PII.
#define AnalyticsParametersFromNSError(__nserror) \
^{ \
return (@{ \
kOWSAnalyticsParameterNSErrorDomain : (__nserror.domain ?: @"unknown"), \
kOWSAnalyticsParameterNSErrorCode : @(__nserror.code), \
}); \
}
#define AnalyticsParametersFromNSException(__exception) \
^{ \
return (@{ \
kOWSAnalyticsParameterNSExceptionName : (__exception.name ?: @"unknown"), \
kOWSAnalyticsParameterNSExceptionReason : (__exception.reason ?: @"unknown"), \
kOWSAnalyticsParameterNSExceptionClassName : \
(__exception ? NSStringFromClass([__exception class]) : @"unknown"), \
}); \
}
// These methods should be used to assert errors for which we want to fire analytics events.
//
// In production, returns __Value, the assert value, so that we can handle this case.
@ -125,26 +98,6 @@ typedef NSDictionary<NSString *, id> *_Nonnull (^OWSProdAssertParametersBlock)()
#define OWSProdCFail(__eventName) OWSProdCFailWParams(__eventName, nil)
// The debug logs can be more verbose than the analytics events.
//
// In this case `debugDescription` is valuable enough to
// log but too dangerous to include in the analytics event.
#define OWSProdFailWNSError(__eventName, __nserror) \
{ \
DDLogError(@"%s:%d %@: %@", __PRETTY_FUNCTION__, __LINE__, __eventName, __nserror.debugDescription); \
OWSProdFailWParams(__eventName, AnalyticsParametersFromNSError(__nserror)) \
}
// The debug logs can be more verbose than the analytics events.
//
// In this case `exception` is valuable enough to
// log but too dangerous to include in the analytics event.
#define OWSProdFailWNSException(__eventName, __exception) \
{ \
DDLogError(@"%s:%d %@: %@", __PRETTY_FUNCTION__, __LINE__, __eventName, __exception); \
OWSProdFailWParams(__eventName, AnalyticsParametersFromNSException(__exception)) \
}
#define OWSProdCFail(__eventName) OWSProdCFailWParams(__eventName, nil)
#define OWSProdEventWParams(__severityLevel, __eventName, __parametersBlock) \
@ -172,26 +125,6 @@ typedef NSDictionary<NSString *, id> *_Nonnull (^OWSProdAssertParametersBlock)()
#define OWSProdError(__eventName) OWSProdEventWParams(OWSAnalyticsSeverityError, __eventName, nil)
// The debug logs can be more verbose than the analytics events.
//
// In this case `debugDescription` is valuable enough to
// log but too dangerous to include in the analytics event.
#define OWSProdErrorWNSError(__eventName, __nserror) \
{ \
DDLogError(@"%s:%d %@: %@", __PRETTY_FUNCTION__, __LINE__, __eventName, __nserror.debugDescription); \
OWSProdErrorWParams(__eventName, AnalyticsParametersFromNSError(__nserror)) \
}
// The debug logs can be more verbose than the analytics events.
//
// In this case `exception` is valuable enough to
// log but too dangerous to include in the analytics event.
#define OWSProdErrorWNSException(__eventName, __exception) \
{ \
DDLogError(@"%s:%d %@: %@", __PRETTY_FUNCTION__, __LINE__, __eventName, __exception); \
OWSProdErrorWParams(__eventName, AnalyticsParametersFromNSException(__exception)) \
}
#pragma mark - Critical Events
#define OWSProdCriticalWParams(__eventName, __parametersBlock) \
@ -199,20 +132,4 @@ typedef NSDictionary<NSString *, id> *_Nonnull (^OWSProdAssertParametersBlock)()
#define OWSProdCritical(__eventName) OWSProdEventWParams(OWSAnalyticsSeverityCritical, __eventName, nil)
#define OWSProdCriticalWNSError(__eventName, __nserror) \
{ \
DDLogError(@"%s:%d %@: %@", __PRETTY_FUNCTION__, __LINE__, __eventName, __nserror.debugDescription); \
OWSProdCriticalWParams(__eventName, AnalyticsParametersFromNSError(__nserror)) \
}
// The debug logs can be more verbose than the analytics events.
//
// In this case `exception` is valuable enough to
// log but too dangerous to include in the analytics event.
#define OWSProdCriticalWNSException(__eventName, __exception) \
{ \
DDLogError(@"%s:%d %@: %@", __PRETTY_FUNCTION__, __LINE__, __eventName, __exception); \
OWSProdCriticalWParams(__eventName, AnalyticsParametersFromNSException(__exception)) \
}
NS_ASSUME_NONNULL_END