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 OctagonAnalyticsAttemptedJoin = @"OAAttemptedJoin";
54 NSString* const OctagonAnalyticsLastHealthCheck = @"OAHealthCheck";
55 NSString* const OctagonAnalyticsSOSStatus = @"OASOSStatus";
56 NSString* const OctagonAnalyticsDateOfLastPreflightPreapprovedJoin = @"OALastPPJ";
57 NSString* const OctagonAnalyticsLastKeystateReady = @"OALastKSR";
58 NSString* const OctagonAnalyticsLastCoreFollowup = @"OALastCFU";
59 //NSString* const OctagonAnalyticsCoreFollowupStatus = @"OACFUStatus";
60 NSString* const OctagonAnalyticsCoreFollowupFailureCount = @"OACFUTFailureCount";
61 NSString* const OctagonAnalyticsCoreFollowupLastFailureTime = @"OACFULastFailureTime";
62 NSString* const OctagonAnalyticsPrerecordPending = @"OAPrerecordPending";
63 NSString* const OctagonAnalyticsCDPStateRun = @"OACDPStateRun";
65 NSString* const OctagonAnalyticsHaveMachineID = @"OAMIDPresent";
66 NSString* const OctagonAnalyticsMIDOnMemoizedList = @"OAMIDOnList";
67 NSString* const OctagonAnalyticsPeersWithMID = @"OAPeersWithMID";
69 NSString* const CKKSAnalyticsLastCKKSPush = @"lastCKKSPush";
70 NSString* const CKKSAnalyticsLastOctagonPush = @"lastOctagonPush";
72 NSString* const OctagonAnalyticsKVSProvisioned = @"OADCKVSProvisioned";
73 NSString* const OctagonAnalyticsKVSEnabled = @"OADCKVSEnabled";
74 NSString* const OctagonAnalyticsKeychainSyncProvisioned = @"OADCKCSProvisioned";
75 NSString* const OctagonAnalyticsKeychainSyncEnabled = @"OADCKCSEnabled";
76 NSString* const OctagonAnalyticsCloudKitProvisioned = @"OADCCKProvisioned";
77 NSString* const OctagonAnalyticsCloudKitEnabled = @"OADCCKEnabled";
79 static NSString* const CKKSAnalyticsAttributeRecoverableError = @"recoverableError";
80 static NSString* const CKKSAnalyticsAttributeZoneName = @"zone";
81 static NSString* const CKKSAnalyticsAttributeErrorDomain = @"errorDomain";
82 static NSString* const CKKSAnalyticsAttributeErrorCode = @"errorCode";
83 static NSString* const CKKSAnalyticsAttributeErrorChain = @"errorChain";
85 CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassA = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessIncomingQueueClassA";
86 CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassC = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessIncomingQueueClassC";
87 CKKSAnalyticsFailableEvent* const CKKSEventProcessOutgoingQueue = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessOutgoingQueue";
88 CKKSAnalyticsFailableEvent* const CKKSEventUploadChanges = (CKKSAnalyticsFailableEvent*)@"CKKSEventUploadChanges";
89 CKKSAnalyticsFailableEvent* const CKKSEventStateError = (CKKSAnalyticsFailableEvent*)@"CKKSEventStateError";
90 CKKSAnalyticsFailableEvent* const CKKSEventProcessHealKeyHierarchy = (CKKSAnalyticsFailableEvent *)@"CKKSEventProcessHealKeyHierarchy";
91 CKKSAnalyticsFailableEvent* const CKKSEventProcessReencryption = (CKKSAnalyticsFailableEvent *)@"CKKSEventProcessReencryption";
93 NSString* const OctagonEventFailureReason = @"FailureReason";
95 CKKSAnalyticsFailableEvent* const OctagonEventPreflightBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightBottle";
96 CKKSAnalyticsFailableEvent* const OctagonEventLaunchBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventLaunchBottle";
97 CKKSAnalyticsFailableEvent* const OctagonEventRestoreBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventRestoreBottle";
98 CKKSAnalyticsFailableEvent* const OctagonEventScrubBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventScrubBottle";
99 CKKSAnalyticsFailableEvent* const OctagonEventSignIn = (CKKSAnalyticsFailableEvent *)@"OctagonEventSignIn";
100 CKKSAnalyticsFailableEvent* const OctagonEventSignOut = (CKKSAnalyticsFailableEvent *)@"OctagonEventSignIn";
101 CKKSAnalyticsFailableEvent* const OctagonEventRamp = (CKKSAnalyticsFailableEvent *)@"OctagonEventRamp";
102 CKKSAnalyticsFailableEvent* const OctagonEventBottleCheck = (CKKSAnalyticsFailableEvent *)@"OctagonEventBottleCheck";
103 CKKSAnalyticsFailableEvent* const OctagonEventCoreFollowUp = (CKKSAnalyticsFailableEvent *)@"OctagonEventCoreFollowUp";
104 CKKSAnalyticsFailableEvent* const OctagonEventUpdateBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpdateBottle";
106 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustState = (CKKSAnalyticsFailableEvent *)@"OctagonEventCheckTrustState";
108 CKKSAnalyticsFailableEvent* const OctagonEventBottledPeerRestore = (CKKSAnalyticsFailableEvent*)@"OctagonEventBottledPeerRestore";
109 CKKSAnalyticsFailableEvent* const OctagonEventRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventRecoveryKey";
111 CKKSAnalyticsFailableEvent* const OctagonEventFetchAllBottles = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchAllBottles";
112 CKKSAnalyticsFailableEvent* const OctagonEventFetchEscrowContents = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchEscrowContents";
113 CKKSAnalyticsFailableEvent* const OctagonEventResetAndEstablish = (CKKSAnalyticsFailableEvent*)@"OctagonEventResetAndEstablish";
114 CKKSAnalyticsFailableEvent* const OctagonEventEstablish = (CKKSAnalyticsFailableEvent*)@"OctagonEventEstablish";
115 CKKSAnalyticsFailableEvent* const OctagonEventLeaveClique = (CKKSAnalyticsFailableEvent*)@"OctagonEventLeaveClique";
116 CKKSAnalyticsFailableEvent* const OctagonEventRemoveFriendsInClique = (CKKSAnalyticsFailableEvent*)@"OctagonEventRemoveFriendsInClique";
118 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeFetchDeviceIDs = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeFetchDeviceIDs";
119 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSetAllowList = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeSetAllowList";
120 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSilentEscrow = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeSilentEscrow";
121 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoin = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreapprovedJoin";
122 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreflightPreapprovedJoin = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreflightPreapprovedJoin";
123 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoinAfterPairing = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreapprovedJoinAfterPairing";
124 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePrepare = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePrepare";
126 CKKSAnalyticsFailableEvent* const OctagonEventJoinWithVoucher = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinWithVoucher";
128 CKKSAnalyticsFailableEvent* const OctagonEventPreflightVouchWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightVouchWithBottle";
129 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithBottle";
131 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithRecoveryKey";
133 CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventSetRecoveryKey";
135 CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKeyValidationFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventSetRecoveryKeyValidationFailed";
136 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyValidationFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyValidationFailed";
137 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleReset = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyCircleReset";
138 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleResetFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyCircleResetFailed";
139 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyEnrollFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyEnrollFailed";
140 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyFailed";
142 CKKSAnalyticsFailableEvent* const OctagonEventReset = (CKKSAnalyticsFailableEvent*)@"OctagonEventReset";
144 CKKSAnalyticsFailableEvent* const OctagonEventPrepareIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventPrepareIdentity";
146 CKKSAnalyticsFailableEvent* const OctagonEventEstablishIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventEstablishIdentity";
147 CKKSAnalyticsFailableEvent* const OctagonEventFetchViews = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchViews";
149 CKKSAnalyticsFailableEvent* const OctagonEventStateTransition = (CKKSAnalyticsFailableEvent*)@"OctagonEventStateTransition";
151 CKKSAnalyticsFailableEvent* const OctagonEventCompanionPairing = (CKKSAnalyticsFailableEvent*)@"OctagonEventCompanionPairing";
153 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustForCFU = (CKKSAnalyticsFailableEvent*)@"OctagonEventCheckTrustForCFU";
155 CKKSAnalyticsSignpostEvent* const CKKSEventPushNotificationReceived = (CKKSAnalyticsSignpostEvent*)@"CKKSEventPushNotificationReceived";
156 CKKSAnalyticsSignpostEvent* const CKKSEventItemAddedToOutgoingQueue = (CKKSAnalyticsSignpostEvent*)@"CKKSEventItemAddedToOutgoingQueue";
157 CKKSAnalyticsSignpostEvent* const CKKSEventMissingLocalItemsFound = (CKKSAnalyticsSignpostEvent*)@"CKKSEventMissingLocalItemsFound";
158 CKKSAnalyticsSignpostEvent* const CKKSEventReachabilityTimerExpired = (CKKSAnalyticsSignpostEvent *)@"CKKSEventReachabilityTimerExpired";
160 CKKSAnalyticsFailableEvent* const OctagonEventTPHHealthCheckStatus = (CKKSAnalyticsFailableEvent*)@"OctagonEventTPHHealthCheckStatus";
162 CKKSAnalyticsFailableEvent* const OctagonEventAuthKitDeviceList = (CKKSAnalyticsFailableEvent *)@"OctagonEventAuthKitDeviceList";
164 CKKSAnalyticsActivity* const CKKSActivityOTFetchRampState = (CKKSAnalyticsActivity *)@"CKKSActivityOTFetchRampState";
165 CKKSAnalyticsActivity* const CKKSActivityOctagonPreflightBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonPreflightBottle";
166 CKKSAnalyticsActivity* const CKKSActivityOctagonLaunchBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonLaunchBottle";
167 CKKSAnalyticsActivity* const CKKSActivityOctagonRestore = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonRestore";
168 CKKSAnalyticsActivity* const CKKSActivityScrubBottle = (CKKSAnalyticsActivity *)@"CKKSActivityScrubBottle";
169 CKKSAnalyticsActivity* const CKKSActivityBottleCheck = (CKKSAnalyticsActivity *)@"CKKSActivityBottleCheck";
170 CKKSAnalyticsActivity* const CKKSActivityOctagonUpdateBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonUpdateBottle";
172 CKKSAnalyticsActivity* const OctagonActivityAccountAvailable = (CKKSAnalyticsActivity *)@"OctagonActivityAccountAvailable";
173 CKKSAnalyticsActivity* const OctagonActivityAccountNotAvailable = (CKKSAnalyticsActivity *)@"OctagonActivityAccountNotAvailable";
174 CKKSAnalyticsActivity* const OctagonActivityResetAndEstablish = (CKKSAnalyticsActivity *)@"OctagonActivityResetAndEstablish";
175 CKKSAnalyticsActivity* const OctagonActivityEstablish = (CKKSAnalyticsActivity *)@"OctagonActivityEstablish";
176 CKKSAnalyticsActivity* const OctagonSOSAdapterUpdateKeys = (CKKSAnalyticsActivity*)@"OctagonSOSAdapterUpdateKeys";
178 CKKSAnalyticsActivity* const OctagonActivityFetchAllViableBottles = (CKKSAnalyticsActivity *)@"OctagonActivityFetchAllViableBottles";
179 CKKSAnalyticsActivity* const OctagonActivityFetchEscrowContents = (CKKSAnalyticsActivity *)@"OctagonActivityFetchEscrowContents";
180 CKKSAnalyticsActivity* const OctagonActivityBottledPeerRestore = (CKKSAnalyticsActivity *)@"OctagonActivityBottledPeerRestore";
181 CKKSAnalyticsActivity* const OctagonActivitySetRecoveryKey = (CKKSAnalyticsActivity *)@"OctagonActivitySetRecoveryKey";
182 CKKSAnalyticsActivity* const OctagonActivityJoinWithRecoveryKey = (CKKSAnalyticsActivity *)@"OctagonActivityJoinWithRecoveryKey";
184 CKKSAnalyticsActivity* const OctagonActivityLeaveClique = (CKKSAnalyticsActivity *)@"OctagonActivityLeaveClique";
185 CKKSAnalyticsActivity* const OctagonActivityRemoveFriendsInClique = (CKKSAnalyticsActivity *)@"OctagonActivityRemoveFriendsInClique";
189 @implementation CKKSAnalytics
191 + (NSString*)databasePath
193 // This block exists because we moved database locations in 11.3 for easier sandboxing of securityuploadd, so we're cleaning up.
194 static dispatch_once_t onceToken;
195 dispatch_once(&onceToken, ^{
196 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db"), ^(const char *filename) {
199 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-wal"), ^(const char *filename) {
202 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-shm"), ^(const char *filename) {
206 return [CKKSAnalytics defaultAnalyticsDatabasePath:@"ckks_analytics"];
209 + (instancetype)logger
211 // just here because I want it in the header for discoverability
212 return [super logger];
215 - (void)logSuccessForEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view
217 [self logSuccessForEventNamed:[NSString stringWithFormat:@"%@-%@", view.zoneName, event]];
218 [self setDateProperty:[NSDate date] forKey:[NSString stringWithFormat:@"last_success_%@-%@", view.zoneName, event]];
221 - (bool)isCKPartialError:(NSError *)error
223 return [error.domain isEqualToString:CKErrorDomain] && error.code == CKErrorPartialFailure;
226 - (void)addCKPartialError:(NSMutableDictionary *)errorDictionary error:(NSError *)error depth:(NSUInteger)depth
228 // capture one random underlaying error
229 if ([self isCKPartialError:error]) {
230 NSDictionary<NSString *,NSError *> *partialErrors = error.userInfo[CKPartialErrorsByItemIDKey];
231 if ([partialErrors isKindOfClass:[NSDictionary class]]) {
232 for (NSString *key in partialErrors) {
233 NSError* ckError = partialErrors[key];
234 if (![ckError isKindOfClass:[NSError class]])
236 if ([ckError.domain isEqualToString:CKErrorDomain] && ckError.code == CKErrorBatchRequestFailed) {
239 NSDictionary *res = [self errorChain:ckError depth:(depth + 1)];
241 errorDictionary[@"oneCloudKitPartialFailure"] = res;
249 // if we have underlying errors, capture the chain below the top-most error
250 - (NSDictionary *)errorChain:(NSError *)error depth:(NSUInteger)depth
252 NSMutableDictionary *errorDictionary = nil;
254 if (depth > 5 || ![error isKindOfClass:[NSError class]])
257 errorDictionary = [@{
258 @"domain" : error.domain,
259 @"code" : @(error.code),
262 errorDictionary[@"child"] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:(depth + 1)];
263 [self addCKPartialError:errorDictionary error:error depth:(depth + 1)];
265 return errorDictionary;
268 - (NSDictionary *)createErrorAttributes:(NSError *)error
269 depth:(NSUInteger)depth
270 attributes:(NSDictionary *)attributes
272 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
274 /* Don't allow caller to overwrite our attributes, lets merge them first */
276 [eventAttributes setValuesForKeysWithDictionary:attributes];
279 [eventAttributes setValuesForKeysWithDictionary:@{
280 CKKSAnalyticsAttributeRecoverableError : @(YES),
281 CKKSAnalyticsAttributeErrorDomain : error.domain,
282 CKKSAnalyticsAttributeErrorCode : @(error.code)
285 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
286 [self addCKPartialError:eventAttributes error:error depth:0];
288 return eventAttributes;
291 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event zoneName:(NSString*)zoneName withAttributes:(NSDictionary *)attributes
296 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
298 /* Don't allow caller to overwrite our attributes, lets merge them first */
300 [eventAttributes setValuesForKeysWithDictionary:attributes];
303 [eventAttributes setValuesForKeysWithDictionary:@{
304 CKKSAnalyticsAttributeRecoverableError : @(YES),
305 CKKSAnalyticsAttributeZoneName : zoneName,
306 CKKSAnalyticsAttributeErrorDomain : error.domain,
307 CKKSAnalyticsAttributeErrorCode : @(error.code)
310 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
311 [self addCKPartialError:eventAttributes error:error depth:0];
313 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
316 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event withAttributes:(NSDictionary *)attributes
321 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
323 /* Don't allow caller to overwrite our attributes, lets merge them first */
325 [eventAttributes setValuesForKeysWithDictionary:attributes];
328 [eventAttributes setValuesForKeysWithDictionary:@{
329 CKKSAnalyticsAttributeRecoverableError : @(YES),
330 CKKSAnalyticsAttributeErrorDomain : error.domain,
331 CKKSAnalyticsAttributeErrorCode : @(error.code)
334 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
335 [self addCKPartialError:eventAttributes error:error depth:0];
337 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
340 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view withAttributes:(NSDictionary *)attributes
345 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
347 /* Don't allow caller to overwrite our attributes, lets merge them first */
349 [eventAttributes setValuesForKeysWithDictionary:attributes];
352 [eventAttributes setValuesForKeysWithDictionary:@{
353 CKKSAnalyticsAttributeRecoverableError : @(YES),
354 CKKSAnalyticsAttributeZoneName : view.zoneName,
355 CKKSAnalyticsAttributeErrorDomain : error.domain,
356 CKKSAnalyticsAttributeErrorCode : @(error.code)
359 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
360 [self addCKPartialError:eventAttributes error:error depth:0];
362 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
365 - (void)logUnrecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view withAttributes:(NSDictionary *)attributes
370 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
372 [eventAttributes setValuesForKeysWithDictionary:attributes];
375 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
376 [self addCKPartialError:eventAttributes error:error depth:0];
378 [eventAttributes setValuesForKeysWithDictionary:@{
379 CKKSAnalyticsAttributeRecoverableError : @(NO),
380 CKKSAnalyticsAttributeZoneName : view.zoneName,
381 CKKSAnalyticsAttributeErrorDomain : error.domain,
382 CKKSAnalyticsAttributeErrorCode : @(error.code)
385 [self logHardFailureForEventNamed:event withAttributes:eventAttributes];
388 - (void)logUnrecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event withAttributes:(NSDictionary *)attributes
393 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
395 /* Don't allow caller to overwrite our attributes, lets merge them first */
397 [eventAttributes setValuesForKeysWithDictionary:attributes];
400 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
401 [self addCKPartialError:eventAttributes error:error depth:0];
403 [eventAttributes setValuesForKeysWithDictionary:@{
404 CKKSAnalyticsAttributeRecoverableError : @(NO),
405 CKKSAnalyticsAttributeZoneName : OctagonEventAttributeZoneName,
406 CKKSAnalyticsAttributeErrorDomain : error.domain,
407 CKKSAnalyticsAttributeErrorCode : @(error.code)
410 [self logHardFailureForEventNamed:event withAttributes:eventAttributes];
413 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event
415 [self noteEventNamed:event];
417 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event inView:(CKKSKeychainView*)view
419 [self noteEventNamed:[NSString stringWithFormat:@"%@-%@", view.zoneName, event]];
422 - (NSDate*)dateOfLastSuccessForEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view
424 return [self datePropertyForKey:[NSString stringWithFormat:@"last_success_%@-%@", view.zoneName, event]];
427 - (void)setDateProperty:(NSDate*)date forKey:(NSString*)key inView:(CKKSKeychainView *)view
429 [self setDateProperty:date forKey:[NSString stringWithFormat:@"%@-%@", key, view.zoneName]];
431 - (NSDate *)datePropertyForKey:(NSString *)key inView:(CKKSKeychainView *)view
433 return [self datePropertyForKey:[NSString stringWithFormat:@"%@-%@", key, view.zoneName]];