Skip to content

Commit a25c555

Browse files
committed
add metrics to saveClientRegistration
1 parent 2ddb12c commit a25c555

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ class SsoAccessTokenProvider(
399399
"Reauth Required: $stageName",
400400
"Expired client registration"
401401
)
402-
// TODO: reauth
403402
else -> Pair(
404403
"Unable to load client registration from cache: $stageName",
405404
"Null client registration"
@@ -481,17 +480,32 @@ class SsoAccessTokenProvider(
481480
}
482481

483482
private fun saveClientRegistration(registration: ClientRegistration) {
484-
when (registration) {
485-
is DeviceAuthorizationClientRegistration -> {
486-
cache.saveClientRegistration(dagClientRegistrationCacheKey, registration)
487-
}
483+
val credentialType = registration::class.java.name
484+
try {
485+
when (registration) {
486+
is DeviceAuthorizationClientRegistration -> {
487+
cache.saveClientRegistration(dagClientRegistrationCacheKey, registration)
488+
}
488489

489-
is PKCEClientRegistration -> {
490-
cache.saveClientRegistration(pkceClientRegistrationCacheKey, registration)
490+
is PKCEClientRegistration -> {
491+
cache.saveClientRegistration(pkceClientRegistrationCacheKey, registration)
492+
}
491493
}
494+
} catch (e: Exception) {
495+
AwsTelemetry.openCredentials(
496+
result = Result.Failed,
497+
reason = "$credentialType failed to write to cache",
498+
reasonDesc = e.message
499+
)
500+
throw e
492501
}
502+
AwsTelemetry.createCredentials(
503+
result = Result.Succeeded,
504+
reason = "$credentialType successfully written to cache",
505+
)
493506
}
494507

508+
495509
private fun invalidateClientRegistration() {
496510
cache.invalidateClientRegistration(dagClientRegistrationCacheKey)
497511
cache.invalidateClientRegistration(pkceClientRegistrationCacheKey)

0 commit comments

Comments
 (0)