@@ -11,6 +11,7 @@ import com.intellij.openapi.progress.ProgressManager
1111import com.intellij.openapi.util.registry.Registry
1212import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider
1313import software.amazon.awssdk.awscore.exception.AwsServiceException
14+ import software.amazon.awssdk.core.exception.SdkServiceException
1415import software.amazon.awssdk.services.ssooidc.SsoOidcClient
1516import software.amazon.awssdk.services.ssooidc.model.AuthorizationPendingException
1617import software.amazon.awssdk.services.ssooidc.model.CreateTokenResponse
@@ -338,11 +339,34 @@ class SsoAccessTokenProvider(
338339 throw ProcessCanceledException (IllegalStateException (" Login canceled by user" ))
339340 }
340341
341- val tokenResponse = client.createToken {
342- it.clientId(registration.clientId)
343- it.clientSecret(registration.clientSecret)
344- it.grantType(DEVICE_GRANT_TYPE )
345- it.deviceCode(authorization.deviceCode)
342+ val startTime = clock.instant()
343+ val tokenResponse = try {
344+ client.createToken {
345+ it.clientId(registration.clientId)
346+ it.clientSecret(registration.clientSecret)
347+ it.grantType(DEVICE_GRANT_TYPE )
348+ it.deviceCode(authorization.deviceCode)
349+ }.also {
350+ val duration = Duration .between(startTime, clock.instant()).toMillis().toDouble()
351+ AuthTelemetry .ssoTokenOperation(
352+ result = Result .Succeeded ,
353+ grantType = DEVICE_GRANT_TYPE ,
354+ duration = duration
355+ )
356+ LOG .info { " SSO token operation succeeded: grantType=$DEVICE_GRANT_TYPE , duration=${duration} ms" }
357+ }
358+ } catch (e: Exception ) {
359+ val duration = Duration .between(startTime, clock.instant()).toMillis().toDouble()
360+ AuthTelemetry .ssoTokenOperation(
361+ result = Result .Failed ,
362+ grantType = DEVICE_GRANT_TYPE ,
363+ duration = duration,
364+ reason = e::class .simpleName,
365+ reasonDesc = e.message?.let { scrubNames(it) },
366+ httpStatusCode = (e as ? SdkServiceException )?.statusCode()?.toString()
367+ )
368+ LOG .warn { " SSO token operation failed: grantType=$DEVICE_GRANT_TYPE , duration=${duration} ms, error=${e::class .simpleName} " }
369+ throw e
346370 }
347371
348372 onPendingToken.tokenRetrieved()
@@ -459,11 +483,34 @@ class SsoAccessTokenProvider(
459483
460484 stageName = RefreshCredentialStage .CREATE_TOKEN
461485 try {
462- val newToken = client.createToken {
463- it.clientId(registration.clientId)
464- it.clientSecret(registration.clientSecret)
465- it.grantType(REFRESH_GRANT_TYPE )
466- it.refreshToken(currentToken.refreshToken)
486+ val startTime = clock.instant()
487+ val newToken = try {
488+ client.createToken {
489+ it.clientId(registration.clientId)
490+ it.clientSecret(registration.clientSecret)
491+ it.grantType(REFRESH_GRANT_TYPE )
492+ it.refreshToken(currentToken.refreshToken)
493+ }.also {
494+ val duration = Duration .between(startTime, clock.instant()).toMillis().toDouble()
495+ AuthTelemetry .ssoTokenOperation(
496+ result = Result .Succeeded ,
497+ grantType = REFRESH_GRANT_TYPE ,
498+ duration = duration
499+ )
500+ LOG .info { " SSO token operation succeeded: grantType=$REFRESH_GRANT_TYPE , duration=${duration} ms" }
501+ }
502+ } catch (e: Exception ) {
503+ val duration = Duration .between(startTime, clock.instant()).toMillis().toDouble()
504+ AuthTelemetry .ssoTokenOperation(
505+ result = Result .Failed ,
506+ grantType = REFRESH_GRANT_TYPE ,
507+ duration = duration,
508+ reason = e::class .simpleName,
509+ reasonDesc = e.message?.let { scrubNames(it) },
510+ httpStatusCode = (e as ? SdkServiceException )?.statusCode()?.toString()
511+ )
512+ LOG .warn { " SSO token operation failed: grantType=$REFRESH_GRANT_TYPE , duration=${duration} ms, error=${e::class .simpleName} " }
513+ throw e
467514 }
468515
469516 stageName = RefreshCredentialStage .GET_TOKEN_DETAILS
0 commit comments