2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 #import <CloudKit/CloudKit.h>
27 #import <CloudKit/CloudKit_Private.h>
30 #import "keychain/ckks/CKKSAnalytics.h"
31 #import "keychain/ot/OTDefines.h"
32 #import "keychain/ckks/CKKS.h"
33 #import "keychain/ckks/CKKSViewManager.h"
34 #import "keychain/ckks/CKKSKeychainView.h"
35 #include <utilities/SecFileLocations.h>
38 NSString* const CKKSAnalyticsInCircle = @"inCircle";
39 NSString* const CKKSAnalyticsHasTLKs = @"TLKs";
40 NSString* const CKKSAnalyticsSyncedClassARecently = @"inSyncA";
41 NSString* const CKKSAnalyticsSyncedClassCRecently = @"inSyncC";
42 NSString* const CKKSAnalyticsIncomingQueueIsErrorFree = @"IQNOE";
43 NSString* const CKKSAnalyticsOutgoingQueueIsErrorFree = @"OQNOE";
44 NSString* const CKKSAnalyticsInSync = @"inSync";
45 NSString* const CKKSAnalyticsValidCredentials = @"validCredentials";
46 NSString* const CKKSAnalyticsLastUnlock = @"lastUnlock";
47 NSString* const CKKSAnalyticsLastKeystateReady = @"lastKSR";
48 NSString* const CKKSAnalyticsLastInCircle = @"lastInCircle";
50 NSString* const OctagonAnalyticsStateMachineState = @"OASMState";
51 NSString* const OctagonAnalyticIcloudAccountState = @"OAiC";
52 NSString* const OctagonAnalyticCDPBitStatus = @"OACDPStatus";
54 NSString* const OctagonAnalyticsTrustState = @"OATrust";
55 NSString* const OctagonAnalyticsAttemptedJoin = @"OAAttemptedJoin";
56 NSString* const OctagonAnalyticsUserControllableViewsSyncing = @"OAUserViewsSyncing";
57 NSString* const OctagonAnalyticsLastHealthCheck = @"OAHealthCheck";
58 NSString* const OctagonAnalyticsSOSStatus = @"OASOSStatus";
59 NSString* const OctagonAnalyticsDateOfLastPreflightPreapprovedJoin = @"OALastPPJ";
60 NSString* const OctagonAnalyticsLastKeystateReady = @"OALastKSR";
61 NSString* const OctagonAnalyticsLastCoreFollowup = @"OALastCFU";
62 //NSString* const OctagonAnalyticsCoreFollowupStatus = @"OACFUStatus";
63 NSString* const OctagonAnalyticsCoreFollowupFailureCount = @"OACFUTFailureCount";
64 NSString* const OctagonAnalyticsCoreFollowupLastFailureTime = @"OACFULastFailureTime";
65 NSString* const OctagonAnalyticsPrerecordPending = @"OAPrerecordPending";
66 NSString* const OctagonAnalyticsCDPStateRun = @"OACDPStateRun";
68 NSString* const OctagonAnalyticsBottledUniqueTLKsRecovered = @"OABottledUniqueTLKsRecoveredCount";
69 NSString* const OctagonAnalyticsBottledTotalTLKShares = @"OABottledTotalTLKSharesCount";
70 NSString* const OctagonAnalyticsBottledTotalTLKSharesRecovered = @"OABottledTotalTLKSharesRecoveredCount";
71 NSString* const OctagonAnalyticsBottledUniqueTLKsWithSharesCount = @"OABottledUniqueTLKsWithSharesCount";
72 NSString* const OctagonAnalyticsBottledTLKUniqueViewCount = @"OABottledTLKUniqueViewCount";
74 NSString* const OctagonAnalyticsHaveMachineID = @"OAMIDPresent";
75 NSString* const OctagonAnalyticsMIDOnMemoizedList = @"OAMIDOnList";
76 NSString* const OctagonAnalyticsPeersWithMID = @"OAPeersWithMID";
78 NSString* const CKKSAnalyticsLastCKKSPush = @"lastCKKSPush";
79 NSString* const CKKSAnalyticsLastOctagonPush = @"lastOctagonPush";
81 NSString* const OctagonAnalyticsKVSProvisioned = @"OADCKVSProvisioned";
82 NSString* const OctagonAnalyticsKVSEnabled = @"OADCKVSEnabled";
83 NSString* const OctagonAnalyticsKeychainSyncProvisioned = @"OADCKCSProvisioned";
84 NSString* const OctagonAnalyticsKeychainSyncEnabled = @"OADCKCSEnabled";
85 NSString* const OctagonAnalyticsCloudKitProvisioned = @"OADCCKProvisioned";
86 NSString* const OctagonAnalyticsCloudKitEnabled = @"OADCCKEnabled";
88 static NSString* const CKKSAnalyticsAttributeRecoverableError = @"recoverableError";
89 static NSString* const CKKSAnalyticsAttributeZoneName = @"zone";
90 static NSString* const CKKSAnalyticsAttributeErrorDomain = @"errorDomain";
91 static NSString* const CKKSAnalyticsAttributeErrorCode = @"errorCode";
92 static NSString* const CKKSAnalyticsAttributeErrorChain = @"errorChain";
94 CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassA = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessIncomingQueueClassA";
95 CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassC = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessIncomingQueueClassC";
96 CKKSAnalyticsFailableEvent* const CKKSEventProcessOutgoingQueue = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessOutgoingQueue";
97 CKKSAnalyticsFailableEvent* const CKKSEventUploadChanges = (CKKSAnalyticsFailableEvent*)@"CKKSEventUploadChanges";
98 CKKSAnalyticsFailableEvent* const CKKSEventStateError = (CKKSAnalyticsFailableEvent*)@"CKKSEventStateError";
99 CKKSAnalyticsFailableEvent* const CKKSEventProcessHealKeyHierarchy = (CKKSAnalyticsFailableEvent *)@"CKKSEventProcessHealKeyHierarchy";
100 CKKSAnalyticsFailableEvent* const CKKSEventProcessReencryption = (CKKSAnalyticsFailableEvent *)@"CKKSEventProcessReencryption";
102 NSString* const OctagonEventFailureReason = @"FailureReason";
104 CKKSAnalyticsFailableEvent* const OctagonEventPreflightBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightBottle";
105 CKKSAnalyticsFailableEvent* const OctagonEventLaunchBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventLaunchBottle";
106 CKKSAnalyticsFailableEvent* const OctagonEventRestoreBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventRestoreBottle";
107 CKKSAnalyticsFailableEvent* const OctagonEventScrubBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventScrubBottle";
108 CKKSAnalyticsFailableEvent* const OctagonEventSignIn = (CKKSAnalyticsFailableEvent *)@"OctagonEventSignIn";
109 CKKSAnalyticsFailableEvent* const OctagonEventSignOut = (CKKSAnalyticsFailableEvent *)@"OctagonEventSignIn";
110 CKKSAnalyticsFailableEvent* const OctagonEventRamp = (CKKSAnalyticsFailableEvent *)@"OctagonEventRamp";
111 CKKSAnalyticsFailableEvent* const OctagonEventBottleCheck = (CKKSAnalyticsFailableEvent *)@"OctagonEventBottleCheck";
112 CKKSAnalyticsFailableEvent* const OctagonEventCoreFollowUp = (CKKSAnalyticsFailableEvent *)@"OctagonEventCoreFollowUp";
113 CKKSAnalyticsFailableEvent* const OctagonEventUpdateBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpdateBottle";
115 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustState = (CKKSAnalyticsFailableEvent *)@"OctagonEventCheckTrustState";
117 CKKSAnalyticsFailableEvent* const OctagonEventBottledPeerRestore = (CKKSAnalyticsFailableEvent*)@"OctagonEventBottledPeerRestore";
118 CKKSAnalyticsFailableEvent* const OctagonEventRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventRecoveryKey";
120 CKKSAnalyticsFailableEvent* const OctagonEventFetchAllBottles = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchAllBottles";
121 CKKSAnalyticsFailableEvent* const OctagonEventFetchEscrowContents = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchEscrowContents";
122 CKKSAnalyticsFailableEvent* const OctagonEventResetAndEstablish = (CKKSAnalyticsFailableEvent*)@"OctagonEventResetAndEstablish";
123 CKKSAnalyticsFailableEvent* const OctagonEventEstablish = (CKKSAnalyticsFailableEvent*)@"OctagonEventEstablish";
124 CKKSAnalyticsFailableEvent* const OctagonEventLeaveClique = (CKKSAnalyticsFailableEvent*)@"OctagonEventLeaveClique";
125 CKKSAnalyticsFailableEvent* const OctagonEventRemoveFriendsInClique = (CKKSAnalyticsFailableEvent*)@"OctagonEventRemoveFriendsInClique";
127 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeFetchDeviceIDs = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeFetchDeviceIDs";
128 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSetAllowList = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeSetAllowList";
129 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSilentEscrow = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeSilentEscrow";
130 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoin = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreapprovedJoin";
131 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreflightPreapprovedJoin = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreflightPreapprovedJoin";
132 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoinAfterPairing = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreapprovedJoinAfterPairing";
133 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePrepare = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePrepare";
135 CKKSAnalyticsFailableEvent* const OctagonEventJoinWithVoucher = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinWithVoucher";
137 CKKSAnalyticsFailableEvent* const OctagonEventPreflightVouchWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightVouchWithBottle";
138 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithBottle";
140 CKKSAnalyticsFailableEvent* const OctagonEventPreflightVouchWithRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightVouchWithRecoveryKey";;
141 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithRecoveryKey";
143 CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventSetRecoveryKey";
145 CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKeyValidationFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventSetRecoveryKeyValidationFailed";
146 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyValidationFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyValidationFailed";
147 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleReset = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyCircleReset";
148 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleResetFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyCircleResetFailed";
149 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyEnrollFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyEnrollFailed";
150 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyFailed";
152 CKKSAnalyticsFailableEvent* const OctagonEventReset = (CKKSAnalyticsFailableEvent*)@"OctagonEventReset";
154 CKKSAnalyticsFailableEvent* const OctagonEventPrepareIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventPrepareIdentity";
156 CKKSAnalyticsFailableEvent* const OctagonEventEstablishIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventEstablishIdentity";
157 CKKSAnalyticsFailableEvent* const OctagonEventFetchViews = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchViews";
159 CKKSAnalyticsFailableEvent* const OctagonEventStateTransition = (CKKSAnalyticsFailableEvent*)@"OctagonEventStateTransition";
161 CKKSAnalyticsFailableEvent* const OctagonEventCompanionPairing = (CKKSAnalyticsFailableEvent*)@"OctagonEventCompanionPairing";
163 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustForCFU = (CKKSAnalyticsFailableEvent*)@"OctagonEventCheckTrustForCFU";
165 CKKSAnalyticsSignpostEvent* const CKKSEventPushNotificationReceived = (CKKSAnalyticsSignpostEvent*)@"CKKSEventPushNotificationReceived";
166 CKKSAnalyticsSignpostEvent* const CKKSEventItemAddedToOutgoingQueue = (CKKSAnalyticsSignpostEvent*)@"CKKSEventItemAddedToOutgoingQueue";
167 CKKSAnalyticsSignpostEvent* const CKKSEventMissingLocalItemsFound = (CKKSAnalyticsSignpostEvent*)@"CKKSEventMissingLocalItemsFound";
168 CKKSAnalyticsSignpostEvent* const CKKSEventReachabilityTimerExpired = (CKKSAnalyticsSignpostEvent *)@"CKKSEventReachabilityTimerExpired";
170 CKKSAnalyticsFailableEvent* const OctagonEventTPHHealthCheckStatus = (CKKSAnalyticsFailableEvent*)@"OctagonEventTPHHealthCheckStatus";
172 CKKSAnalyticsFailableEvent* const OctagonEventAuthKitDeviceList = (CKKSAnalyticsFailableEvent *)@"OctagonEventAuthKitDeviceList";
174 CKKSAnalyticsActivity* const CKKSActivityOTFetchRampState = (CKKSAnalyticsActivity *)@"CKKSActivityOTFetchRampState";
175 CKKSAnalyticsActivity* const CKKSActivityOctagonPreflightBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonPreflightBottle";
176 CKKSAnalyticsActivity* const CKKSActivityOctagonLaunchBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonLaunchBottle";
177 CKKSAnalyticsActivity* const CKKSActivityOctagonRestore = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonRestore";
178 CKKSAnalyticsActivity* const CKKSActivityScrubBottle = (CKKSAnalyticsActivity *)@"CKKSActivityScrubBottle";
179 CKKSAnalyticsActivity* const CKKSActivityBottleCheck = (CKKSAnalyticsActivity *)@"CKKSActivityBottleCheck";
180 CKKSAnalyticsActivity* const CKKSActivityOctagonUpdateBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonUpdateBottle";
182 CKKSAnalyticsActivity* const OctagonActivityAccountAvailable = (CKKSAnalyticsActivity *)@"OctagonActivityAccountAvailable";
183 CKKSAnalyticsActivity* const OctagonActivityAccountNotAvailable = (CKKSAnalyticsActivity *)@"OctagonActivityAccountNotAvailable";
184 CKKSAnalyticsActivity* const OctagonActivityResetAndEstablish = (CKKSAnalyticsActivity *)@"OctagonActivityResetAndEstablish";
185 CKKSAnalyticsActivity* const OctagonActivityEstablish = (CKKSAnalyticsActivity *)@"OctagonActivityEstablish";
186 CKKSAnalyticsActivity* const OctagonSOSAdapterUpdateKeys = (CKKSAnalyticsActivity*)@"OctagonSOSAdapterUpdateKeys";
188 CKKSAnalyticsActivity* const OctagonActivityFetchAllViableBottles = (CKKSAnalyticsActivity *)@"OctagonActivityFetchAllViableBottles";
189 CKKSAnalyticsActivity* const OctagonActivityFetchEscrowContents = (CKKSAnalyticsActivity *)@"OctagonActivityFetchEscrowContents";
190 CKKSAnalyticsActivity* const OctagonActivityBottledPeerRestore = (CKKSAnalyticsActivity *)@"OctagonActivityBottledPeerRestore";
191 CKKSAnalyticsActivity* const OctagonActivitySetRecoveryKey = (CKKSAnalyticsActivity *)@"OctagonActivitySetRecoveryKey";
192 CKKSAnalyticsActivity* const OctagonActivityJoinWithRecoveryKey = (CKKSAnalyticsActivity *)@"OctagonActivityJoinWithRecoveryKey";
194 CKKSAnalyticsActivity* const OctagonActivityLeaveClique = (CKKSAnalyticsActivity *)@"OctagonActivityLeaveClique";
195 CKKSAnalyticsActivity* const OctagonActivityRemoveFriendsInClique = (CKKSAnalyticsActivity *)@"OctagonActivityRemoveFriendsInClique";
199 @implementation CKKSAnalytics
201 + (NSString*)databasePath
203 // This block exists because we moved database locations in 11.3 for easier sandboxing of securityuploadd, so we're cleaning up.
204 static dispatch_once_t onceToken;
205 dispatch_once(&onceToken, ^{
206 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db"), ^(const char *filename) {
209 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-wal"), ^(const char *filename) {
212 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-shm"), ^(const char *filename) {
216 return [CKKSAnalytics defaultAnalyticsDatabasePath:@"ckks_analytics"];
219 + (instancetype)logger
221 // just here because I want it in the header for discoverability
222 return [super logger];
225 - (void)logSuccessForEvent:(CKKSAnalyticsFailableEvent*)event zoneName:(NSString*)zoneName
227 [self logSuccessForEventNamed:[NSString stringWithFormat:@"%@-%@", zoneName, event]];
228 [self setDateProperty:[NSDate date] forKey:[NSString stringWithFormat:@"last_success_%@-%@", zoneName, event]];
231 - (bool)isCKPartialError:(NSError *)error
233 return [error.domain isEqualToString:CKErrorDomain] && error.code == CKErrorPartialFailure;
236 - (void)addCKPartialError:(NSMutableDictionary *)errorDictionary error:(NSError *)error depth:(NSUInteger)depth
238 // capture one random underlaying error
239 if ([self isCKPartialError:error]) {
240 NSDictionary<NSString *,NSError *> *partialErrors = error.userInfo[CKPartialErrorsByItemIDKey];
241 if ([partialErrors isKindOfClass:[NSDictionary class]]) {
242 for (NSString *key in partialErrors) {
243 NSError* ckError = partialErrors[key];
244 if (![ckError isKindOfClass:[NSError class]])
246 if ([ckError.domain isEqualToString:CKErrorDomain] && ckError.code == CKErrorBatchRequestFailed) {
249 NSDictionary *res = [self errorChain:ckError depth:(depth + 1)];
251 errorDictionary[@"oneCloudKitPartialFailure"] = res;
259 // if we have underlying errors, capture the chain below the top-most error
260 - (NSDictionary *)errorChain:(NSError *)error depth:(NSUInteger)depth
262 NSMutableDictionary *errorDictionary = nil;
264 if (depth > 5 || ![error isKindOfClass:[NSError class]])
267 errorDictionary = [@{
268 @"domain" : error.domain,
269 @"code" : @(error.code),
272 errorDictionary[@"child"] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:(depth + 1)];
273 [self addCKPartialError:errorDictionary error:error depth:(depth + 1)];
275 return errorDictionary;
278 - (NSDictionary *)createErrorAttributes:(NSError *)error
279 depth:(NSUInteger)depth
280 attributes:(NSDictionary *)attributes
282 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
284 /* Don't allow caller to overwrite our attributes, lets merge them first */
286 [eventAttributes setValuesForKeysWithDictionary:attributes];
289 [eventAttributes setValuesForKeysWithDictionary:@{
290 CKKSAnalyticsAttributeRecoverableError : @(YES),
291 CKKSAnalyticsAttributeErrorDomain : error.domain,
292 CKKSAnalyticsAttributeErrorCode : @(error.code)
295 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
296 [self addCKPartialError:eventAttributes error:error depth:0];
298 return eventAttributes;
301 - (void)logRecoverableError:(NSError*)error
302 forEvent:(CKKSAnalyticsFailableEvent*)event
303 zoneName:(NSString*)zoneName
304 withAttributes:(NSDictionary *)attributes
309 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
311 /* Don't allow caller to overwrite our attributes, lets merge them first */
313 [eventAttributes setValuesForKeysWithDictionary:attributes];
316 [eventAttributes setValuesForKeysWithDictionary:@{
317 CKKSAnalyticsAttributeRecoverableError : @(YES),
318 CKKSAnalyticsAttributeZoneName : zoneName,
319 CKKSAnalyticsAttributeErrorDomain : error.domain,
320 CKKSAnalyticsAttributeErrorCode : @(error.code)
323 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
324 [self addCKPartialError:eventAttributes error:error depth:0];
326 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
329 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event withAttributes:(NSDictionary *)attributes
334 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
336 /* Don't allow caller to overwrite our attributes, lets merge them first */
338 [eventAttributes setValuesForKeysWithDictionary:attributes];
341 [eventAttributes setValuesForKeysWithDictionary:@{
342 CKKSAnalyticsAttributeRecoverableError : @(YES),
343 CKKSAnalyticsAttributeErrorDomain : error.domain,
344 CKKSAnalyticsAttributeErrorCode : @(error.code)
347 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
348 [self addCKPartialError:eventAttributes error:error depth:0];
350 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
353 - (void)logUnrecoverableError:(NSError*)error
354 forEvent:(CKKSAnalyticsFailableEvent*)event
355 zoneName:(NSString*)zoneName
356 withAttributes:(NSDictionary *)attributes
361 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
363 [eventAttributes setValuesForKeysWithDictionary:attributes];
366 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
367 [self addCKPartialError:eventAttributes error:error depth:0];
369 [eventAttributes setValuesForKeysWithDictionary:@{
370 CKKSAnalyticsAttributeRecoverableError : @(NO),
371 CKKSAnalyticsAttributeZoneName : zoneName,
372 CKKSAnalyticsAttributeErrorDomain : error.domain,
373 CKKSAnalyticsAttributeErrorCode : @(error.code)
376 [self logHardFailureForEventNamed:event withAttributes:eventAttributes];
379 - (void)logUnrecoverableError:(NSError*)error
380 forEvent:(CKKSAnalyticsFailableEvent*)event
381 withAttributes:(NSDictionary *)attributes
386 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
388 /* Don't allow caller to overwrite our attributes, lets merge them first */
390 [eventAttributes setValuesForKeysWithDictionary:attributes];
393 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
394 [self addCKPartialError:eventAttributes error:error depth:0];
396 [eventAttributes setValuesForKeysWithDictionary:@{
397 CKKSAnalyticsAttributeRecoverableError : @(NO),
398 CKKSAnalyticsAttributeZoneName : OctagonEventAttributeZoneName,
399 CKKSAnalyticsAttributeErrorDomain : error.domain,
400 CKKSAnalyticsAttributeErrorCode : @(error.code)
403 [self logHardFailureForEventNamed:event withAttributes:eventAttributes];
406 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event
408 [self noteEventNamed:event];
410 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event zoneName:(NSString*)zoneName
412 [self noteEventNamed:[NSString stringWithFormat:@"%@-%@", zoneName, event]];
415 - (NSDate*)dateOfLastSuccessForEvent:(CKKSAnalyticsFailableEvent*)event zoneName:(NSString*)zoneName
417 return [self datePropertyForKey:[NSString stringWithFormat:@"last_success_%@-%@", zoneName, event]];
420 - (void)setDateProperty:(NSDate*)date forKey:(NSString*)key zoneName:(NSString*)zoneName
422 [self setDateProperty:date forKey:[NSString stringWithFormat:@"%@-%@", key, zoneName]];
424 - (NSDate *)datePropertyForKey:(NSString *)key zoneName:(NSString*)zoneName
426 return [self datePropertyForKey:[NSString stringWithFormat:@"%@-%@", key, zoneName]];