@@ -39,24 +39,27 @@ import * as beta from './dev/beta'
3939import { activate as activateApplicationComposer } from './applicationcomposer/activation'
4040import { activate as activateRedshift } from './awsService/redshift/activation'
4141import { activate as activateIamPolicyChecks } from './awsService/accessanalyzer/activation'
42+ import { activate as activateNotifications } from './notifications/activation'
4243import { SchemaService } from './shared/schemas'
4344import { AwsResourceManager } from './dynamicResources/awsResourceManager'
4445import globals from './shared/extensionGlobals'
4546import { Experiments , Settings , showSettingsFailedMsg } from './shared/settings'
4647import { isReleaseVersion } from './shared/vscode/env'
47- import { telemetry } from './shared/telemetry/telemetry'
48+ import { AuthStatus , AuthUserState , telemetry } from './shared/telemetry/telemetry'
4849import { Auth , SessionSeparationPrompt } from './auth/auth'
50+ import { getTelemetryMetadataForConn } from './auth/connection'
4951import { registerSubmitFeedback } from './feedback/vue/submitFeedback'
50- import { activateCommon , deactivateCommon , emitUserState } from './extension'
52+ import { activateCommon , deactivateCommon } from './extension'
5153import { learnMoreAmazonQCommand , qExtensionPageCommand , dismissQTree } from './amazonq/explorer/amazonQChildrenNodes'
5254import { AuthUtil , codeWhispererCoreScopes , isPreviousQUser } from './codewhisperer/util/authUtil'
5355import { installAmazonQExtension } from './codewhisperer/commands/basicCommands'
5456import { isExtensionInstalled , VSCODE_EXTENSION_ID } from './shared/utilities'
55- import { ExtensionUse , initializeCredentialsProviderManager } from './auth/utils'
57+ import { ExtensionUse , getAuthFormIdsFromConnection , initializeCredentialsProviderManager } from './auth/utils'
5658import { ExtStartUpSources } from './shared/telemetry'
5759import { activate as activateThreatComposerEditor } from './threatComposer/activation'
5860import { isSsoConnection , hasScopes } from './auth/connection'
5961import { CrashMonitoring , setContext } from './shared'
62+ import { AuthFormId } from './login/webview/vue/types'
6063
6164let localize : nls . LocalizeFunc
6265
@@ -233,7 +236,17 @@ export async function activate(context: vscode.ExtensionContext) {
233236 globals . telemetry . assertPassiveTelemetry ( globals . didReload )
234237 }
235238
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 )
237250 } catch ( error ) {
238251 const stacktrace = ( error as Error ) . stack ?. split ( '\n' )
239252 // truncate if the stacktrace is unusually long
@@ -324,3 +337,36 @@ function recordToolkitInitialization(activationStartedOn: number, settingsValid:
324337 logger ?. error ( err as Error )
325338 }
326339}
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