@@ -270,12 +270,12 @@ - (BOOL)clearWithContext:(id<MSIDRequestContext>)context
270270- (NSArray <MSIDBaseToken *> *)allTokensWithContext : (id <MSIDRequestContext>)context
271271 error : (NSError **)error
272272{
273- MSIDTelemetryCacheEvent * event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP context: context] ;
273+ CONDITIONAL_START_CACHE_EVENT ( event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP, context) ;
274274
275275 NSArray <MSIDCredentialCacheItem *> *cacheItems = [_accountCredentialCache getAllItemsWithContext: context error: error];
276276 NSArray <MSIDBaseToken *> *tokens = [self validTokensFromCacheItems: cacheItems];
277277
278- [MSIDTelemetry stopCacheEvent: event withItem: nil success: [cacheItems count ] > 0 context: context] ;
278+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , [cacheItems count ] > 0 , context) ;
279279 return tokens;
280280}
281281
@@ -413,7 +413,7 @@ - (BOOL)removeAccessToken:(MSIDAccessToken *)token
413413 MSID_LOG_WITH_CTX (MSIDLogLevelInfo, context, @" (Default accessor) Get accounts." );
414414 MSID_LOG_WITH_CTX_PII (MSIDLogLevelVerbose, context, @" (Default accessor) Get accounts with environment %@ , clientId %@ , familyId %@ , account %@ , username %@ " , authority.environment , clientId, familyId, accountIdentifier.maskedHomeAccountId , accountIdentifier.maskedDisplayableId );
415415
416- MSIDTelemetryCacheEvent * event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP context: context] ;
416+ CONDITIONAL_START_CACHE_EVENT ( event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP, context) ;
417417
418418 NSArray <NSString *> *environmentAliases = [authority defaultCacheEnvironmentAliases ];
419419
@@ -429,7 +429,7 @@ - (BOOL)removeAccessToken:(MSIDAccessToken *)token
429429 if (!allAccounts)
430430 {
431431 MSID_LOG_WITH_CTX (MSIDLogLevelError, context, @" (Default accessor) Failed accounts lookup" );
432- [MSIDTelemetry stopCacheEvent: event withItem: nil success: NO context: context] ;
432+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , NO , context) ;
433433 return nil ;
434434 }
435435
@@ -451,7 +451,7 @@ - (BOOL)removeAccessToken:(MSIDAccessToken *)token
451451 {
452452 *error = localError;
453453 }
454- [MSIDTelemetry stopCacheEvent: event withItem: nil success: NO context: context] ;
454+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , NO , context) ;
455455 return nil ;
456456 }
457457 }
@@ -477,21 +477,21 @@ - (BOOL)removeAccessToken:(MSIDAccessToken *)token
477477 {
478478 *error = localError;
479479 }
480- [MSIDTelemetry stopCacheEvent: event withItem: nil success: NO context: context] ;
480+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , NO , context) ;
481481 return nil ;
482482 }
483483
484484 if ([returnAccountsSet count ])
485485 {
486486 MSID_LOG_WITH_CTX_PII (MSIDLogLevelInfo, context, @" (Default accessor) Found the following accounts in default accessor: %@ " , MSID_PII_LOG_MASKABLE ([returnAccountsSet allObjects ]));
487487
488- [MSIDTelemetry stopCacheEvent: event withItem: nil success: YES context: context] ;
488+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , YES , context) ;
489489 }
490490 else
491491 {
492492 MSID_LOG_WITH_CTX (MSIDLogLevelInfo, context, @" (Default accessor) No accounts found in default accessor." );
493493 NSError *wipeError = nil ;
494- [MSIDTelemetry stopFailedCacheEvent: event wipeData: [_accountCredentialCache wipeInfoWithContext: context error: &wipeError] context: context] ;
494+ CONDITIONAL_STOP_FAILED_CACHE_EVENT ( event, [_accountCredentialCache wipeInfoWithContext: context error: &wipeError], context) ;
495495 if (wipeError) MSID_LOG_WITH_CTX_PII (MSIDLogLevelWarning, context, @" Failed to read wipe info with error %@ " , MSID_PII_LOG_MASKABLE (wipeError));
496496 }
497497
@@ -528,7 +528,7 @@ - (MSIDAccount *)getAccountForIdentifier:(MSIDAccountIdentifier *)accountIdentif
528528{
529529 MSID_LOG_WITH_CTX_PII (MSIDLogLevelVerbose, context, @" (Default accessor) Looking for account with authority %@ , legacy user ID %@ , home account ID %@ " , authority.url , accountIdentifier.maskedDisplayableId , accountIdentifier.maskedHomeAccountId );
530530
531- MSIDTelemetryCacheEvent * event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP context: context] ;
531+ CONDITIONAL_START_CACHE_EVENT ( event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP, context) ;
532532
533533 MSIDDefaultAccountCacheQuery *cacheQuery = [MSIDDefaultAccountCacheQuery new ];
534534 cacheQuery.homeAccountId = accountIdentifier.homeAccountId ;
@@ -546,7 +546,7 @@ - (MSIDAccount *)getAccountForIdentifier:(MSIDAccountIdentifier *)accountIdentif
546546 {
547547 MSID_LOG_WITH_CTX (MSIDLogLevelWarning, context, @" (Default accessor) Failed to retrieve account with authority %@ " , authority.url );
548548 NSError *wipeError = nil ;
549- [MSIDTelemetry stopFailedCacheEvent: event wipeData: [_accountCredentialCache wipeInfoWithContext: context error: &wipeError] context: context] ;
549+ CONDITIONAL_STOP_FAILED_CACHE_EVENT ( event, [_accountCredentialCache wipeInfoWithContext: context error: &wipeError], context) ;
550550 if (wipeError) MSID_LOG_WITH_CTX_PII (MSIDLogLevelWarning, context, @" Failed to read wipe info with error %@ " , MSID_PII_LOG_MASKABLE (wipeError));
551551 return nil ;
552552 }
@@ -569,7 +569,7 @@ Note that lookup by realmHint is a best effort (hence it is a hint), because dev
569569 if (!firstAccount) firstAccount = account;
570570 }
571571
572- [MSIDTelemetry stopCacheEvent: event withItem: nil success: YES context: context] ;
572+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , YES , context) ;
573573 return firstAccount;
574574}
575575
@@ -607,7 +607,7 @@ - (BOOL)clearCacheForAccount:(MSIDAccountIdentifier *)accountIdentifier
607607
608608 MSID_LOG_WITH_CTX_PII (MSIDLogLevelInfo, context, @" (Default accessor) Clearing cache for environment: %@ , client ID %@ , family ID %@ , account %@ " , authority.environment , clientId, familyId, accountIdentifier.maskedHomeAccountId );
609609
610- MSIDTelemetryCacheEvent * event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_TOKEN_CACHE_DELETE context: context] ;
610+ CONDITIONAL_START_CACHE_EVENT ( event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_DELETE, context) ;
611611
612612 NSString *homeAccountId = accountIdentifier.homeAccountId ;
613613
@@ -659,11 +659,11 @@ - (BOOL)clearCacheForAccount:(MSIDAccountIdentifier *)accountIdentifier
659659 }
660660 }
661661
662- [MSIDTelemetry stopCacheEvent: event withItem: nil success: result context: context] ;
662+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , result, context) ;
663663 }
664664 else
665665 {
666- [MSIDTelemetry stopCacheEvent: event withItem: nil success: YES context: context] ;
666+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , YES , context) ;
667667 }
668668
669669 // Clear cache from other accessors
@@ -688,7 +688,7 @@ - (BOOL)clearCacheForAllAccountsWithContext:(id<MSIDRequestContext>)context
688688{
689689 MSID_LOG_WITH_CTX_PII (MSIDLogLevelInfo, context, @" (Default accessor) Clearing cache for all accounts" );
690690
691- MSIDTelemetryCacheEvent * event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_TOKEN_CACHE_DELETE context: context] ;
691+ CONDITIONAL_START_CACHE_EVENT ( event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_DELETE, context) ;
692692
693693 BOOL result = YES ;
694694 NSError *accountRemovalError;
@@ -701,7 +701,7 @@ - (BOOL)clearCacheForAllAccountsWithContext:(id<MSIDRequestContext>)context
701701 if (error) *error = accountRemovalError;
702702 }
703703
704- [MSIDTelemetry stopCacheEvent: event withItem: nil success: result context: context] ;
704+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , result, context) ;
705705
706706 // Clear cache from other accessors
707707 for (id <MSIDCacheAccessor> accessor in _otherAccessors)
@@ -932,15 +932,15 @@ - (BOOL)removeToken:(MSIDBaseToken *)token
932932 return NO ;
933933 }
934934
935- MSIDTelemetryCacheEvent * event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_TOKEN_CACHE_DELETE context: context] ;
935+ CONDITIONAL_START_CACHE_EVENT ( event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_DELETE, context) ;
936936 BOOL result = [_accountCredentialCache removeCredential: token.tokenCacheItem context: context error: error];
937937
938938 if (result && token.credentialType == MSIDRefreshTokenType)
939939 {
940940 [_accountCredentialCache saveWipeInfoWithContext: context error: nil ];
941941 }
942942
943- [MSIDTelemetry stopCacheEvent: event withItem: token success: result context: context] ;
943+ CONDITIONAL_STOP_CACHE_EVENT ( event, token, result, context) ;
944944 return result;
945945}
946946
@@ -951,7 +951,7 @@ - (NSString *)homeAccountIdForLegacyId:(NSString *)legacyAccountId
951951 context : (id <MSIDRequestContext>)context
952952 error : (NSError **)error
953953{
954- MSIDTelemetryCacheEvent * event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP context: context] ;
954+ CONDITIONAL_START_CACHE_EVENT ( event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP, context) ;
955955
956956 MSIDDefaultAccountCacheQuery *accountsQuery = [MSIDDefaultAccountCacheQuery new ];
957957 accountsQuery.username = legacyAccountId;
@@ -964,12 +964,12 @@ - (NSString *)homeAccountIdForLegacyId:(NSString *)legacyAccountId
964964
965965 if ([accountCacheItems count ])
966966 {
967- [MSIDTelemetry stopCacheEvent: event withItem: nil success: YES context: context] ;
967+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , YES , context) ;
968968 MSIDAccountCacheItem *accountCacheItem = accountCacheItems[0 ];
969969 return accountCacheItem.homeAccountId ;
970970 }
971971
972- [MSIDTelemetry stopCacheEvent: event withItem: nil success: NO context: context] ;
972+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , NO , context) ;
973973 return nil ;
974974}
975975
@@ -978,7 +978,7 @@ - (MSIDBaseToken *)getTokenWithEnvironment:(NSString *)environment
978978 context : (id <MSIDRequestContext>)context
979979 error : (NSError **)error
980980{
981- MSIDTelemetryCacheEvent * event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP context: context] ;
981+ CONDITIONAL_START_CACHE_EVENT ( event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP, context) ;
982982
983983 MSID_LOG_WITH_CTX (MSIDLogLevelVerbose, context, @" (Default accessor) Looking for token with aliases %@ , tenant %@ , clientId %@ , scopes %@ " , cacheQuery.environmentAliases , cacheQuery.realm , cacheQuery.clientId , cacheQuery.target );
984984
@@ -988,27 +988,27 @@ - (MSIDBaseToken *)getTokenWithEnvironment:(NSString *)environment
988988 if (cacheError)
989989 {
990990 if (error) *error = cacheError;
991- [MSIDTelemetry stopCacheEvent: event withItem: nil success: NO context: context] ;
991+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , NO , context) ;
992992 return nil ;
993993 }
994994
995995 MSID_LOG_WITH_CTX (MSIDLogLevelVerbose, context, @" (Default accessor) Found %lu tokens" , (unsigned long )[resultTokens count ]);
996996
997997 if (resultTokens.count > 0 )
998998 {
999- [MSIDTelemetry stopCacheEvent: event withItem: resultTokens[0 ] success: YES context: context] ;
999+ CONDITIONAL_STOP_CACHE_EVENT ( event, resultTokens[0 ], YES , context) ;
10001000 return resultTokens[0 ];
10011001 }
10021002
10031003 if (cacheQuery.credentialType == MSIDRefreshTokenType)
10041004 {
10051005 NSError *wipeError = nil ;
1006- [MSIDTelemetry stopFailedCacheEvent: event wipeData: [_accountCredentialCache wipeInfoWithContext: context error: &wipeError] context: context] ;
1006+ CONDITIONAL_STOP_FAILED_CACHE_EVENT ( event, [_accountCredentialCache wipeInfoWithContext: context error: &wipeError], context) ;
10071007 if (wipeError) MSID_LOG_WITH_CTX_PII (MSIDLogLevelWarning, context, @" Failed to read wipe info with error %@ " , MSID_PII_LOG_MASKABLE (wipeError));
10081008 }
10091009 else
10101010 {
1011- [MSIDTelemetry stopCacheEvent: event withItem: nil success: NO context: context] ;
1011+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , NO , context) ;
10121012 }
10131013 return nil ;
10141014}
@@ -1018,7 +1018,7 @@ - (MSIDBaseToken *)getTokenWithEnvironment:(NSString *)environment
10181018 context : (id <MSIDRequestContext>)context
10191019 error : (NSError **)error
10201020{
1021- MSIDTelemetryCacheEvent * event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP context: context] ;
1021+ CONDITIONAL_START_CACHE_EVENT ( event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_LOOKUP, context) ;
10221022
10231023 MSID_LOG_WITH_CTX (MSIDLogLevelInfo, context, @" (Default accessor) Looking for token with aliases %@ , tenant %@ , clientId %@ , scopes %@ " , cacheQuery.environmentAliases , cacheQuery.realm , cacheQuery.clientId , cacheQuery.target );
10241024
@@ -1029,7 +1029,7 @@ - (MSIDBaseToken *)getTokenWithEnvironment:(NSString *)environment
10291029 if (cacheError)
10301030 {
10311031 if (error) *error = cacheError;
1032- [MSIDTelemetry stopCacheEvent: event withItem: nil success: NO context: context] ;
1032+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , NO , context) ;
10331033 return nil ;
10341034 }
10351035
@@ -1099,11 +1099,11 @@ - (BOOL)saveToken:(MSIDBaseToken *)token
10991099 return NO ;
11001100 }
11011101
1102- MSIDTelemetryCacheEvent * event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_TOKEN_CACHE_WRITE context: context] ;
1102+ CONDITIONAL_START_CACHE_EVENT ( event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_WRITE, context) ;
11031103
11041104 MSIDCredentialCacheItem *cacheItem = token.tokenCacheItem ;
11051105 BOOL result = [_accountCredentialCache saveCredential: cacheItem context: context error: error];
1106- [MSIDTelemetry stopCacheEvent: event withItem: token success: result context: context] ;
1106+ CONDITIONAL_STOP_CACHE_EVENT ( event, token, result, context) ;
11071107 return result;
11081108}
11091109
@@ -1116,11 +1116,11 @@ - (BOOL)saveAccount:(MSIDAccount *)account
11161116 return NO ;
11171117 }
11181118
1119- MSIDTelemetryCacheEvent * event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_TOKEN_CACHE_WRITE context: context] ;
1119+ CONDITIONAL_START_CACHE_EVENT ( event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_WRITE, context) ;
11201120
11211121 MSIDAccountCacheItem *cacheItem = account.accountCacheItem ;
11221122 BOOL result = [_accountCredentialCache saveAccount: cacheItem context: context error: error];
1123- [MSIDTelemetry stopCacheEvent: event withItem: nil success: result context: context] ;
1123+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , result, context) ;
11241124 return result;
11251125}
11261126
@@ -1297,11 +1297,11 @@ - (BOOL)saveAppMetadataWithConfiguration:(MSIDConfiguration *)configuration
12971297 }
12981298
12991299 metadata.environment = [configuration.authority cacheEnvironmentWithContext: context];
1300- MSIDTelemetryCacheEvent *event = [MSIDTelemetry startCacheEventWithName: MSID_TELEMETRY_EVENT_APP_METADATA_WRITE
1301- context: context] ;
1300+
1301+ CONDITIONAL_START_CACHE_EVENT (event, MSID_TELEMETRY_EVENT_APP_METADATA_WRITE, context) ;
13021302
13031303 BOOL result = [_accountCredentialCache saveAppMetadata: metadata context: context error: error];
1304- [MSIDTelemetry stopCacheEvent: event withItem: nil success: result context: context] ;
1304+ CONDITIONAL_STOP_CACHE_EVENT ( event, nil , result, context) ;
13051305
13061306 return result;
13071307}
0 commit comments