@@ -25,6 +25,7 @@ import {
25
25
scopesGumby ,
26
26
isIdcSsoConnection ,
27
27
hasExactScopes ,
28
+ getTelemetryMetadataForConn ,
28
29
} from '../../auth/connection'
29
30
import { getLogger } from '../../shared/logger'
30
31
import { Commands } from '../../shared/vscode/commands2'
@@ -35,6 +36,7 @@ import { showReauthenticateMessage } from '../../shared/utilities/messages'
35
36
import { showAmazonQWalkthroughOnce } from '../../amazonq/onboardingPage/walkthrough'
36
37
import { setContext } from '../../shared/vscode/setContext'
37
38
import { isInDevEnv } from '../../shared/vscode/env'
39
+ import { telemetry } from '../../shared/telemetry/telemetry'
38
40
39
41
/** Backwards compatibility for connections w pre-chat scopes */
40
42
export const codeWhispererCoreScopes = [ ...scopesCodeWhispererCore ]
@@ -99,7 +101,7 @@ export class AuthUtil {
99
101
'Amazon Q' ,
100
102
isValidCodeWhispererCoreConnection
101
103
)
102
- public readonly restore = ( ) => this . secondaryAuth . restoreConnection ( )
104
+ public readonly restore = ( source ?: string ) => this . secondaryAuth . restoreConnection ( source )
103
105
104
106
public constructor ( public readonly auth = Auth . instance ) { }
105
107
@@ -402,15 +404,29 @@ export class AuthUtil {
402
404
* auth connections that the Amazon Q extension has cached. We need to remove these
403
405
* as they are irrelevant to the Q extension and can cause issues.
404
406
*/
405
- public async clearExtraConnections ( ) : Promise < void > {
407
+ public async clearExtraConnections ( source : string ) : Promise < void > {
406
408
const currentQConn = this . conn
407
409
// Q currently only maintains 1 connection at a time, so we assume everything else is extra.
408
410
// IMPORTANT: In the case Q starts to manage multiple connections, this implementation will need to be updated.
409
411
const allOtherConnections = ( await this . auth . listConnections ( ) ) . filter ( ( c ) => c . id !== currentQConn ?. id )
410
412
for ( const conn of allOtherConnections ) {
411
413
getLogger ( ) . warn ( `forgetting extra amazon q connection: %O` , conn )
412
- // in a Dev Env the connection may be used by code catalyst, so we forget instead of fully deleting
413
- isInDevEnv ( ) ? await this . auth . forgetConnection ( conn ) : await this . auth . deleteConnection ( conn )
414
+ await telemetry . auth_modifyConnection . run ( async ( ) => {
415
+ telemetry . record ( {
416
+ connectionState : Auth . instance . getConnectionState ( conn ) ?? 'undefined' ,
417
+ source,
418
+ ...( await getTelemetryMetadataForConn ( conn ) ) ,
419
+ } )
420
+
421
+ if ( isInDevEnv ( ) ) {
422
+ telemetry . record ( { action : 'forget' } )
423
+ // in a Dev Env the connection may be used by code catalyst, so we forget instead of fully deleting
424
+ await this . auth . forgetConnection ( conn )
425
+ } else {
426
+ telemetry . record ( { action : 'delete' } )
427
+ await this . auth . deleteConnection ( conn )
428
+ }
429
+ } )
414
430
}
415
431
}
416
432
}
0 commit comments