Skip to content

Commit cb480ec

Browse files
authored
fix: emit sessionDuration (#6102)
1 parent 5d7bca5 commit cb480ec

File tree

1 file changed

+7
-0
lines changed
  • plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import software.aws.toolkits.telemetry.AuthTelemetry
3232
import software.aws.toolkits.telemetry.CredentialSourceId
3333
import software.aws.toolkits.telemetry.CredentialType
3434
import software.aws.toolkits.telemetry.Result
35+
import java.time.Duration
3536
import java.time.Instant
3637

3738
sealed interface ToolkitConnection {
@@ -265,6 +266,7 @@ fun reauthConnectionIfNeeded(
265266
isReAuth = true,
266267
result = Result.Succeeded,
267268
source = source,
269+
tokenProvider = tokenProvider,
268270
)
269271
recordAddConnection(
270272
credentialSourceId = getCredentialIdForTelemetry(connection),
@@ -282,6 +284,7 @@ fun reauthConnectionIfNeeded(
282284
isReAuth = true,
283285
result = result,
284286
source = source,
287+
tokenProvider = tokenProvider,
285288
)
286289
recordAddConnection(
287290
credentialSourceId = getCredentialIdForTelemetry(connection),
@@ -371,6 +374,7 @@ private fun recordLoginWithBrowser(
371374
isReAuth: Boolean,
372375
result: Result,
373376
source: String? = null,
377+
tokenProvider: BearerTokenProvider? = null,
374378
) {
375379
TelemetryService.getInstance().record(null as Project?) {
376380
datum("aws_loginWithBrowser") {
@@ -385,6 +389,9 @@ private fun recordLoginWithBrowser(
385389
reason?.let { metadata("reason", it) }
386390
metadata("result", result.toString())
387391
source?.let { metadata("source", it) }
392+
tokenProvider?.currentToken()?.let { token ->
393+
metadata("sessionDuration", Duration.between(token.createdAt, Instant.now()).toMillis().toString())
394+
}
388395
}
389396
}
390397
}

0 commit comments

Comments
 (0)