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";
87 NSString* const OctagonAnalyticsSecureBackupTermsAccepted = @"OASecureBackupTermsAccepted";
89 static NSString* const CKKSAnalyticsAttributeRecoverableError = @"recoverableError";
90 static NSString* const CKKSAnalyticsAttributeZoneName = @"zone";
91 static NSString* const CKKSAnalyticsAttributeErrorDomain = @"errorDomain";
92 static NSString* const CKKSAnalyticsAttributeErrorCode = @"errorCode";
93 static NSString* const CKKSAnalyticsAttributeErrorChain = @"errorChain";
95 CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassA = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessIncomingQueueClassA";
96 CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassC = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessIncomingQueueClassC";
97 CKKSAnalyticsFailableEvent* const CKKSEventProcessOutgoingQueue = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessOutgoingQueue";
98 CKKSAnalyticsFailableEvent* const CKKSEventUploadChanges = (CKKSAnalyticsFailableEvent*)@"CKKSEventUploadChanges";
99 CKKSAnalyticsFailableEvent* const CKKSEventStateError = (CKKSAnalyticsFailableEvent*)@"CKKSEventStateError";
100 CKKSAnalyticsFailableEvent* const CKKSEventProcessHealKeyHierarchy = (CKKSAnalyticsFailableEvent *)@"CKKSEventProcessHealKeyHierarchy";
101 CKKSAnalyticsFailableEvent* const CKKSEventProcessReencryption = (CKKSAnalyticsFailableEvent *)@"CKKSEventProcessReencryption";
103 NSString* const OctagonEventFailureReason = @"FailureReason";
105 CKKSAnalyticsFailableEvent* const OctagonEventPreflightBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightBottle";
106 CKKSAnalyticsFailableEvent* const OctagonEventLaunchBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventLaunchBottle";
107 CKKSAnalyticsFailableEvent* const OctagonEventRestoreBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventRestoreBottle";
108 CKKSAnalyticsFailableEvent* const OctagonEventScrubBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventScrubBottle";
109 CKKSAnalyticsFailableEvent* const OctagonEventSignIn = (CKKSAnalyticsFailableEvent *)@"OctagonEventSignIn";
110 CKKSAnalyticsFailableEvent* const OctagonEventSignOut = (CKKSAnalyticsFailableEvent *)@"OctagonEventSignIn";
111 CKKSAnalyticsFailableEvent* const OctagonEventRamp = (CKKSAnalyticsFailableEvent *)@"OctagonEventRamp";
112 CKKSAnalyticsFailableEvent* const OctagonEventBottleCheck = (CKKSAnalyticsFailableEvent *)@"OctagonEventBottleCheck";
113 CKKSAnalyticsFailableEvent* const OctagonEventCoreFollowUp = (CKKSAnalyticsFailableEvent *)@"OctagonEventCoreFollowUp";
114 CKKSAnalyticsFailableEvent* const OctagonEventUpdateBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpdateBottle";
116 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustState = (CKKSAnalyticsFailableEvent *)@"OctagonEventCheckTrustState";
118 CKKSAnalyticsFailableEvent* const OctagonEventBottledPeerRestore = (CKKSAnalyticsFailableEvent*)@"OctagonEventBottledPeerRestore";
119 CKKSAnalyticsFailableEvent* const OctagonEventRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventRecoveryKey";
121 CKKSAnalyticsFailableEvent* const OctagonEventFetchAllBottles = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchAllBottles";
122 CKKSAnalyticsFailableEvent* const OctagonEventFetchEscrowContents = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchEscrowContents";
123 CKKSAnalyticsFailableEvent* const OctagonEventResetAndEstablish = (CKKSAnalyticsFailableEvent*)@"OctagonEventResetAndEstablish";
124 CKKSAnalyticsFailableEvent* const OctagonEventEstablish = (CKKSAnalyticsFailableEvent*)@"OctagonEventEstablish";
125 CKKSAnalyticsFailableEvent* const OctagonEventLeaveClique = (CKKSAnalyticsFailableEvent*)@"OctagonEventLeaveClique";
126 CKKSAnalyticsFailableEvent* const OctagonEventRemoveFriendsInClique = (CKKSAnalyticsFailableEvent*)@"OctagonEventRemoveFriendsInClique";
128 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeFetchDeviceIDs = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeFetchDeviceIDs";
129 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSetAllowList = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeSetAllowList";
130 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSilentEscrow = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeSilentEscrow";
131 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoin = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreapprovedJoin";
132 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreflightPreapprovedJoin = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreflightPreapprovedJoin";
133 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoinAfterPairing = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreapprovedJoinAfterPairing";
134 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePrepare = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePrepare";
136 CKKSAnalyticsFailableEvent* const OctagonEventJoinWithVoucher = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinWithVoucher";
138 CKKSAnalyticsFailableEvent* const OctagonEventPreflightVouchWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightVouchWithBottle";
139 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithBottle";
141 CKKSAnalyticsFailableEvent* const OctagonEventPreflightVouchWithRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightVouchWithRecoveryKey";;
142 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithRecoveryKey";
144 CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventSetRecoveryKey";
146 CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKeyValidationFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventSetRecoveryKeyValidationFailed";
147 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyValidationFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyValidationFailed";
148 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleReset = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyCircleReset";
149 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleResetFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyCircleResetFailed";
150 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyEnrollFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyEnrollFailed";
151 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyFailed";
153 CKKSAnalyticsFailableEvent* const OctagonEventReset = (CKKSAnalyticsFailableEvent*)@"OctagonEventReset";
155 CKKSAnalyticsFailableEvent* const OctagonEventPrepareIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventPrepareIdentity";
157 CKKSAnalyticsFailableEvent* const OctagonEventEstablishIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventEstablishIdentity";
158 CKKSAnalyticsFailableEvent* const OctagonEventFetchViews = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchViews";
160 CKKSAnalyticsFailableEvent* const OctagonEventStateTransition = (CKKSAnalyticsFailableEvent*)@"OctagonEventStateTransition";
162 CKKSAnalyticsFailableEvent* const OctagonEventCompanionPairing = (CKKSAnalyticsFailableEvent*)@"OctagonEventCompanionPairing";
164 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustForCFU = (CKKSAnalyticsFailableEvent*)@"OctagonEventCheckTrustForCFU";
166 CKKSAnalyticsSignpostEvent* const CKKSEventPushNotificationReceived = (CKKSAnalyticsSignpostEvent*)@"CKKSEventPushNotificationReceived";
167 CKKSAnalyticsSignpostEvent* const CKKSEventItemAddedToOutgoingQueue = (CKKSAnalyticsSignpostEvent*)@"CKKSEventItemAddedToOutgoingQueue";
168 CKKSAnalyticsSignpostEvent* const CKKSEventMissingLocalItemsFound = (CKKSAnalyticsSignpostEvent*)@"CKKSEventMissingLocalItemsFound";
169 CKKSAnalyticsSignpostEvent* const CKKSEventReachabilityTimerExpired = (CKKSAnalyticsSignpostEvent *)@"CKKSEventReachabilityTimerExpired";
171 CKKSAnalyticsFailableEvent* const OctagonEventTPHHealthCheckStatus = (CKKSAnalyticsFailableEvent*)@"OctagonEventTPHHealthCheckStatus";
173 CKKSAnalyticsFailableEvent* const OctagonEventAuthKitDeviceList = (CKKSAnalyticsFailableEvent *)@"OctagonEventAuthKitDeviceList";
175 CKKSAnalyticsActivity* const CKKSActivityOTFetchRampState = (CKKSAnalyticsActivity *)@"CKKSActivityOTFetchRampState";
176 CKKSAnalyticsActivity* const CKKSActivityOctagonPreflightBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonPreflightBottle";
177 CKKSAnalyticsActivity* const CKKSActivityOctagonLaunchBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonLaunchBottle";
178 CKKSAnalyticsActivity* const CKKSActivityOctagonRestore = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonRestore";
179 CKKSAnalyticsActivity* const CKKSActivityScrubBottle = (CKKSAnalyticsActivity *)@"CKKSActivityScrubBottle";
180 CKKSAnalyticsActivity* const CKKSActivityBottleCheck = (CKKSAnalyticsActivity *)@"CKKSActivityBottleCheck";
181 CKKSAnalyticsActivity* const CKKSActivityOctagonUpdateBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonUpdateBottle";
183 CKKSAnalyticsActivity* const OctagonActivityAccountAvailable = (CKKSAnalyticsActivity *)@"OctagonActivityAccountAvailable";
184 CKKSAnalyticsActivity* const OctagonActivityAccountNotAvailable = (CKKSAnalyticsActivity *)@"OctagonActivityAccountNotAvailable";
185 CKKSAnalyticsActivity* const OctagonActivityResetAndEstablish = (CKKSAnalyticsActivity *)@"OctagonActivityResetAndEstablish";
186 CKKSAnalyticsActivity* const OctagonActivityEstablish = (CKKSAnalyticsActivity *)@"OctagonActivityEstablish";
187 CKKSAnalyticsActivity* const OctagonSOSAdapterUpdateKeys = (CKKSAnalyticsActivity*)@"OctagonSOSAdapterUpdateKeys";
189 CKKSAnalyticsActivity* const OctagonActivityFetchAllViableBottles = (CKKSAnalyticsActivity *)@"OctagonActivityFetchAllViableBottles";
190 CKKSAnalyticsActivity* const OctagonActivityFetchEscrowContents = (CKKSAnalyticsActivity *)@"OctagonActivityFetchEscrowContents";
191 CKKSAnalyticsActivity* const OctagonActivityBottledPeerRestore = (CKKSAnalyticsActivity *)@"OctagonActivityBottledPeerRestore";
192 CKKSAnalyticsActivity* const OctagonActivitySetRecoveryKey = (CKKSAnalyticsActivity *)@"OctagonActivitySetRecoveryKey";
193 CKKSAnalyticsActivity* const OctagonActivityJoinWithRecoveryKey = (CKKSAnalyticsActivity *)@"OctagonActivityJoinWithRecoveryKey";
195 CKKSAnalyticsActivity* const OctagonActivityLeaveClique = (CKKSAnalyticsActivity *)@"OctagonActivityLeaveClique";
196 CKKSAnalyticsActivity* const OctagonActivityRemoveFriendsInClique = (CKKSAnalyticsActivity *)@"OctagonActivityRemoveFriendsInClique";
200 @implementation CKKSAnalytics
202 + (NSString*)databasePath
204 // This block exists because we moved database locations in 11.3 for easier sandboxing of securityuploadd, so we're cleaning up.
205 static dispatch_once_t onceToken;
206 dispatch_once(&onceToken, ^{
207 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db"), ^(const char *filename) {
210 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-wal"), ^(const char *filename) {
213 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-shm"), ^(const char *filename) {
217 return [CKKSAnalytics defaultAnalyticsDatabasePath:@"ckks_analytics"];
220 + (instancetype)logger
222 // just here because I want it in the header for discoverability
223 return [super logger];
226 - (void)logSuccessForEvent:(CKKSAnalyticsFailableEvent*)event zoneName:(NSString*)zoneName
228 [self logSuccessForEventNamed:[NSString stringWithFormat:@"%@-%@", zoneName, event]];
229 [self setDateProperty:[NSDate date] forKey:[NSString stringWithFormat:@"last_success_%@-%@", zoneName, event]];
232 - (bool)isCKPartialError:(NSError *)error
234 return [error.domain isEqualToString:CKErrorDomain] && error.code == CKErrorPartialFailure;
237 - (void)addCKPartialError:(NSMutableDictionary *)errorDictionary error:(NSError *)error depth:(NSUInteger)depth
239 // capture one random underlaying error
240 if ([self isCKPartialError:error]) {
241 NSDictionary<NSString *,NSError *> *partialErrors = error.userInfo[CKPartialErrorsByItemIDKey];
242 if ([partialErrors isKindOfClass:[NSDictionary class]]) {
243 for (NSString *key in partialErrors) {
244 NSError* ckError = partialErrors[key];
245 if (![ckError isKindOfClass:[NSError class]])
247 if ([ckError.domain isEqualToString:CKErrorDomain] && ckError.code == CKErrorBatchRequestFailed) {
250 NSDictionary *res = [self errorChain:ckError depth:(depth + 1)];
252 errorDictionary[@"oneCloudKitPartialFailure"] = res;
260 // if we have underlying errors, capture the chain below the top-most error
261 - (NSDictionary *)errorChain:(NSError *)error depth:(NSUInteger)depth
263 NSMutableDictionary *errorDictionary = nil;
265 if (depth > 5 || ![error isKindOfClass:[NSError class]])
268 errorDictionary = [@{
269 @"domain" : error.domain,
270 @"code" : @(error.code),
273 errorDictionary[@"child"] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:(depth + 1)];
274 [self addCKPartialError:errorDictionary error:error depth:(depth + 1)];
276 return errorDictionary;
279 - (NSDictionary *)createErrorAttributes:(NSError *)error
280 depth:(NSUInteger)depth
281 attributes:(NSDictionary *)attributes
283 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
285 /* Don't allow caller to overwrite our attributes, lets merge them first */
287 [eventAttributes setValuesForKeysWithDictionary:attributes];
290 [eventAttributes setValuesForKeysWithDictionary:@{
291 CKKSAnalyticsAttributeRecoverableError : @(YES),
292 CKKSAnalyticsAttributeErrorDomain : error.domain,
293 CKKSAnalyticsAttributeErrorCode : @(error.code)
296 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
297 [self addCKPartialError:eventAttributes error:error depth:0];
299 return eventAttributes;
302 - (void)logRecoverableError:(NSError*)error
303 forEvent:(CKKSAnalyticsFailableEvent*)event
304 zoneName:(NSString*)zoneName
305 withAttributes:(NSDictionary *)attributes
310 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
312 /* Don't allow caller to overwrite our attributes, lets merge them first */
314 [eventAttributes setValuesForKeysWithDictionary:attributes];
317 [eventAttributes setValuesForKeysWithDictionary:@{
318 CKKSAnalyticsAttributeRecoverableError : @(YES),
319 CKKSAnalyticsAttributeZoneName : zoneName,
320 CKKSAnalyticsAttributeErrorDomain : error.domain,
321 CKKSAnalyticsAttributeErrorCode : @(error.code)
324 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
325 [self addCKPartialError:eventAttributes error:error depth:0];
327 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
330 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event withAttributes:(NSDictionary *)attributes
335 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
337 /* Don't allow caller to overwrite our attributes, lets merge them first */
339 [eventAttributes setValuesForKeysWithDictionary:attributes];
342 [eventAttributes setValuesForKeysWithDictionary:@{
343 CKKSAnalyticsAttributeRecoverableError : @(YES),
344 CKKSAnalyticsAttributeErrorDomain : error.domain,
345 CKKSAnalyticsAttributeErrorCode : @(error.code)
348 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
349 [self addCKPartialError:eventAttributes error:error depth:0];
351 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
354 - (void)logUnrecoverableError:(NSError*)error
355 forEvent:(CKKSAnalyticsFailableEvent*)event
356 zoneName:(NSString*)zoneName
357 withAttributes:(NSDictionary *)attributes
362 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
364 [eventAttributes setValuesForKeysWithDictionary:attributes];
367 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
368 [self addCKPartialError:eventAttributes error:error depth:0];
370 [eventAttributes setValuesForKeysWithDictionary:@{
371 CKKSAnalyticsAttributeRecoverableError : @(NO),
372 CKKSAnalyticsAttributeZoneName : zoneName,
373 CKKSAnalyticsAttributeErrorDomain : error.domain,
374 CKKSAnalyticsAttributeErrorCode : @(error.code)
377 [self logHardFailureForEventNamed:event withAttributes:eventAttributes];
380 - (void)logUnrecoverableError:(NSError*)error
381 forEvent:(CKKSAnalyticsFailableEvent*)event
382 withAttributes:(NSDictionary *)attributes
387 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
389 /* Don't allow caller to overwrite our attributes, lets merge them first */
391 [eventAttributes setValuesForKeysWithDictionary:attributes];
394 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
395 [self addCKPartialError:eventAttributes error:error depth:0];
397 [eventAttributes setValuesForKeysWithDictionary:@{
398 CKKSAnalyticsAttributeRecoverableError : @(NO),
399 CKKSAnalyticsAttributeZoneName : OctagonEventAttributeZoneName,
400 CKKSAnalyticsAttributeErrorDomain : error.domain,
401 CKKSAnalyticsAttributeErrorCode : @(error.code)
404 [self logHardFailureForEventNamed:event withAttributes:eventAttributes];
407 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event
409 [self noteEventNamed:event];
411 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event zoneName:(NSString*)zoneName
413 [self noteEventNamed:[NSString stringWithFormat:@"%@-%@", zoneName, event]];
416 - (NSDate*)dateOfLastSuccessForEvent:(CKKSAnalyticsFailableEvent*)event zoneName:(NSString*)zoneName
418 return [self datePropertyForKey:[NSString stringWithFormat:@"last_success_%@-%@", zoneName, event]];
421 - (void)setDateProperty:(NSDate*)date forKey:(NSString*)key zoneName:(NSString*)zoneName
423 [self setDateProperty:date forKey:[NSString stringWithFormat:@"%@-%@", key, zoneName]];
425 - (NSDate *)datePropertyForKey:(NSString *)key zoneName:(NSString*)zoneName
427 return [self datePropertyForKey:[NSString stringWithFormat:@"%@-%@", key, zoneName]];