Skip to content

Commit 368b473

Browse files
Merge main into feature/q-lsp
2 parents 3e3babf + 8c69af2 commit 368b473

File tree

5 files changed

+182
-191
lines changed

5 files changed

+182
-191
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/GettingStartedAuthUtils.kt

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread
2727
import software.aws.toolkits.resources.AwsCoreBundle
2828
import software.aws.toolkits.telemetry.AuthTelemetry
2929
import software.aws.toolkits.telemetry.FeatureId
30+
import software.aws.toolkits.telemetry.MetricResult
3031
import software.aws.toolkits.telemetry.Result
32+
import software.aws.toolkits.telemetry.Telemetry
3133

3234
fun requestCredentialsForCodeWhisperer(
3335
project: Project,
@@ -83,16 +85,15 @@ fun requestCredentialsForCodeWhisperer(
8385
)
8486
val isAuthenticationSuccessful = authenticationDialog.showAndGet()
8587
if (isAuthenticationSuccessful) {
86-
AuthTelemetry.addConnection(
87-
project,
88-
source = getSourceOfEntry(SourceOfEntry.CODEWHISPERER, isFirstInstance, connectionInitiatedFromExplorer),
89-
featureId = FeatureId.Codewhisperer,
90-
credentialSourceId = authenticationDialog.authType,
91-
isAggregated = true,
92-
attempts = authenticationDialog.attempts + 1,
93-
result = Result.Succeeded,
94-
isReAuth = isReauth
95-
)
88+
Telemetry.auth.addConnection.use {
89+
it.source(getSourceOfEntry(SourceOfEntry.CODEWHISPERER, isFirstInstance, connectionInitiatedFromExplorer))
90+
.featureId(FeatureId.Codewhisperer)
91+
.credentialSourceId(authenticationDialog.authType)
92+
.isAggregated(true)
93+
.attempts(authenticationDialog.attempts + 1)
94+
.result(MetricResult.Succeeded)
95+
.isReAuth(isReauth)
96+
}
9697
AuthTelemetry.addedConnections(
9798
project,
9899
source = getSourceOfEntry(SourceOfEntry.CODEWHISPERER, isFirstInstance, connectionInitiatedFromExplorer),
@@ -104,16 +105,15 @@ fun requestCredentialsForCodeWhisperer(
104105
result = Result.Succeeded
105106
)
106107
} else {
107-
AuthTelemetry.addConnection(
108-
project,
109-
source = getSourceOfEntry(SourceOfEntry.CODEWHISPERER, isFirstInstance, connectionInitiatedFromExplorer),
110-
featureId = FeatureId.Codewhisperer,
111-
credentialSourceId = authenticationDialog.authType,
112-
isAggregated = false,
113-
attempts = authenticationDialog.attempts + 1,
114-
result = Result.Cancelled,
115-
isReAuth = isReauth
116-
)
108+
Telemetry.auth.addConnection.use {
109+
it.source(getSourceOfEntry(SourceOfEntry.CODEWHISPERER, isFirstInstance, connectionInitiatedFromExplorer))
110+
.featureId(FeatureId.Codewhisperer)
111+
.credentialSourceId(authenticationDialog.authType)
112+
.isAggregated(false)
113+
.attempts(authenticationDialog.attempts + 1)
114+
.result(MetricResult.Cancelled)
115+
.isReAuth(isReauth)
116+
}
117117
}
118118
return isAuthenticationSuccessful
119119
}
@@ -193,16 +193,15 @@ fun requestCredentialsForQ(
193193

194194
val isAuthenticationSuccessful = authenticationDialog.showAndGet()
195195
if (isAuthenticationSuccessful) {
196-
AuthTelemetry.addConnection(
197-
project,
198-
source = getSourceOfEntry(SourceOfEntry.Q, isFirstInstance, connectionInitiatedFromExplorer, connectionInitiatedFromQChatPanel),
199-
featureId = FeatureId.AmazonQ,
200-
credentialSourceId = authenticationDialog.authType,
201-
isAggregated = true,
202-
attempts = authenticationDialog.attempts + 1,
203-
result = Result.Succeeded,
204-
isReAuth = isReauth
205-
)
196+
Telemetry.auth.addConnection.use {
197+
it.source(getSourceOfEntry(SourceOfEntry.Q, isFirstInstance, connectionInitiatedFromExplorer, connectionInitiatedFromQChatPanel))
198+
.featureId(FeatureId.AmazonQ)
199+
.credentialSourceId(authenticationDialog.authType)
200+
.isAggregated(true)
201+
.attempts(authenticationDialog.attempts + 1)
202+
.result(MetricResult.Succeeded)
203+
.isReAuth(isReauth)
204+
}
206205
AuthTelemetry.addedConnections(
207206
project,
208207
source = getSourceOfEntry(SourceOfEntry.Q, isFirstInstance, connectionInitiatedFromExplorer, connectionInitiatedFromQChatPanel),
@@ -214,16 +213,15 @@ fun requestCredentialsForQ(
214213
result = Result.Succeeded
215214
)
216215
} else {
217-
AuthTelemetry.addConnection(
218-
project,
219-
source = getSourceOfEntry(SourceOfEntry.Q, isFirstInstance, connectionInitiatedFromExplorer, connectionInitiatedFromQChatPanel),
220-
featureId = FeatureId.AmazonQ,
221-
credentialSourceId = authenticationDialog.authType,
222-
isAggregated = false,
223-
attempts = authenticationDialog.attempts + 1,
224-
result = Result.Cancelled,
225-
isReAuth = isReauth
226-
)
216+
Telemetry.auth.addConnection.use {
217+
it.source(getSourceOfEntry(SourceOfEntry.Q, isFirstInstance, connectionInitiatedFromExplorer, connectionInitiatedFromQChatPanel))
218+
.featureId(FeatureId.AmazonQ)
219+
.credentialSourceId(authenticationDialog.authType)
220+
.isAggregated(false)
221+
.attempts(authenticationDialog.attempts + 1)
222+
.result(MetricResult.Cancelled)
223+
.isReAuth(isReauth)
224+
}
227225
}
228226
return isAuthenticationSuccessful
229227
}

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/SetupAuthenticationDialog.kt

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ import software.aws.toolkits.jetbrains.utils.runUnderProgressIfNeeded
5252
import software.aws.toolkits.jetbrains.utils.ui.editorNotificationCompoundBorder
5353
import software.aws.toolkits.jetbrains.utils.ui.selected
5454
import software.aws.toolkits.resources.AwsCoreBundle
55-
import software.aws.toolkits.telemetry.AuthTelemetry
5655
import software.aws.toolkits.telemetry.CredentialSourceId
5756
import software.aws.toolkits.telemetry.FeatureId
58-
import software.aws.toolkits.telemetry.Result
57+
import software.aws.toolkits.telemetry.MetricResult
58+
import software.aws.toolkits.telemetry.Telemetry
5959
import java.awt.BorderLayout
6060
import java.util.Optional
6161
import javax.swing.Action
@@ -279,17 +279,16 @@ class SetupAuthenticationDialog(
279279

280280
val connection = authAndUpdateConfig(project, profile, configFilesFacade, {}, {}) { e ->
281281
Messages.showErrorDialog(project, e.message, title)
282-
AuthTelemetry.addConnection(
283-
project,
284-
source = getSourceOfEntry(sourceOfEntry, isFirstInstance, connectionInitiatedFromExplorer, connectionInitiatedFromQChatPanel),
285-
featureId = featureId,
286-
credentialSourceId = CredentialSourceId.IamIdentityCenter,
287-
isAggregated = false,
288-
attempts = ++attempts,
289-
result = Result.Failed,
290-
reason = "ConnectionUnsuccessful",
291-
isReAuth = false
292-
)
282+
Telemetry.auth.addConnection.use {
283+
it.source(getSourceOfEntry(sourceOfEntry, isFirstInstance, connectionInitiatedFromExplorer, connectionInitiatedFromQChatPanel))
284+
.featureId(featureId)
285+
.credentialSourceId(CredentialSourceId.IamIdentityCenter)
286+
.isAggregated(false)
287+
.attempts(++attempts)
288+
.result(MetricResult.Failed)
289+
.reason("ConnectionUnsuccessful")
290+
.isReAuth(false)
291+
}
293292
} ?: return
294293

295294
if (!promptForIdcPermissionSet) {
@@ -332,17 +331,16 @@ class SetupAuthenticationDialog(
332331

333332
if (existingProfiles.containsKey(profileName)) {
334333
Messages.showErrorDialog(project, AwsCoreBundle.message("gettingstarted.setup.iam.profile.exists", profileName), title)
335-
AuthTelemetry.addConnection(
336-
project,
337-
source = getSourceOfEntry(sourceOfEntry, isFirstInstance, connectionInitiatedFromExplorer),
338-
featureId = featureId,
339-
credentialSourceId = CredentialSourceId.SharedCredentials,
340-
isAggregated = false,
341-
attempts = ++attempts,
342-
result = Result.Failed,
343-
reason = "DuplicateProfileName",
344-
isReAuth = false
345-
)
334+
Telemetry.auth.addConnection.use {
335+
it.source(getSourceOfEntry(sourceOfEntry, isFirstInstance, connectionInitiatedFromExplorer))
336+
.featureId(featureId)
337+
.credentialSourceId(CredentialSourceId.SharedCredentials)
338+
.isAggregated(false)
339+
.attempts(++attempts)
340+
.result(MetricResult.Failed)
341+
.reason("DuplicateProfileName")
342+
.isReAuth(false)
343+
}
346344
return
347345
}
348346

@@ -359,17 +357,16 @@ class SetupAuthenticationDialog(
359357

360358
if (callerIdentity == null) {
361359
Messages.showErrorDialog(project, AwsCoreBundle.message("gettingstarted.setup.iam.profile.invalid_credentials"), title)
362-
AuthTelemetry.addConnection(
363-
project,
364-
source = getSourceOfEntry(sourceOfEntry, isFirstInstance, connectionInitiatedFromExplorer),
365-
featureId = featureId,
366-
credentialSourceId = CredentialSourceId.SharedCredentials,
367-
isAggregated = false,
368-
attempts = ++attempts,
369-
result = Result.Failed,
370-
reason = "InvalidCredentials",
371-
isReAuth = false
372-
)
360+
Telemetry.auth.addConnection.use {
361+
it.source(getSourceOfEntry(sourceOfEntry, isFirstInstance, connectionInitiatedFromExplorer))
362+
.featureId(featureId)
363+
.credentialSourceId(CredentialSourceId.SharedCredentials)
364+
.isAggregated(false)
365+
.attempts(++attempts)
366+
.result(MetricResult.Failed)
367+
.reason("InvalidCredentials")
368+
.isReAuth(false)
369+
}
373370
return
374371
}
375372

@@ -432,18 +429,16 @@ class SetupAuthenticationDialog(
432429

433430
private fun handleConfigFacadeError(e: Exception) {
434431
val (errorMessage, errorType) = messageFromConfigFacadeError(e)
435-
436-
AuthTelemetry.addConnection(
437-
project,
438-
source = getSourceOfEntry(sourceOfEntry, isFirstInstance, connectionInitiatedFromExplorer, connectionInitiatedFromQChatPanel),
439-
featureId = featureId,
440-
credentialSourceId = CredentialSourceId.IamIdentityCenter,
441-
isAggregated = false,
442-
attempts = ++attempts,
443-
result = Result.Failed,
444-
reason = errorType,
445-
isReAuth = false
446-
)
432+
Telemetry.auth.addConnection.use {
433+
it.source(getSourceOfEntry(sourceOfEntry, isFirstInstance, connectionInitiatedFromExplorer, connectionInitiatedFromQChatPanel))
434+
.featureId(featureId)
435+
.credentialSourceId(CredentialSourceId.IamIdentityCenter)
436+
.isAggregated(false)
437+
.attempts(++attempts)
438+
.result(MetricResult.Failed)
439+
.reason(errorType)
440+
.isReAuth(false)
441+
}
447442

448443
LOG.error(e) { errorMessage }
449444
Messages.showErrorDialog(project, errorMessage, title)

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/webview/LoginBrowser.kt

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ import software.aws.toolkits.jetbrains.core.gettingstarted.editor.SourceOfEntry
4545
import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread
4646
import software.aws.toolkits.jetbrains.utils.pollFor
4747
import software.aws.toolkits.resources.AwsCoreBundle
48-
import software.aws.toolkits.telemetry.AuthTelemetry
4948
import software.aws.toolkits.telemetry.AuthType
5049
import software.aws.toolkits.telemetry.AwsTelemetry
5150
import software.aws.toolkits.telemetry.CredentialSourceId
5251
import software.aws.toolkits.telemetry.CredentialType
5352
import software.aws.toolkits.telemetry.FeatureId
53+
import software.aws.toolkits.telemetry.MetricResult
5454
import software.aws.toolkits.telemetry.Result
55+
import software.aws.toolkits.telemetry.Telemetry
5556
import java.time.Duration
5657
import java.util.Timer
5758
import java.util.TimerTask
@@ -104,15 +105,15 @@ abstract class LoginBrowser(
104105
authType = getAuthType(ssoRegion),
105106
source = SourceOfEntry.LOGIN_BROWSER.toString(),
106107
)
107-
AuthTelemetry.addConnection(
108-
result = Result.Failed,
109-
reason = "Browser authentication idle for more than 15min",
110-
credentialSourceId = if (startUrl == SONO_URL) CredentialSourceId.AwsId else CredentialSourceId.IamIdentityCenter,
111-
isAggregated = false,
112-
featureId = getFeatureId(scopes),
113-
isReAuth = isReAuth(scopes, startUrl),
114-
source = SourceOfEntry.LOGIN_BROWSER.toString(),
115-
)
108+
Telemetry.auth.addConnection.use {
109+
it.result(MetricResult.Failed)
110+
.reason("Browser authentication idle for more than 15min")
111+
.credentialSourceId(if (startUrl == SONO_URL) CredentialSourceId.AwsId else CredentialSourceId.IamIdentityCenter)
112+
.isAggregated(false)
113+
.featureId(getFeatureId(scopes))
114+
.isReAuth(isReAuth(scopes, startUrl))
115+
.source(SourceOfEntry.LOGIN_BROWSER.toString())
116+
}
116117
stopAndClearBrowserOpenTimer()
117118
}
118119
},
@@ -203,15 +204,15 @@ abstract class LoginBrowser(
203204
authType = getAuthType(SONO_REGION),
204205
source = SourceOfEntry.LOGIN_BROWSER.toString(),
205206
)
206-
AuthTelemetry.addConnection(
207-
result = Result.Failed,
208-
credentialSourceId = CredentialSourceId.AwsId,
209-
reason = e.message,
210-
isReAuth = isReauth,
211-
featureId = featureId,
212-
isAggregated = false,
213-
source = SourceOfEntry.LOGIN_BROWSER.toString()
214-
)
207+
Telemetry.auth.addConnection.use {
208+
it.result(MetricResult.Failed)
209+
.credentialSourceId(CredentialSourceId.AwsId)
210+
.reason(e.message)
211+
.isReAuth(isReauth)
212+
.featureId(featureId)
213+
.isAggregated(false)
214+
.source(SourceOfEntry.LOGIN_BROWSER.toString())
215+
}
215216
}
216217
val onSuccess: () -> Unit = {
217218
stopAndClearBrowserOpenTimer()
@@ -224,14 +225,14 @@ abstract class LoginBrowser(
224225
authType = getAuthType(SONO_REGION),
225226
source = SourceOfEntry.LOGIN_BROWSER.toString(),
226227
)
227-
AuthTelemetry.addConnection(
228-
result = Result.Succeeded,
229-
credentialSourceId = CredentialSourceId.AwsId,
230-
isReAuth = isReauth,
231-
featureId = featureId,
232-
isAggregated = true,
233-
source = SourceOfEntry.LOGIN_BROWSER.toString()
234-
)
228+
Telemetry.auth.addConnection.use {
229+
it.result(MetricResult.Succeeded)
230+
.credentialSourceId(CredentialSourceId.AwsId)
231+
.isReAuth(isReauth)
232+
.featureId(featureId)
233+
.isAggregated(true)
234+
.source(SourceOfEntry.LOGIN_BROWSER.toString())
235+
}
235236
}
236237

237238
loginWithBackgroundContext {
@@ -283,15 +284,15 @@ abstract class LoginBrowser(
283284
authType = getAuthType(region.name),
284285
source = SourceOfEntry.LOGIN_BROWSER.toString()
285286
)
286-
AuthTelemetry.addConnection(
287-
result = result,
288-
credentialSourceId = CredentialSourceId.IamIdentityCenter,
289-
reason = message,
290-
isReAuth = isReAuth,
291-
featureId = featureId,
292-
isAggregated = false,
293-
source = SourceOfEntry.LOGIN_BROWSER.toString()
294-
)
287+
Telemetry.auth.addConnection.use {
288+
it.result(result)
289+
.credentialSourceId(CredentialSourceId.IamIdentityCenter)
290+
.reason(message)
291+
.isReAuth(isReAuth)
292+
.featureId(featureId)
293+
.isAggregated(false)
294+
.source(SourceOfEntry.LOGIN_BROWSER.toString())
295+
}
295296
}
296297
val onSuccess: () -> Unit = {
297298
stopAndClearBrowserOpenTimer()
@@ -305,15 +306,14 @@ abstract class LoginBrowser(
305306
authType = getAuthType(region.name),
306307
source = SourceOfEntry.LOGIN_BROWSER.toString(),
307308
)
308-
AuthTelemetry.addConnection(
309-
project = null,
310-
result = Result.Succeeded,
311-
isReAuth = isReAuth,
312-
credentialSourceId = CredentialSourceId.IamIdentityCenter,
313-
featureId = featureId,
314-
isAggregated = true,
315-
source = SourceOfEntry.LOGIN_BROWSER.toString()
316-
)
309+
Telemetry.auth.addConnection.use {
310+
it.result(MetricResult.Succeeded)
311+
.isReAuth(isReAuth)
312+
.credentialSourceId(CredentialSourceId.IamIdentityCenter)
313+
.featureId(featureId)
314+
.isAggregated(true)
315+
.source(SourceOfEntry.LOGIN_BROWSER.toString())
316+
}
317317
}
318318
return Pair(onError, onSuccess)
319319
}

0 commit comments

Comments
 (0)