Skip to content

Commit a74994d

Browse files
authored
Add metadata to authAddConnection metrics (#4943)
* Add metadata to authAddConnection metrics * detekt
1 parent 280b6fd commit a74994d

File tree

11 files changed

+69
-65
lines changed

11 files changed

+69
-65
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/auth/AuthController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class AuthController {
8888
AuthFollowUpType.FullAuth,
8989
-> runInEdt {
9090
UiTelemetry.click(project, "amazonq_chatAuthenticate")
91-
requestCredentialsForQ(project, connectionInitiatedFromQChatPanel = true)
91+
requestCredentialsForQ(project, connectionInitiatedFromQChatPanel = true, isReauth = false)
9292
}
9393

9494
AuthFollowUpType.ReAuth,

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/explorerActions/SignInToQAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class SignInToQAction : SignInToQActionBase(message("q.sign.in")) {
2424
UiTelemetry.click(project, "auth_start_Q")
2525

2626
if (!isQWebviewsAvailable()) {
27-
requestCredentialsForQ(project)
27+
requestCredentialsForQ(project, isReauth = false)
2828
} else {
2929
ToolWindowManager.getInstance(project).getToolWindow(AmazonQToolWindowFactory.WINDOW_ID)?.show()
3030
}
@@ -42,7 +42,7 @@ abstract class SignInToQActionBase(actionName: String) : DumbAwareAction(actionN
4242
reauthConnectionIfNeeded(project, it, isReAuth = true)
4343
} ?: run {
4444
runInEdt {
45-
if (requestCredentialsForQ(project)) {
45+
if (requestCredentialsForQ(project, isReauth = false)) {
4646
if (!openMeetQPage(project)) {
4747
return@runInEdt
4848
}

plugins/core/jetbrains-community/resources/telemetryOverride.json

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -810,50 +810,6 @@
810810
"type": "authType"
811811
}
812812
]
813-
},
814-
{
815-
"name": "auth_addConnection",
816-
"description": "Captures the result of adding a new connection in the 'Add New Connection' workflow",
817-
"metadata": [
818-
{
819-
"type": "attempts",
820-
"required": false
821-
},
822-
{
823-
"type": "credentialSourceId"
824-
},
825-
{
826-
"type": "featureId",
827-
"required": false
828-
},
829-
{
830-
"type": "invalidInputFields",
831-
"required": false
832-
},
833-
{
834-
"type": "isAggregated",
835-
"required": false
836-
},
837-
{
838-
"type": "reason",
839-
"required": false
840-
},
841-
{
842-
"type": "result"
843-
},
844-
{
845-
"type": "source",
846-
"required": false
847-
},
848-
{
849-
"type": "credentialStartUrl",
850-
"required": false
851-
},
852-
{
853-
"type": "isReAuth",
854-
"required": false
855-
}
856-
]
857813
}
858814
]
859815
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fun requestCredentialsForCodeWhisperer(
3636
),
3737
isFirstInstance: Boolean = false,
3838
connectionInitiatedFromExplorer: Boolean = false,
39+
isReauth: Boolean = false,
3940
): Boolean {
4041
val authenticationDialog = SetupAuthenticationDialog(
4142
project,
@@ -87,7 +88,8 @@ fun requestCredentialsForCodeWhisperer(
8788
credentialSourceId = authenticationDialog.authType,
8889
isAggregated = true,
8990
attempts = authenticationDialog.attempts + 1,
90-
result = Result.Succeeded
91+
result = Result.Succeeded,
92+
isReAuth = isReauth
9193
)
9294
AuthTelemetry.addedConnections(
9395
project,
@@ -108,6 +110,7 @@ fun requestCredentialsForCodeWhisperer(
108110
isAggregated = false,
109111
attempts = authenticationDialog.attempts + 1,
110112
result = Result.Cancelled,
113+
isReAuth = isReauth
111114
)
112115
}
113116
return isAuthenticationSuccessful
@@ -123,6 +126,7 @@ fun requestCredentialsForQ(
123126
isFirstInstance: Boolean = false,
124127
connectionInitiatedFromExplorer: Boolean = false,
125128
connectionInitiatedFromQChatPanel: Boolean = false,
129+
isReauth: Boolean,
126130
): Boolean {
127131
// try to scope upgrade if we have a codewhisperer connection
128132
val codeWhispererConnection = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(CodeWhispererConnection.getInstance())
@@ -194,7 +198,8 @@ fun requestCredentialsForQ(
194198
credentialSourceId = authenticationDialog.authType,
195199
isAggregated = true,
196200
attempts = authenticationDialog.attempts + 1,
197-
result = Result.Succeeded
201+
result = Result.Succeeded,
202+
isReAuth = isReauth
198203
)
199204
AuthTelemetry.addedConnections(
200205
project,
@@ -215,6 +220,7 @@ fun requestCredentialsForQ(
215220
isAggregated = false,
216221
attempts = authenticationDialog.attempts + 1,
217222
result = Result.Cancelled,
223+
isReAuth = isReauth
218224
)
219225
}
220226
return isAuthenticationSuccessful

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ class SetupAuthenticationDialog(
287287
isAggregated = false,
288288
attempts = ++attempts,
289289
result = Result.Failed,
290-
reason = "ConnectionUnsuccessful"
290+
reason = "ConnectionUnsuccessful",
291+
isReAuth = false
291292
)
292293
} ?: return
293294

@@ -339,7 +340,8 @@ class SetupAuthenticationDialog(
339340
isAggregated = false,
340341
attempts = ++attempts,
341342
result = Result.Failed,
342-
reason = "DuplicateProfileName"
343+
reason = "DuplicateProfileName",
344+
isReAuth = false
343345
)
344346
return
345347
}
@@ -365,7 +367,8 @@ class SetupAuthenticationDialog(
365367
isAggregated = false,
366368
attempts = ++attempts,
367369
result = Result.Failed,
368-
reason = "InvalidCredentials"
370+
reason = "InvalidCredentials",
371+
isReAuth = false
369372
)
370373
return
371374
}
@@ -438,7 +441,8 @@ class SetupAuthenticationDialog(
438441
isAggregated = false,
439442
attempts = ++attempts,
440443
result = Result.Failed,
441-
reason = errorType
444+
reason = errorType,
445+
isReAuth = false
442446
)
443447

444448
LOG.error(e) { errorMessage }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ enum class SourceOfEntry {
181181
FIRST_STARTUP,
182182
Q,
183183
AMAZONQ_CHAT_PANEL,
184+
LOGIN_BROWSER,
184185
UNKNOWN,
185186
;
186187
override fun toString(): String {

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import software.aws.toolkits.jetbrains.core.credentials.sono.SONO_URL
3939
import software.aws.toolkits.jetbrains.core.credentials.sso.PendingAuthorization
4040
import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.InteractiveBearerTokenProvider
4141
import software.aws.toolkits.jetbrains.core.credentials.ssoErrorMessageFromException
42+
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.SourceOfEntry
4243
import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread
4344
import software.aws.toolkits.jetbrains.utils.pollFor
4445
import software.aws.toolkits.resources.AwsCoreBundle
@@ -87,7 +88,7 @@ abstract class LoginBrowser(
8788

8889
private var browserOpenTimer: Timer? = null
8990

90-
private fun startBrowserOpenTimer(startUrl: String, ssoRegion: String) {
91+
private fun startBrowserOpenTimer(startUrl: String, ssoRegion: String, scopes: List<String>) {
9192
browserOpenTimer = Timer()
9293
browserOpenTimer?.schedule(
9394
object : TimerTask() {
@@ -103,7 +104,11 @@ abstract class LoginBrowser(
103104
AuthTelemetry.addConnection(
104105
result = Result.Failed,
105106
reason = "Browser authentication idle for more than 15min",
106-
credentialSourceId = if (startUrl == SONO_URL) CredentialSourceId.AwsId else CredentialSourceId.IamIdentityCenter
107+
credentialSourceId = if (startUrl == SONO_URL) CredentialSourceId.AwsId else CredentialSourceId.IamIdentityCenter,
108+
isAggregated = false,
109+
source = SourceOfEntry.LOGIN_BROWSER.toString(),
110+
featureId = getFeatureId(scopes),
111+
isReAuth = isReAuth(scopes, startUrl)
107112
)
108113
stopAndClearBrowserOpenTimer()
109114
}
@@ -121,7 +126,7 @@ abstract class LoginBrowser(
121126
}
122127

123128
protected val onPendingToken: (InteractiveBearerTokenProvider) -> Unit = { provider ->
124-
startBrowserOpenTimer(provider.startUrl, provider.region)
129+
startBrowserOpenTimer(provider.startUrl, provider.region, provider.scopes)
125130
projectCoroutineScope(project).launch {
126131
val authorization = pollForAuthorization(provider)
127132
if (authorization != null) {
@@ -180,6 +185,7 @@ abstract class LoginBrowser(
180185

181186
open fun loginBuilderId(scopes: List<String>) {
182187
val isReauth = isReAuth(scopes, SONO_URL)
188+
val featureId = getFeatureId(scopes)
183189
val onError: (Exception) -> Unit = { e ->
184190
stopAndClearBrowserOpenTimer()
185191
isUserCancellation(e)
@@ -196,7 +202,10 @@ abstract class LoginBrowser(
196202
result = Result.Failed,
197203
credentialSourceId = CredentialSourceId.AwsId,
198204
reason = e.message,
199-
isReAuth = isReauth
205+
isReAuth = isReauth,
206+
featureId = featureId,
207+
isAggregated = false,
208+
source = SourceOfEntry.LOGIN_BROWSER.toString()
200209
)
201210
}
202211
val onSuccess: () -> Unit = {
@@ -212,7 +221,10 @@ abstract class LoginBrowser(
212221
AuthTelemetry.addConnection(
213222
result = Result.Succeeded,
214223
credentialSourceId = CredentialSourceId.AwsId,
215-
isReAuth = isReauth
224+
isReAuth = isReauth,
225+
featureId = featureId,
226+
isAggregated = true,
227+
source = SourceOfEntry.LOGIN_BROWSER.toString()
216228
)
217229
}
218230

@@ -239,7 +251,7 @@ abstract class LoginBrowser(
239251
region: AwsRegion,
240252
): Pair<(Exception) -> Unit, () -> Unit> {
241253
val isReAuth = isReAuth(scopes, url)
242-
254+
val featureId = getFeatureId(scopes)
243255
val onError: (Exception) -> Unit = { e ->
244256
stopAndClearBrowserOpenTimer()
245257
val message = ssoErrorMessageFromException(e)
@@ -269,6 +281,9 @@ abstract class LoginBrowser(
269281
credentialSourceId = CredentialSourceId.IamIdentityCenter,
270282
reason = message,
271283
isReAuth = isReAuth,
284+
featureId = featureId,
285+
isAggregated = false,
286+
source = SourceOfEntry.LOGIN_BROWSER.toString()
272287
)
273288
}
274289
val onSuccess: () -> Unit = {
@@ -286,7 +301,10 @@ abstract class LoginBrowser(
286301
project = null,
287302
result = Result.Succeeded,
288303
isReAuth = isReAuth,
289-
credentialSourceId = CredentialSourceId.IamIdentityCenter
304+
credentialSourceId = CredentialSourceId.IamIdentityCenter,
305+
featureId = featureId,
306+
isAggregated = true,
307+
source = SourceOfEntry.LOGIN_BROWSER.toString()
290308
)
291309
}
292310
return Pair(onError, onSuccess)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
package software.aws.toolkits.jetbrains.core.webview
55

66
import com.intellij.openapi.util.registry.Registry
7+
import software.aws.toolkits.jetbrains.core.credentials.sono.CODECATALYST_SCOPES
8+
import software.aws.toolkits.jetbrains.core.credentials.sono.Q_SCOPES
79
import software.aws.toolkits.telemetry.AuthType
10+
import software.aws.toolkits.telemetry.FeatureId
811

912
fun getAuthType(region: String = "us-east-1"): AuthType {
1013
val isCommercialRegion = !region.startsWith("us-gov") && !region.startsWith("us-iso") && !region.startsWith("cn")
@@ -14,3 +17,12 @@ fun getAuthType(region: String = "us-east-1"): AuthType {
1417
return AuthType.DeviceCode
1518
}
1619
}
20+
21+
fun getFeatureId(scopes: List<String>): FeatureId =
22+
if (scopes.intersect(Q_SCOPES.toSet()).isNotEmpty()) {
23+
FeatureId.Q
24+
} else if (scopes.intersect(CODECATALYST_SCOPES.toSet()).isNotEmpty()) {
25+
FeatureId.Codecatalyst
26+
} else {
27+
FeatureId.AwsExplorer
28+
}

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/gettingstarted/GettingStartedOnStartup.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class GettingStartedOnStartup : StartupActivity {
4343
featureId = FeatureId.Unknown,
4444
credentialSourceId = CredentialSourceId.Unknown,
4545
isAggregated = true,
46-
result = Result.Succeeded
46+
result = Result.Succeeded,
47+
isReAuth = false
4748
)
4849
AuthTelemetry.addedConnections(
4950
project,
@@ -66,7 +67,8 @@ class GettingStartedOnStartup : StartupActivity {
6667
credentialSourceId = CredentialSourceId.Unknown,
6768
isAggregated = false,
6869
result = Result.Failed,
69-
reason = "Error opening getting started panel"
70+
reason = "Error opening getting started panel",
71+
isReAuth = false
7072
)
7173
AuthTelemetry.addedConnections(
7274
project,

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/gettingstarted/ToolkitGettingStartedAuthUtils.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ fun requestCredentialsForCodeCatalyst(
8989
credentialSourceId = authenticationDialog.authType,
9090
isAggregated = true,
9191
attempts = authenticationDialog.attempts + 1,
92-
result = Result.Succeeded
92+
result = Result.Succeeded,
93+
isReAuth = false
9394
)
9495
AuthTelemetry.addedConnections(
9596
project,
@@ -110,6 +111,7 @@ fun requestCredentialsForCodeCatalyst(
110111
isAggregated = false,
111112
attempts = authenticationDialog.attempts + 1,
112113
result = Result.Cancelled,
114+
isReAuth = false
113115
)
114116
}
115117
return isAuthenticationSuccessful
@@ -157,7 +159,8 @@ fun requestCredentialsForExplorer(
157159
credentialSourceId = authenticationDialog.authType,
158160
isAggregated = true,
159161
attempts = authenticationDialog.attempts + 1,
160-
result = Result.Succeeded
162+
result = Result.Succeeded,
163+
isReAuth = false
161164
)
162165
AuthTelemetry.addedConnections(
163166
project,
@@ -178,6 +181,7 @@ fun requestCredentialsForExplorer(
178181
isAggregated = false,
179182
attempts = authenticationDialog.attempts + 1,
180183
result = Result.Cancelled,
184+
isReAuth = false
181185
)
182186
}
183187
return isAuthSuccessful

0 commit comments

Comments
 (0)