@@ -39,24 +39,27 @@ import * as beta from './dev/beta'
39
39
import { activate as activateApplicationComposer } from './applicationcomposer/activation'
40
40
import { activate as activateRedshift } from './awsService/redshift/activation'
41
41
import { activate as activateIamPolicyChecks } from './awsService/accessanalyzer/activation'
42
+ import { activate as activateNotifications } from './notifications/activation'
42
43
import { SchemaService } from './shared/schemas'
43
44
import { AwsResourceManager } from './dynamicResources/awsResourceManager'
44
45
import globals from './shared/extensionGlobals'
45
46
import { Experiments , Settings , showSettingsFailedMsg } from './shared/settings'
46
47
import { isReleaseVersion } from './shared/vscode/env'
47
- import { telemetry } from './shared/telemetry/telemetry'
48
+ import { AuthStatus , AuthUserState , telemetry } from './shared/telemetry/telemetry'
48
49
import { Auth , SessionSeparationPrompt } from './auth/auth'
50
+ import { getTelemetryMetadataForConn } from './auth/connection'
49
51
import { registerSubmitFeedback } from './feedback/vue/submitFeedback'
50
- import { activateCommon , deactivateCommon , emitUserState } from './extension'
52
+ import { activateCommon , deactivateCommon } from './extension'
51
53
import { learnMoreAmazonQCommand , qExtensionPageCommand , dismissQTree } from './amazonq/explorer/amazonQChildrenNodes'
52
54
import { AuthUtil , codeWhispererCoreScopes , isPreviousQUser } from './codewhisperer/util/authUtil'
53
55
import { installAmazonQExtension } from './codewhisperer/commands/basicCommands'
54
56
import { isExtensionInstalled , VSCODE_EXTENSION_ID } from './shared/utilities'
55
- import { ExtensionUse , initializeCredentialsProviderManager } from './auth/utils'
57
+ import { ExtensionUse , getAuthFormIdsFromConnection , initializeCredentialsProviderManager } from './auth/utils'
56
58
import { ExtStartUpSources } from './shared/telemetry'
57
59
import { activate as activateThreatComposerEditor } from './threatComposer/activation'
58
60
import { isSsoConnection , hasScopes } from './auth/connection'
59
61
import { CrashMonitoring , setContext } from './shared'
62
+ import { AuthFormId } from './login/webview/vue/types'
60
63
61
64
let localize : nls . LocalizeFunc
62
65
@@ -233,7 +236,17 @@ export async function activate(context: vscode.ExtensionContext) {
233
236
globals . telemetry . assertPassiveTelemetry ( globals . didReload )
234
237
}
235
238
236
- await emitUserState ( )
239
+ // TODO: Should probably emit for web as well.
240
+ // Will the web metric look the same?
241
+ const authState = await getAuthState ( )
242
+ telemetry . auth_userState . emit ( {
243
+ passive : true ,
244
+ result : 'Succeeded' ,
245
+ source : ExtensionUse . instance . sourceForTelemetry ( ) ,
246
+ ...authState ,
247
+ } )
248
+
249
+ await activateNotifications ( context , authState , getAuthState )
237
250
} catch ( error ) {
238
251
const stacktrace = ( error as Error ) . stack ?. split ( '\n' )
239
252
// truncate if the stacktrace is unusually long
@@ -324,3 +337,36 @@ function recordToolkitInitialization(activationStartedOn: number, settingsValid:
324
337
logger ?. error ( err as Error )
325
338
}
326
339
}
340
+
341
+ async function getAuthState ( ) : Promise < Omit < AuthUserState , 'source' > > {
342
+ let authStatus : AuthStatus = 'notConnected'
343
+ const enabledConnections : Set < AuthFormId > = new Set ( )
344
+ const enabledScopes : Set < string > = new Set ( )
345
+ if ( Auth . instance . hasConnections ) {
346
+ authStatus = 'expired'
347
+ ; ( await Auth . instance . listConnections ( ) ) . forEach ( ( conn ) => {
348
+ const state = Auth . instance . getConnectionState ( conn )
349
+ if ( state === 'valid' ) {
350
+ authStatus = 'connected'
351
+ }
352
+
353
+ getAuthFormIdsFromConnection ( conn ) . forEach ( ( id ) => enabledConnections . add ( id ) )
354
+ if ( isSsoConnection ( conn ) ) {
355
+ conn . scopes ?. forEach ( ( s ) => enabledScopes . add ( s ) )
356
+ }
357
+ } )
358
+ }
359
+
360
+ // There may be other SSO connections in toolkit, but there is no use case for
361
+ // displaying registration info for non-active connections at this time.
362
+ const activeConn = Auth . instance . activeConnection
363
+ if ( activeConn ?. type === 'sso' ) {
364
+ telemetry . record ( await getTelemetryMetadataForConn ( activeConn ) )
365
+ }
366
+
367
+ return {
368
+ authStatus,
369
+ authEnabledConnections : [ ...enabledConnections ] . sort ( ) . join ( ',' ) ,
370
+ authScopes : [ ...enabledScopes ] . sort ( ) . join ( ',' ) ,
371
+ }
372
+ }
0 commit comments