Skip to content

Commit 5ad1ad3

Browse files
authored
Fixes AB#3448445 add telemetry points inside saveAndLoadAggregatedAccountData (#2827)
Fixes [AB#3448445](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3448445) From the analysis of the added telemetry points, we identified that saveTokenResult() is a problematic area. This method internally call saveAndLoadAggregatedAccountData. So this PR adds more telemetry to identify the main bottleneck.
1 parent ea12611 commit 5ad1ad3

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

common4j/src/main/com/microsoft/identity/common/java/cache/BrokerOAuth2TokenCache.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.microsoft.identity.common.java.interfaces.INameValueStorage;
3030
import com.microsoft.identity.common.java.interfaces.IPlatformComponents;
3131
import com.microsoft.identity.common.java.opentelemetry.AttributeName;
32+
import com.microsoft.identity.common.java.opentelemetry.OTelUtility;
3233
import com.microsoft.identity.common.java.opentelemetry.SpanExtension;
3334
import com.microsoft.identity.common.java.providers.oauth2.OAuth2Strategy;
3435
import com.microsoft.identity.common.java.providers.oauth2.OAuth2TokenCache;
@@ -278,6 +279,7 @@ public ICacheRecord save(@NonNull AccountRecord accountRecord,
278279
@Nullable RefreshTokenRecord refreshTokenRecord,
279280
@Nullable String familyId) throws ClientException {
280281
final String methodName = ":save (5 args)";
282+
final long saveStartTime = System.currentTimeMillis();
281283

282284
final ICacheRecord result;
283285

@@ -319,7 +321,7 @@ public ICacheRecord save(@NonNull AccountRecord accountRecord,
319321
familyId,
320322
mUid
321323
);
322-
324+
OTelUtility.recordElapsedTime(AttributeName.elapsed_time_save_aggregated_account_data.name(), saveStartTime);
323325
return result;
324326
}
325327

@@ -366,6 +368,7 @@ public synchronized List<ICacheRecord> saveAndLoadAggregatedAccountData(
366368
private List<ICacheRecord> loadAggregatedAccountData(final @NonNull AbstractAuthenticationScheme authScheme,
367369
final @NonNull ICacheRecord cacheRecord) {
368370
final String methodName = ":loadAggregatedAccountData";
371+
final long loadStartTime = System.currentTimeMillis();
369372

370373
final String clientId = cacheRecord.getAccessToken().getClientId();
371374
final String target = cacheRecord.getAccessToken().getTarget();
@@ -386,14 +389,17 @@ private List<ICacheRecord> loadAggregatedAccountData(final @NonNull AbstractAuth
386389
return null;
387390
}
388391

389-
return cache.loadWithAggregatedAccountData(
392+
List<ICacheRecord> cacheRecordList = cache.loadWithAggregatedAccountData(
390393
clientId,
391394
applicationIdentifier,
392395
mamEnrollmentIdentifier,
393396
target,
394397
cacheRecord.getAccount(),
395398
authScheme
396399
);
400+
OTelUtility.recordElapsedTime(AttributeName.elapsed_time_load_aggregated_account_data.name(),
401+
loadStartTime);
402+
return cacheRecordList;
397403
}
398404

399405
@Override

common4j/src/main/com/microsoft/identity/common/java/opentelemetry/AttributeName.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,5 +502,15 @@ public enum AttributeName {
502502
/**
503503
* Passkey DOM exception name (if any).
504504
*/
505-
passkey_dom_exception_name
505+
passkey_dom_exception_name,
506+
507+
/**
508+
* Elapsed time (in milliseconds) spent in executing the save() method in BrokerOAuth2TokenCache.
509+
*/
510+
elapsed_time_save_aggregated_account_data,
511+
512+
/**
513+
* Elapsed time (in milliseconds) spent in executing the loadAggregatedAccountData() method in BrokerOAuth2TokenCache.
514+
*/
515+
elapsed_time_load_aggregated_account_data
506516
}

0 commit comments

Comments
 (0)