Skip to content

Commit e74072a

Browse files
committed
add more metrics to catch blocks.
1 parent 7504455 commit e74072a

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ import software.aws.toolkits.jetbrains.utils.sleepWithCancellation
2828
import software.aws.toolkits.resources.AwsCoreBundle
2929
import software.aws.toolkits.telemetry.AuthType
3030
import software.aws.toolkits.telemetry.AwsTelemetry
31+
import software.aws.toolkits.telemetry.CredentialModification
3132
import software.aws.toolkits.telemetry.CredentialSourceId
3233
import software.aws.toolkits.telemetry.Result
3334
import java.io.FileNotFoundException
35+
import java.io.IOException
3436
import java.time.Clock
3537
import java.time.Duration
3638
import java.time.Instant
@@ -442,14 +444,15 @@ class SsoAccessTokenProvider(
442444
is AwsServiceException -> e.requestId()
443445
else -> null
444446
}
445-
447+
// AwsServiceException#message will automatically pull in AwsServiceException#awsErrorDetails
448+
// we expect messages for SsoOidcException to be populated in e.message using execution executor added in
449+
// https://github.com/aws/aws-toolkit-jetbrains/commit/cc9ed87fa9391dd39ac05cbf99b4437112fa3d10
446450
val message = e.message ?: "$stageName: ${e::class.java.name}"
447-
val reasonDesc = "Step: $stageName - $message"
448451

449452
sendRefreshCredentialsMetric(
450453
currentToken,
451454
reason = "Refresh access token request failed: $stageName",
452-
reasonDesc = reasonDesc,
455+
reasonDesc = "Step: $message",
453456
requestId = requestId,
454457
result = Result.Failed
455458
)
@@ -469,6 +472,11 @@ class SsoAccessTokenProvider(
469472
return it
470473
}
471474
} catch (e: FileNotFoundException) {
475+
AwsTelemetry.openCredentials(
476+
result = Result.Failed,
477+
reason = "Failed to load DAG client registration from cache",
478+
reasonDesc = e.message
479+
)
472480
throw e
473481
}
474482

@@ -478,6 +486,11 @@ class SsoAccessTokenProvider(
478486
return it as PKCEClientRegistration
479487
}
480488
} catch (e: FileNotFoundException) {
489+
AwsTelemetry.openCredentials(
490+
result = Result.Failed,
491+
reason = "Failed to load PKCE client registration from cache",
492+
reasonDesc = e.message
493+
)
481494
throw e
482495
}
483496

@@ -513,8 +526,14 @@ class SsoAccessTokenProvider(
513526
try {
514527
cache.invalidateClientRegistration(dagClientRegistrationCacheKey)
515528
cache.invalidateClientRegistration(pkceClientRegistrationCacheKey)
516-
} catch (e: Exception) {
517-
throw e
529+
} catch (e: IOException) {
530+
AwsTelemetry.modifyCredentials(
531+
credentialModification = CredentialModification.Delete,
532+
result = Result.Failed,
533+
reason = "Failed to invalidate client registration",
534+
reasonDesc = e.message,
535+
source = "SsoAccessTokenProvider.invalidateClientRegistration"
536+
)
518537
}
519538
}
520539

0 commit comments

Comments
 (0)