Skip to content

Commit f3bf546

Browse files
committed
refactor: increase debugging trail of function_call
1 parent b71d84a commit f3bf546

File tree

7 files changed

+106
-67
lines changed

7 files changed

+106
-67
lines changed

packages/core/src/auth/sso/validation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function validateSsoUrlFormat(url: string) {
1818
}
1919
}
2020

21+
// TODO: Remove this if unused?
2122
export async function validateIsNewSsoUrlAsync(
2223
auth: Auth,
2324
url: string,

packages/core/src/auth/utils.ts

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -598,29 +598,39 @@ export async function hasSso(
598598
kind: SsoKind = 'any',
599599
allConnections = () => Auth.instance.listConnections()
600600
): Promise<boolean> {
601-
return (await findSsoConnections(kind, allConnections)).length > 0
601+
return telemetry.function_call.run(
602+
async () => {
603+
return (await findSsoConnections(kind, allConnections)).length > 0
604+
},
605+
{ emit: false, functionId: { name: 'hasSso', class: 'utils' } }
606+
)
602607
}
603608

604609
export async function findSsoConnections(
605610
kind: SsoKind = 'any',
606611
allConnections = () => Auth.instance.listConnections()
607612
): Promise<SsoConnection[]> {
608-
let predicate: (c?: Connection) => boolean
609-
switch (kind) {
610-
case 'codewhisperer':
611-
predicate = (conn?: Connection) => {
612-
return isIdcSsoConnection(conn) && isValidCodeWhispererCoreConnection(conn)
613-
}
614-
break
615-
case 'codecatalyst':
616-
predicate = (conn?: Connection) => {
617-
return isIdcSsoConnection(conn) && isValidCodeCatalystConnection(conn)
613+
return telemetry.function_call.run(
614+
async () => {
615+
let predicate: (c?: Connection) => boolean
616+
switch (kind) {
617+
case 'codewhisperer':
618+
predicate = (conn?: Connection) => {
619+
return isIdcSsoConnection(conn) && isValidCodeWhispererCoreConnection(conn)
620+
}
621+
break
622+
case 'codecatalyst':
623+
predicate = (conn?: Connection) => {
624+
return isIdcSsoConnection(conn) && isValidCodeCatalystConnection(conn)
625+
}
626+
break
627+
case 'any':
628+
predicate = isIdcSsoConnection
618629
}
619-
break
620-
case 'any':
621-
predicate = isIdcSsoConnection
622-
}
623-
return (await allConnections()).filter(predicate).filter(isIdcSsoConnection)
630+
return (await allConnections()).filter(predicate).filter(isIdcSsoConnection)
631+
},
632+
{ emit: false, functionId: { name: 'findSsoConnections', class: 'utils' } }
633+
)
624634
}
625635

626636
export type BuilderIdKind = 'any' | 'codewhisperer' | 'codecatalyst'
@@ -635,29 +645,42 @@ export async function hasBuilderId(
635645
kind: BuilderIdKind = 'any',
636646
allConnections = () => Auth.instance.listConnections()
637647
): Promise<boolean> {
638-
return (await findBuilderIdConnections(kind, allConnections)).length > 0
648+
return telemetry.function_call.run(
649+
async () => {
650+
return (await findBuilderIdConnections(kind, allConnections)).length > 0
651+
},
652+
{ emit: false, functionId: { name: 'hasBuilderId', class: 'utils' } }
653+
)
639654
}
640655

641656
async function findBuilderIdConnections(
642657
kind: BuilderIdKind = 'any',
643658
allConnections = () => Auth.instance.listConnections()
644659
): Promise<SsoConnection[]> {
645-
let predicate: (c?: Connection) => boolean
646-
switch (kind) {
647-
case 'codewhisperer':
648-
predicate = (conn?: Connection) => {
649-
return isBuilderIdConnection(conn) && isValidCodeWhispererCoreConnection(conn)
650-
}
651-
break
652-
case 'codecatalyst':
653-
predicate = (conn?: Connection) => {
654-
return isBuilderIdConnection(conn) && isValidCodeCatalystConnection(conn)
660+
return telemetry.function_call.run(
661+
async () => {
662+
let predicate: (c?: Connection) => boolean
663+
switch (kind) {
664+
case 'codewhisperer':
665+
predicate = (conn?: Connection) => {
666+
return isBuilderIdConnection(conn) && isValidCodeWhispererCoreConnection(conn)
667+
}
668+
break
669+
case 'codecatalyst':
670+
predicate = (conn?: Connection) => {
671+
return isBuilderIdConnection(conn) && isValidCodeCatalystConnection(conn)
672+
}
673+
break
674+
case 'any':
675+
predicate = isBuilderIdConnection
655676
}
656-
break
657-
case 'any':
658-
predicate = isBuilderIdConnection
659-
}
660-
return (await allConnections()).filter(predicate).filter(isAnySsoConnection)
677+
return (await allConnections()).filter(predicate).filter(isAnySsoConnection)
678+
},
679+
{
680+
emit: false,
681+
functionId: { name: 'findBuilderIdConnections', class: 'utils' },
682+
}
683+
)
661684
}
662685

663686
/**

packages/core/src/codecatalyst/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ export class CodeCatalystAuthenticationProvider {
203203
* This cannot create a Builder ID, but will return an existing Builder ID,
204204
* upgrading the scopes if necessary.
205205
*/
206+
@withTelemetryContext({ name: 'tryGetBuilderIdConnection', class: authClassName })
206207
public async tryGetBuilderIdConnection(): Promise<SsoConnection> {
207208
if (this.activeConnection && isBuilderIdConnection(this.activeConnection)) {
208209
return this.activeConnection

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ export class AuthUtil {
476476
* auth connections that the Amazon Q extension has cached. We need to remove these
477477
* as they are irrelevant to the Q extension and can cause issues.
478478
*/
479+
@withTelemetryContext({ name: 'clearExtraConnections', class: authClassName })
479480
public async clearExtraConnections(): Promise<void> {
480481
const currentQConn = this.conn
481482
// Q currently only maintains 1 connection at a time, so we assume everything else is extra.

packages/core/src/dev/activation.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,15 @@ async function editSsoConnections() {
495495
}
496496

497497
async function deleteSsoConnections() {
498-
const conns = targetAuth.listConnections()
499-
const ssoConns = (await conns).filter(isAnySsoConnection)
500-
await Promise.all(ssoConns.map((conn) => targetAuth.deleteConnection(conn)))
501-
void vscode.window.showInformationMessage(`Deleted: ${ssoConns.map((c) => c.startUrl).join(', ')}`)
498+
return telemetry.function_call.run(
499+
async () => {
500+
const conns = targetAuth.listConnections()
501+
const ssoConns = (await conns).filter(isAnySsoConnection)
502+
await Promise.all(ssoConns.map((conn) => targetAuth.deleteConnection(conn)))
503+
void vscode.window.showInformationMessage(`Deleted: ${ssoConns.map((c) => c.startUrl).join(', ')}`)
504+
},
505+
{ emit: false, functionId: { name: 'deleteSsoConnectionsDev', class: 'activation' } }
506+
)
502507
}
503508

504509
async function expireSsoConnections() {
@@ -509,7 +514,7 @@ async function expireSsoConnections() {
509514
await Promise.all(ssoConns.map((conn) => targetAuth.expireConnection(conn)))
510515
void vscode.window.showInformationMessage(`Expired: ${ssoConns.map((c) => c.startUrl).join(', ')}`)
511516
},
512-
{ emit: false, functionId: { name: 'expireSsoConnectionsDev' } }
517+
{ emit: false, functionId: { name: 'expireSsoConnectionsDev', class: 'activation' } }
513518
)
514519
}
515520

packages/core/src/extensionNode.ts

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -324,40 +324,45 @@ function recordToolkitInitialization(activationStartedOn: number, settingsValid:
324324
}
325325

326326
async function getAuthState(): Promise<Omit<AuthUserState, 'source'>> {
327-
let authStatus: AuthStatus = 'notConnected'
328-
const enabledConnections: Set<AuthFormId> = new Set()
329-
const enabledScopes: Set<string> = new Set()
330-
if (Auth.instance.hasConnections) {
331-
authStatus = 'expired'
332-
for (const conn of await Auth.instance.listConnections()) {
333-
const state = Auth.instance.getConnectionState(conn)
334-
if (state === 'valid') {
335-
authStatus = 'connected'
336-
}
327+
return telemetry.function_call.run(
328+
async () => {
329+
let authStatus: AuthStatus = 'notConnected'
330+
const enabledConnections: Set<AuthFormId> = new Set()
331+
const enabledScopes: Set<string> = new Set()
332+
if (Auth.instance.hasConnections) {
333+
authStatus = 'expired'
334+
for (const conn of await Auth.instance.listConnections()) {
335+
const state = Auth.instance.getConnectionState(conn)
336+
if (state === 'valid') {
337+
authStatus = 'connected'
338+
}
337339

338-
for (const id of getAuthFormIdsFromConnection(conn)) {
339-
enabledConnections.add(id)
340-
}
341-
if (isSsoConnection(conn)) {
342-
if (conn.scopes) {
343-
for (const s of conn.scopes) {
344-
enabledScopes.add(s)
340+
for (const id of getAuthFormIdsFromConnection(conn)) {
341+
enabledConnections.add(id)
342+
}
343+
if (isSsoConnection(conn)) {
344+
if (conn.scopes) {
345+
for (const s of conn.scopes) {
346+
enabledScopes.add(s)
347+
}
348+
}
345349
}
346350
}
347351
}
348-
}
349-
}
350352

351-
// There may be other SSO connections in toolkit, but there is no use case for
352-
// displaying registration info for non-active connections at this time.
353-
const activeConn = Auth.instance.activeConnection
354-
if (activeConn?.type === 'sso') {
355-
telemetry.record(await getTelemetryMetadataForConn(activeConn))
356-
}
353+
// There may be other SSO connections in toolkit, but there is no use case for
354+
// displaying registration info for non-active connections at this time.
355+
const activeConn = Auth.instance.activeConnection
356+
if (activeConn?.type === 'sso') {
357+
telemetry.record(await getTelemetryMetadataForConn(activeConn))
358+
}
357359

358-
return {
359-
authStatus,
360-
authEnabledConnections: [...enabledConnections].sort().join(','),
361-
authScopes: [...enabledScopes].sort().join(','),
362-
}
360+
return {
361+
authStatus,
362+
authEnabledConnections: [...enabledConnections].sort().join(','),
363+
authScopes: [...enabledScopes].sort().join(','),
364+
}
365+
},
366+
{ emit: false, functionId: { name: 'getAuthState', class: 'extensionNode' } }
367+
)
363368
}

packages/core/src/login/webview/vue/toolkit/backend_toolkit.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import { CodeCatalystAuthenticationProvider } from '../../../../codecatalyst/aut
2121
import { AuthError, AuthFlowState } from '../types'
2222
import { setContext } from '../../../../shared'
2323
import { builderIdStartUrl } from '../../../../auth/sso/constants'
24+
import { withTelemetryContext } from '../../../../shared/telemetry/util'
2425

26+
const loginWebviewClass = 'ToolkitLoginWebview'
2527
export class ToolkitLoginWebview extends CommonAuthWebview {
2628
public override id: string = 'aws.toolkit.AmazonCommonAuth'
2729
public static sourcePath: string = 'vue/src/login/webview/vue/toolkit/index.js'
@@ -147,6 +149,7 @@ export class ToolkitLoginWebview extends CommonAuthWebview {
147149
return connections
148150
}
149151

152+
@withTelemetryContext({ name: 'listSsoConnections', class: loginWebviewClass })
150153
async listSsoConnections(): Promise<SsoConnection[]> {
151154
return (await Auth.instance.listConnections()).filter((conn) => isSsoConnection(conn)) as SsoConnection[]
152155
}

0 commit comments

Comments
 (0)