]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSAnalytics.m
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / ckks / CKKSAnalytics.m
1 /*
2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #if OCTAGON
25
26 #import <CloudKit/CloudKit.h>
27 #import <CloudKit/CloudKit_Private.h>
28 #import <os/log.h>
29
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>
36 #include <sys/stat.h>
37
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";
49
50 NSString* const OctagonAnalyticsStateMachineState = @"OASMState";
51 NSString* const OctagonAnalyticIcloudAccountState = @"OAiC";
52 NSString* const OctagonAnalyticCDPBitStatus = @"OACDPStatus";
53
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";
67
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";
73
74 NSString* const OctagonAnalyticsHaveMachineID = @"OAMIDPresent";
75 NSString* const OctagonAnalyticsMIDOnMemoizedList = @"OAMIDOnList";
76 NSString* const OctagonAnalyticsPeersWithMID = @"OAPeersWithMID";
77
78 NSString* const CKKSAnalyticsLastCKKSPush = @"lastCKKSPush";
79 NSString* const CKKSAnalyticsLastOctagonPush = @"lastOctagonPush";
80
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
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";
93
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";
101
102 NSString* const OctagonEventFailureReason = @"FailureReason";
103
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";
114
115 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustState = (CKKSAnalyticsFailableEvent *)@"OctagonEventCheckTrustState";
116
117 CKKSAnalyticsFailableEvent* const OctagonEventBottledPeerRestore = (CKKSAnalyticsFailableEvent*)@"OctagonEventBottledPeerRestore";
118 CKKSAnalyticsFailableEvent* const OctagonEventRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventRecoveryKey";
119
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";
126
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";
134
135 CKKSAnalyticsFailableEvent* const OctagonEventJoinWithVoucher = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinWithVoucher";
136
137 CKKSAnalyticsFailableEvent* const OctagonEventPreflightVouchWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightVouchWithBottle";
138 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithBottle";
139
140 CKKSAnalyticsFailableEvent* const OctagonEventPreflightVouchWithRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightVouchWithRecoveryKey";;
141 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithRecoveryKey";
142
143 CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventSetRecoveryKey";
144
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";
151
152 CKKSAnalyticsFailableEvent* const OctagonEventReset = (CKKSAnalyticsFailableEvent*)@"OctagonEventReset";
153
154 CKKSAnalyticsFailableEvent* const OctagonEventPrepareIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventPrepareIdentity";
155
156 CKKSAnalyticsFailableEvent* const OctagonEventEstablishIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventEstablishIdentity";
157 CKKSAnalyticsFailableEvent* const OctagonEventFetchViews = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchViews";
158
159 CKKSAnalyticsFailableEvent* const OctagonEventStateTransition = (CKKSAnalyticsFailableEvent*)@"OctagonEventStateTransition";
160
161 CKKSAnalyticsFailableEvent* const OctagonEventCompanionPairing = (CKKSAnalyticsFailableEvent*)@"OctagonEventCompanionPairing";
162
163 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustForCFU = (CKKSAnalyticsFailableEvent*)@"OctagonEventCheckTrustForCFU";
164
165 CKKSAnalyticsSignpostEvent* const CKKSEventPushNotificationReceived = (CKKSAnalyticsSignpostEvent*)@"CKKSEventPushNotificationReceived";
166 CKKSAnalyticsSignpostEvent* const CKKSEventItemAddedToOutgoingQueue = (CKKSAnalyticsSignpostEvent*)@"CKKSEventItemAddedToOutgoingQueue";
167 CKKSAnalyticsSignpostEvent* const CKKSEventMissingLocalItemsFound = (CKKSAnalyticsSignpostEvent*)@"CKKSEventMissingLocalItemsFound";
168 CKKSAnalyticsSignpostEvent* const CKKSEventReachabilityTimerExpired = (CKKSAnalyticsSignpostEvent *)@"CKKSEventReachabilityTimerExpired";
169
170 CKKSAnalyticsFailableEvent* const OctagonEventTPHHealthCheckStatus = (CKKSAnalyticsFailableEvent*)@"OctagonEventTPHHealthCheckStatus";
171
172 CKKSAnalyticsFailableEvent* const OctagonEventAuthKitDeviceList = (CKKSAnalyticsFailableEvent *)@"OctagonEventAuthKitDeviceList";
173
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";
181
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";
187
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";
193
194 CKKSAnalyticsActivity* const OctagonActivityLeaveClique = (CKKSAnalyticsActivity *)@"OctagonActivityLeaveClique";
195 CKKSAnalyticsActivity* const OctagonActivityRemoveFriendsInClique = (CKKSAnalyticsActivity *)@"OctagonActivityRemoveFriendsInClique";
196
197
198
199 @implementation CKKSAnalytics
200
201 + (NSString*)databasePath
202 {
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) {
207 remove(filename);
208 });
209 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-wal"), ^(const char *filename) {
210 remove(filename);
211 });
212 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-shm"), ^(const char *filename) {
213 remove(filename);
214 });
215 });
216 return [CKKSAnalytics defaultAnalyticsDatabasePath:@"ckks_analytics"];
217 }
218
219 + (instancetype)logger
220 {
221 // just here because I want it in the header for discoverability
222 return [super logger];
223 }
224
225 - (void)logSuccessForEvent:(CKKSAnalyticsFailableEvent*)event zoneName:(NSString*)zoneName
226 {
227 [self logSuccessForEventNamed:[NSString stringWithFormat:@"%@-%@", zoneName, event]];
228 [self setDateProperty:[NSDate date] forKey:[NSString stringWithFormat:@"last_success_%@-%@", zoneName, event]];
229 }
230
231 - (bool)isCKPartialError:(NSError *)error
232 {
233 return [error.domain isEqualToString:CKErrorDomain] && error.code == CKErrorPartialFailure;
234 }
235
236 - (void)addCKPartialError:(NSMutableDictionary *)errorDictionary error:(NSError *)error depth:(NSUInteger)depth
237 {
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]])
245 continue;
246 if ([ckError.domain isEqualToString:CKErrorDomain] && ckError.code == CKErrorBatchRequestFailed) {
247 continue;
248 }
249 NSDictionary *res = [self errorChain:ckError depth:(depth + 1)];
250 if (res) {
251 errorDictionary[@"oneCloudKitPartialFailure"] = res;
252 break;
253 }
254 }
255 }
256 }
257 }
258
259 // if we have underlying errors, capture the chain below the top-most error
260 - (NSDictionary *)errorChain:(NSError *)error depth:(NSUInteger)depth
261 {
262 NSMutableDictionary *errorDictionary = nil;
263
264 if (depth > 5 || ![error isKindOfClass:[NSError class]])
265 return nil;
266
267 errorDictionary = [@{
268 @"domain" : error.domain,
269 @"code" : @(error.code),
270 } mutableCopy];
271
272 errorDictionary[@"child"] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:(depth + 1)];
273 [self addCKPartialError:errorDictionary error:error depth:(depth + 1)];
274
275 return errorDictionary;
276 }
277
278 - (NSDictionary *)createErrorAttributes:(NSError *)error
279 depth:(NSUInteger)depth
280 attributes:(NSDictionary *)attributes
281 {
282 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
283
284 /* Don't allow caller to overwrite our attributes, lets merge them first */
285 if (attributes) {
286 [eventAttributes setValuesForKeysWithDictionary:attributes];
287 }
288
289 [eventAttributes setValuesForKeysWithDictionary:@{
290 CKKSAnalyticsAttributeRecoverableError : @(YES),
291 CKKSAnalyticsAttributeErrorDomain : error.domain,
292 CKKSAnalyticsAttributeErrorCode : @(error.code)
293 }];
294
295 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
296 [self addCKPartialError:eventAttributes error:error depth:0];
297
298 return eventAttributes;
299 }
300
301 - (void)logRecoverableError:(NSError*)error
302 forEvent:(CKKSAnalyticsFailableEvent*)event
303 zoneName:(NSString*)zoneName
304 withAttributes:(NSDictionary *)attributes
305 {
306 if (error == nil){
307 return;
308 }
309 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
310
311 /* Don't allow caller to overwrite our attributes, lets merge them first */
312 if (attributes) {
313 [eventAttributes setValuesForKeysWithDictionary:attributes];
314 }
315
316 [eventAttributes setValuesForKeysWithDictionary:@{
317 CKKSAnalyticsAttributeRecoverableError : @(YES),
318 CKKSAnalyticsAttributeZoneName : zoneName,
319 CKKSAnalyticsAttributeErrorDomain : error.domain,
320 CKKSAnalyticsAttributeErrorCode : @(error.code)
321 }];
322
323 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
324 [self addCKPartialError:eventAttributes error:error depth:0];
325
326 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
327 }
328
329 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event withAttributes:(NSDictionary *)attributes
330 {
331 if (error == nil){
332 return;
333 }
334 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
335
336 /* Don't allow caller to overwrite our attributes, lets merge them first */
337 if (attributes) {
338 [eventAttributes setValuesForKeysWithDictionary:attributes];
339 }
340
341 [eventAttributes setValuesForKeysWithDictionary:@{
342 CKKSAnalyticsAttributeRecoverableError : @(YES),
343 CKKSAnalyticsAttributeErrorDomain : error.domain,
344 CKKSAnalyticsAttributeErrorCode : @(error.code)
345 }];
346
347 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
348 [self addCKPartialError:eventAttributes error:error depth:0];
349
350 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
351 }
352
353 - (void)logUnrecoverableError:(NSError*)error
354 forEvent:(CKKSAnalyticsFailableEvent*)event
355 zoneName:(NSString*)zoneName
356 withAttributes:(NSDictionary *)attributes
357 {
358 if (error == nil){
359 return;
360 }
361 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
362 if (attributes) {
363 [eventAttributes setValuesForKeysWithDictionary:attributes];
364 }
365
366 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
367 [self addCKPartialError:eventAttributes error:error depth:0];
368
369 [eventAttributes setValuesForKeysWithDictionary:@{
370 CKKSAnalyticsAttributeRecoverableError : @(NO),
371 CKKSAnalyticsAttributeZoneName : zoneName,
372 CKKSAnalyticsAttributeErrorDomain : error.domain,
373 CKKSAnalyticsAttributeErrorCode : @(error.code)
374 }];
375
376 [self logHardFailureForEventNamed:event withAttributes:eventAttributes];
377 }
378
379 - (void)logUnrecoverableError:(NSError*)error
380 forEvent:(CKKSAnalyticsFailableEvent*)event
381 withAttributes:(NSDictionary *)attributes
382 {
383 if (error == nil){
384 return;
385 }
386 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
387
388 /* Don't allow caller to overwrite our attributes, lets merge them first */
389 if (attributes) {
390 [eventAttributes setValuesForKeysWithDictionary:attributes];
391 }
392
393 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
394 [self addCKPartialError:eventAttributes error:error depth:0];
395
396 [eventAttributes setValuesForKeysWithDictionary:@{
397 CKKSAnalyticsAttributeRecoverableError : @(NO),
398 CKKSAnalyticsAttributeZoneName : OctagonEventAttributeZoneName,
399 CKKSAnalyticsAttributeErrorDomain : error.domain,
400 CKKSAnalyticsAttributeErrorCode : @(error.code)
401 }];
402
403 [self logHardFailureForEventNamed:event withAttributes:eventAttributes];
404 }
405
406 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event
407 {
408 [self noteEventNamed:event];
409 }
410 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event zoneName:(NSString*)zoneName
411 {
412 [self noteEventNamed:[NSString stringWithFormat:@"%@-%@", zoneName, event]];
413 }
414
415 - (NSDate*)dateOfLastSuccessForEvent:(CKKSAnalyticsFailableEvent*)event zoneName:(NSString*)zoneName
416 {
417 return [self datePropertyForKey:[NSString stringWithFormat:@"last_success_%@-%@", zoneName, event]];
418 }
419
420 - (void)setDateProperty:(NSDate*)date forKey:(NSString*)key zoneName:(NSString*)zoneName
421 {
422 [self setDateProperty:date forKey:[NSString stringWithFormat:@"%@-%@", key, zoneName]];
423 }
424 - (NSDate *)datePropertyForKey:(NSString *)key zoneName:(NSString*)zoneName
425 {
426 return [self datePropertyForKey:[NSString stringWithFormat:@"%@-%@", key, zoneName]];
427 }
428
429 @end
430
431 #endif // OCTAGON