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 OctagonAnalyticsTrustState = @"OATrust";
53 NSString* const OctagonAnalyticsLastHealthCheck = @"OAHealthCheck";
54 NSString* const OctagonAnalyticsSOSStatus = @"OASOSStatus";
55 NSString* const OctagonAnalyticsDateOfLastPreflightPreapprovedJoin = @"OALastPPJ";
56 NSString* const OctagonAnalyticsLastKeystateReady = @"OALastKSR";
57 NSString* const OctagonAnalyticsLastCoreFollowup = @"OALastCFU";
58 //NSString* const OctagonAnalyticsCoreFollowupStatus = @"OACFUStatus";
59 NSString* const OctagonAnalyticsCoreFollowupFailureCount = @"OACFUTFailureCount";
60 NSString* const OctagonAnalyticsCoreFollowupLastFailureTime = @"OACFULastFailureTime";
61 NSString* const OctagonAnalyticsPrerecordPending = @"OAPrerecordPending";
62 NSString* const OctagonAnalyticsCDPStateRun = @"OACDPStateRun";
64 NSString* const CKKSAnalyticsLastCKKSPush = @"lastCKKSPush";
65 NSString* const CKKSAnalyticsLastOctagonPush = @"lastOctagonPush";
67 NSString* const OctagonAnalyticsKVSProvisioned = @"OADCKVSProvisioned";
68 NSString* const OctagonAnalyticsKVSEnabled = @"OADCKVSEnabled";
69 NSString* const OctagonAnalyticsKeychainSyncProvisioned = @"OADCKCSProvisioned";
70 NSString* const OctagonAnalyticsKeychainSyncEnabled = @"OADCKCSEnabled";
71 NSString* const OctagonAnalyticsCloudKitProvisioned = @"OADCCKProvisioned";
72 NSString* const OctagonAnalyticsCloudKitEnabled = @"OADCCKEnabled";
74 static NSString* const CKKSAnalyticsAttributeRecoverableError = @"recoverableError";
75 static NSString* const CKKSAnalyticsAttributeZoneName = @"zone";
76 static NSString* const CKKSAnalyticsAttributeErrorDomain = @"errorDomain";
77 static NSString* const CKKSAnalyticsAttributeErrorCode = @"errorCode";
78 static NSString* const CKKSAnalyticsAttributeErrorChain = @"errorChain";
80 CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassA = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessIncomingQueueClassA";
81 CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassC = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessIncomingQueueClassC";
82 CKKSAnalyticsFailableEvent* const CKKSEventProcessOutgoingQueue = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessOutgoingQueue";
83 CKKSAnalyticsFailableEvent* const CKKSEventUploadChanges = (CKKSAnalyticsFailableEvent*)@"CKKSEventUploadChanges";
84 CKKSAnalyticsFailableEvent* const CKKSEventStateError = (CKKSAnalyticsFailableEvent*)@"CKKSEventStateError";
85 CKKSAnalyticsFailableEvent* const CKKSEventProcessHealKeyHierarchy = (CKKSAnalyticsFailableEvent *)@"CKKSEventProcessHealKeyHierarchy";
86 CKKSAnalyticsFailableEvent* const CKKSEventProcessReencryption = (CKKSAnalyticsFailableEvent *)@"CKKSEventProcessReencryption";
88 NSString* const OctagonEventFailureReason = @"FailureReason";
90 CKKSAnalyticsFailableEvent* const OctagonEventPreflightBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightBottle";
91 CKKSAnalyticsFailableEvent* const OctagonEventLaunchBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventLaunchBottle";
92 CKKSAnalyticsFailableEvent* const OctagonEventRestoreBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventRestoreBottle";
93 CKKSAnalyticsFailableEvent* const OctagonEventScrubBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventScrubBottle";
94 CKKSAnalyticsFailableEvent* const OctagonEventSignIn = (CKKSAnalyticsFailableEvent *)@"OctagonEventSignIn";
95 CKKSAnalyticsFailableEvent* const OctagonEventSignOut = (CKKSAnalyticsFailableEvent *)@"OctagonEventSignIn";
96 CKKSAnalyticsFailableEvent* const OctagonEventRamp = (CKKSAnalyticsFailableEvent *)@"OctagonEventRamp";
97 CKKSAnalyticsFailableEvent* const OctagonEventBottleCheck = (CKKSAnalyticsFailableEvent *)@"OctagonEventBottleCheck";
98 CKKSAnalyticsFailableEvent* const OctagonEventCoreFollowUp = (CKKSAnalyticsFailableEvent *)@"OctagonEventCoreFollowUp";
99 CKKSAnalyticsFailableEvent* const OctagonEventUpdateBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpdateBottle";
101 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustState = (CKKSAnalyticsFailableEvent *)@"OctagonEventCheckTrustState";
103 CKKSAnalyticsFailableEvent* const OctagonEventBottledPeerRestore = (CKKSAnalyticsFailableEvent*)@"OctagonEventBottledPeerRestore";
104 CKKSAnalyticsFailableEvent* const OctagonEventRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventRecoveryKey";
106 CKKSAnalyticsFailableEvent* const OctagonEventFetchAllBottles = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchAllBottles";
107 CKKSAnalyticsFailableEvent* const OctagonEventFetchEscrowContents = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchEscrowContents";
108 CKKSAnalyticsFailableEvent* const OctagonEventResetAndEstablish = (CKKSAnalyticsFailableEvent*)@"OctagonEventResetAndEstablish";
109 CKKSAnalyticsFailableEvent* const OctagonEventEstablish = (CKKSAnalyticsFailableEvent*)@"OctagonEventEstablish";
110 CKKSAnalyticsFailableEvent* const OctagonEventLeaveClique = (CKKSAnalyticsFailableEvent*)@"OctagonEventLeaveClique";
111 CKKSAnalyticsFailableEvent* const OctagonEventRemoveFriendsInClique = (CKKSAnalyticsFailableEvent*)@"OctagonEventRemoveFriendsInClique";
113 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeFetchDeviceIDs = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeFetchDeviceIDs";
114 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSetAllowList = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeSetAllowList";
115 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSilentEscrow = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeSilentEscrow";
116 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoin = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreapprovedJoin";
117 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreflightPreapprovedJoin = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreflightPreapprovedJoin";
118 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoinAfterPairing = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreapprovedJoinAfterPairing";
119 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePrepare = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePrepare";
121 CKKSAnalyticsFailableEvent* const OctagonEventJoinWithVoucher = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinWithVoucher";
123 CKKSAnalyticsFailableEvent* const OctagonEventPreflightVouchWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightVouchWithBottle";
124 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithBottle";
126 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithRecoveryKey";
128 CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventSetRecoveryKey";
130 CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKeyValidationFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventSetRecoveryKeyValidationFailed";
131 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyValidationFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyValidationFailed";
132 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleReset = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyCircleReset";
133 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleResetFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyCircleResetFailed";
134 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyEnrollFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyEnrollFailed";
135 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyFailed";
137 CKKSAnalyticsFailableEvent* const OctagonEventReset = (CKKSAnalyticsFailableEvent*)@"OctagonEventReset";
139 CKKSAnalyticsFailableEvent* const OctagonEventPrepareIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventPrepareIdentity";
141 CKKSAnalyticsFailableEvent* const OctagonEventEstablishIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventEstablishIdentity";
142 CKKSAnalyticsFailableEvent* const OctagonEventFetchViews = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchViews";
144 CKKSAnalyticsFailableEvent* const OctagonEventStateTransition = (CKKSAnalyticsFailableEvent*)@"OctagonEventStateTransition";
146 CKKSAnalyticsFailableEvent* const OctagonEventCompanionPairing = (CKKSAnalyticsFailableEvent*)@"OctagonEventCompanionPairing";
148 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustForCFU = (CKKSAnalyticsFailableEvent*)@"OctagonEventCheckTrustForCFU";
150 CKKSAnalyticsSignpostEvent* const CKKSEventPushNotificationReceived = (CKKSAnalyticsSignpostEvent*)@"CKKSEventPushNotificationReceived";
151 CKKSAnalyticsSignpostEvent* const CKKSEventItemAddedToOutgoingQueue = (CKKSAnalyticsSignpostEvent*)@"CKKSEventItemAddedToOutgoingQueue";
152 CKKSAnalyticsSignpostEvent* const CKKSEventMissingLocalItemsFound = (CKKSAnalyticsSignpostEvent*)@"CKKSEventMissingLocalItemsFound";
153 CKKSAnalyticsSignpostEvent* const CKKSEventReachabilityTimerExpired = (CKKSAnalyticsSignpostEvent *)@"CKKSEventReachabilityTimerExpired";
155 CKKSAnalyticsFailableEvent* const OctagonEventTPHHealthCheckStatus = (CKKSAnalyticsFailableEvent*)@"OctagonEventTPHHealthCheckStatus";
157 CKKSAnalyticsActivity* const CKKSActivityOTFetchRampState = (CKKSAnalyticsActivity *)@"CKKSActivityOTFetchRampState";
158 CKKSAnalyticsActivity* const CKKSActivityOctagonPreflightBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonPreflightBottle";
159 CKKSAnalyticsActivity* const CKKSActivityOctagonLaunchBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonLaunchBottle";
160 CKKSAnalyticsActivity* const CKKSActivityOctagonRestore = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonRestore";
161 CKKSAnalyticsActivity* const CKKSActivityScrubBottle = (CKKSAnalyticsActivity *)@"CKKSActivityScrubBottle";
162 CKKSAnalyticsActivity* const CKKSActivityBottleCheck = (CKKSAnalyticsActivity *)@"CKKSActivityBottleCheck";
163 CKKSAnalyticsActivity* const CKKSActivityOctagonUpdateBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonUpdateBottle";
165 CKKSAnalyticsActivity* const OctagonActivityAccountAvailable = (CKKSAnalyticsActivity *)@"OctagonActivityAccountAvailable";
166 CKKSAnalyticsActivity* const OctagonActivityAccountNotAvailable = (CKKSAnalyticsActivity *)@"OctagonActivityAccountNotAvailable";
167 CKKSAnalyticsActivity* const OctagonActivityResetAndEstablish = (CKKSAnalyticsActivity *)@"OctagonActivityResetAndEstablish";
168 CKKSAnalyticsActivity* const OctagonActivityEstablish = (CKKSAnalyticsActivity *)@"OctagonActivityEstablish";
169 CKKSAnalyticsActivity* const OctagonSOSAdapterUpdateKeys = (CKKSAnalyticsActivity*)@"OctagonSOSAdapterUpdateKeys";
171 CKKSAnalyticsActivity* const OctagonActivityFetchAllViableBottles = (CKKSAnalyticsActivity *)@"OctagonActivityFetchAllViableBottles";
172 CKKSAnalyticsActivity* const OctagonActivityFetchEscrowContents = (CKKSAnalyticsActivity *)@"OctagonActivityFetchEscrowContents";
173 CKKSAnalyticsActivity* const OctagonActivityBottledPeerRestore = (CKKSAnalyticsActivity *)@"OctagonActivityBottledPeerRestore";
174 CKKSAnalyticsActivity* const OctagonActivitySetRecoveryKey = (CKKSAnalyticsActivity *)@"OctagonActivitySetRecoveryKey";
175 CKKSAnalyticsActivity* const OctagonActivityJoinWithRecoveryKey = (CKKSAnalyticsActivity *)@"OctagonActivityJoinWithRecoveryKey";
177 CKKSAnalyticsActivity* const OctagonActivityLeaveClique = (CKKSAnalyticsActivity *)@"OctagonActivityLeaveClique";
178 CKKSAnalyticsActivity* const OctagonActivityRemoveFriendsInClique = (CKKSAnalyticsActivity *)@"OctagonActivityRemoveFriendsInClique";
182 @implementation CKKSAnalytics
184 + (NSString*)databasePath
186 // This block exists because we moved database locations in 11.3 for easier sandboxing of securityuploadd, so we're cleaning up.
187 static dispatch_once_t onceToken;
188 dispatch_once(&onceToken, ^{
189 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db"), ^(const char *filename) {
192 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-wal"), ^(const char *filename) {
195 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-shm"), ^(const char *filename) {
199 return [CKKSAnalytics defaultAnalyticsDatabasePath:@"ckks_analytics"];
202 + (instancetype)logger
204 // just here because I want it in the header for discoverability
205 return [super logger];
208 - (void)logSuccessForEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view
210 [self logSuccessForEventNamed:[NSString stringWithFormat:@"%@-%@", view.zoneName, event]];
211 [self setDateProperty:[NSDate date] forKey:[NSString stringWithFormat:@"last_success_%@-%@", view.zoneName, event]];
214 - (bool)isCKPartialError:(NSError *)error
216 return [error.domain isEqualToString:CKErrorDomain] && error.code == CKErrorPartialFailure;
219 - (void)addCKPartialError:(NSMutableDictionary *)errorDictionary error:(NSError *)error depth:(NSUInteger)depth
221 // capture one random underlaying error
222 if ([self isCKPartialError:error]) {
223 NSDictionary<NSString *,NSError *> *partialErrors = error.userInfo[CKPartialErrorsByItemIDKey];
224 if ([partialErrors isKindOfClass:[NSDictionary class]]) {
225 for (NSString *key in partialErrors) {
226 NSError* ckError = partialErrors[key];
227 if (![ckError isKindOfClass:[NSError class]])
229 if ([ckError.domain isEqualToString:CKErrorDomain] && ckError.code == CKErrorBatchRequestFailed) {
232 NSDictionary *res = [self errorChain:ckError depth:(depth + 1)];
234 errorDictionary[@"oneCloudKitPartialFailure"] = res;
242 // if we have underlying errors, capture the chain below the top-most error
243 - (NSDictionary *)errorChain:(NSError *)error depth:(NSUInteger)depth
245 NSMutableDictionary *errorDictionary = nil;
247 if (depth > 5 || ![error isKindOfClass:[NSError class]])
250 errorDictionary = [@{
251 @"domain" : error.domain,
252 @"code" : @(error.code),
255 errorDictionary[@"child"] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:(depth + 1)];
256 [self addCKPartialError:errorDictionary error:error depth:(depth + 1)];
258 return errorDictionary;
261 - (NSDictionary *)createErrorAttributes:(NSError *)error
262 depth:(NSUInteger)depth
263 attributes:(NSDictionary *)attributes
265 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
267 /* Don't allow caller to overwrite our attributes, lets merge them first */
269 [eventAttributes setValuesForKeysWithDictionary:attributes];
272 [eventAttributes setValuesForKeysWithDictionary:@{
273 CKKSAnalyticsAttributeRecoverableError : @(YES),
274 CKKSAnalyticsAttributeErrorDomain : error.domain,
275 CKKSAnalyticsAttributeErrorCode : @(error.code)
278 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
279 [self addCKPartialError:eventAttributes error:error depth:0];
281 return eventAttributes;
284 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event zoneName:(NSString*)zoneName withAttributes:(NSDictionary *)attributes
289 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
291 /* Don't allow caller to overwrite our attributes, lets merge them first */
293 [eventAttributes setValuesForKeysWithDictionary:attributes];
296 [eventAttributes setValuesForKeysWithDictionary:@{
297 CKKSAnalyticsAttributeRecoverableError : @(YES),
298 CKKSAnalyticsAttributeZoneName : zoneName,
299 CKKSAnalyticsAttributeErrorDomain : error.domain,
300 CKKSAnalyticsAttributeErrorCode : @(error.code)
303 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
304 [self addCKPartialError:eventAttributes error:error depth:0];
306 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
309 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event withAttributes:(NSDictionary *)attributes
314 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
316 /* Don't allow caller to overwrite our attributes, lets merge them first */
318 [eventAttributes setValuesForKeysWithDictionary:attributes];
321 [eventAttributes setValuesForKeysWithDictionary:@{
322 CKKSAnalyticsAttributeRecoverableError : @(YES),
323 CKKSAnalyticsAttributeErrorDomain : error.domain,
324 CKKSAnalyticsAttributeErrorCode : @(error.code)
327 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
328 [self addCKPartialError:eventAttributes error:error depth:0];
330 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
333 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view withAttributes:(NSDictionary *)attributes
338 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
340 /* Don't allow caller to overwrite our attributes, lets merge them first */
342 [eventAttributes setValuesForKeysWithDictionary:attributes];
345 [eventAttributes setValuesForKeysWithDictionary:@{
346 CKKSAnalyticsAttributeRecoverableError : @(YES),
347 CKKSAnalyticsAttributeZoneName : view.zoneName,
348 CKKSAnalyticsAttributeErrorDomain : error.domain,
349 CKKSAnalyticsAttributeErrorCode : @(error.code)
352 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
353 [self addCKPartialError:eventAttributes error:error depth:0];
355 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
358 - (void)logUnrecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view withAttributes:(NSDictionary *)attributes
363 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
365 [eventAttributes setValuesForKeysWithDictionary:attributes];
368 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
369 [self addCKPartialError:eventAttributes error:error depth:0];
371 [eventAttributes setValuesForKeysWithDictionary:@{
372 CKKSAnalyticsAttributeRecoverableError : @(NO),
373 CKKSAnalyticsAttributeZoneName : view.zoneName,
374 CKKSAnalyticsAttributeErrorDomain : error.domain,
375 CKKSAnalyticsAttributeErrorCode : @(error.code)
378 [self logHardFailureForEventNamed:event withAttributes:eventAttributes];
381 - (void)logUnrecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event 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 inView:(CKKSKeychainView*)view
412 [self noteEventNamed:[NSString stringWithFormat:@"%@-%@", view.zoneName, event]];
415 - (NSDate*)dateOfLastSuccessForEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view
417 return [self datePropertyForKey:[NSString stringWithFormat:@"last_success_%@-%@", view.zoneName, event]];
420 - (void)setDateProperty:(NSDate*)date forKey:(NSString*)key inView:(CKKSKeychainView *)view
422 [self setDateProperty:date forKey:[NSString stringWithFormat:@"%@-%@", key, view.zoneName]];
424 - (NSDate *)datePropertyForKey:(NSString *)key inView:(CKKSKeychainView *)view
426 return [self datePropertyForKey:[NSString stringWithFormat:@"%@-%@", key, view.zoneName]];