Skip to content

Commit 1498d93

Browse files
committed
add metric that indicates when token was successfully written to the json & stored in cache
1 parent 44ec779 commit 1498d93

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/sso/SsoAccessTokenProvider.kt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,19 @@ class SsoAccessTokenProvider(
394394
}
395395

396396
if (registration == null) {
397-
val message = "Unable to load client registration from cache"
397+
val (message, reason) = when {
398+
currentToken.expiresAt.isBefore(Instant.now(clock)) -> Pair(
399+
"Client registration has expired",
400+
"Expired client registration"
401+
)
402+
else -> Pair(
403+
"Unable to load client registration from cache",
404+
"Null client registration"
405+
)
406+
}
398407
sendRefreshCredentialsMetric(
399408
currentToken,
400-
reason = "Null client registration",
409+
reason = reason,
401410
reasonDesc = "Step: Load Registration - $message",
402411
result = Result.Failed
403412
)
@@ -476,19 +485,31 @@ class SsoAccessTokenProvider(
476485
}
477486

478487
private fun saveClientRegistration(registration: ClientRegistration) {
488+
var credentialType: String
479489
try {
480490
when (registration) {
481491
is DeviceAuthorizationClientRegistration -> {
492+
credentialType = DeviceAuthorizationClientRegistration::class.java.name
482493
cache.saveClientRegistration(dagClientRegistrationCacheKey, registration)
483494
}
484495

485496
is PKCEClientRegistration -> {
497+
credentialType = PKCEClientRegistration::class.java.name
486498
cache.saveClientRegistration(pkceClientRegistrationCacheKey, registration)
487499
}
488500
}
489501
} catch (e: Exception) {
502+
AwsTelemetry.createCredentials(
503+
result = Result.Failed,
504+
reason = "Failed to save client registration to cache",
505+
reasonDesc = e.message
506+
)
490507
throw e
491508
}
509+
AwsTelemetry.createCredentials(
510+
result = Result.Succeeded,
511+
reason = "$credentialType successfully written to cache",
512+
)
492513
}
493514

494515
private fun invalidateClientRegistration() {

0 commit comments

Comments
 (0)