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