Skip to content

Commit 100eb07

Browse files
authored
telemetry(auth): debounce aws_loadCredentials and add debugging information (#6499)
## Problem This metric is currently being spammed in telemetry at unusual volume. It is suspected that this is connected to this change: https://github.com/aws/aws-toolkit-vscode/pull/5979/files, but the connection is not yet clear. ## Solution - use the `withTelemetryContext` decorator to emit a `function_call` metric to capture additional information. This metric should allow us to determine what is calling this function so much. Added techdebt test to remove this debugging information before the following release. - debounce the current emit line that is causing the high volume emission. ## Future Work - `debounce` reimplements a special case of `debounceWithCancel`, these can be redone to reduce code and improve reliability. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 69db397 commit 100eb07

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

packages/core/src/auth/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ export class Auth implements AuthService, ConnectionManager {
282282
*
283283
* Use {@link Auth.listConnections} to avoid API calls to the SSO service.
284284
*/
285+
@withTelemetryContext({ name: 'listAndTraverseConnections', class: authClassName })
285286
public listAndTraverseConnections(): AsyncCollection<Connection> {
286287
async function* load(this: Auth) {
287288
await loadIamProfilesIntoStore(this.store, this.iamProfileProvider)

packages/core/src/auth/deprecated/loginManager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ import * as localizedText from '../../shared/localizedText'
3333
import { DefaultStsClient } from '../../shared/clients/stsClient'
3434
import { findAsync } from '../../shared/utilities/collectionUtils'
3535
import { telemetry } from '../../shared/telemetry/telemetry'
36+
import { withTelemetryContext } from '../../shared/telemetry/util'
3637

38+
const loginManagerClassName = 'LoginManager'
3739
/**
3840
* @deprecated Replaced by `Auth` in `src/credentials/auth.ts`
3941
*/
@@ -131,6 +133,7 @@ export class LoginManager {
131133

132134
private static didTryAutoConnect = false
133135

136+
@withTelemetryContext({ name: 'tryAutoConnect', class: loginManagerClassName })
134137
public static async tryAutoConnect(awsContext: AwsContext = globals.awsContext): Promise<boolean> {
135138
if (isAutomation()) {
136139
return false

packages/core/src/auth/providers/credentialsProviderManager.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
*/
55

66
import { getLogger } from '../../shared/logger'
7-
import { telemetry } from '../../shared/telemetry/telemetry'
7+
import { AwsLoadCredentials, telemetry } from '../../shared/telemetry/telemetry'
8+
import { withTelemetryContext } from '../../shared/telemetry/util'
9+
import { cancellableDebounce } from '../../shared/utilities/functionUtils'
810
import {
911
asString,
1012
CredentialsProvider,
@@ -14,6 +16,7 @@ import {
1416
} from './credentials'
1517
import { CredentialsProviderFactory } from './credentialsProviderFactory'
1618

19+
const credentialsProviderManagerClassName = 'CredentialsProviderManager'
1720
/**
1821
* Responsible for providing the Toolkit with all available CredentialsProviders.
1922
* Providers may be registered directly or created with supplied CredentialsProviderFactories.
@@ -23,13 +26,18 @@ export class CredentialsProviderManager {
2326
private readonly providerFactories: CredentialsProviderFactory[] = []
2427
private readonly providers: CredentialsProvider[] = []
2528

29+
@withTelemetryContext({ name: 'getAllCredentialsProvider', class: credentialsProviderManagerClassName, emit: true })
2630
public async getAllCredentialsProviders(): Promise<CredentialsProvider[]> {
2731
let providers: CredentialsProvider[] = []
2832

2933
for (const provider of this.providers) {
3034
if (await provider.isAvailable()) {
31-
const telemType = credentialsProviderToTelemetryType(provider.getCredentialsId().credentialSource)
32-
telemetry.aws_loadCredentials.emit({ credentialSourceId: telemType, value: 1 })
35+
telemetry.aws_loadCredentials.emit({
36+
credentialSourceId: credentialsProviderToTelemetryType(
37+
provider.getCredentialsId().credentialSource
38+
),
39+
value: 1,
40+
})
3341
providers = providers.concat(provider)
3442
} else {
3543
getLogger().verbose('auth: "%s" provider unavailable', provider.getCredentialsId().credentialTypeId)
@@ -43,18 +51,25 @@ export class CredentialsProviderManager {
4351
if (!providerType) {
4452
continue
4553
}
46-
const telemType = credentialsProviderToTelemetryType(providerType)
47-
telemetry.aws_loadCredentials.emit({ credentialSourceId: telemType, value: refreshed.length })
54+
55+
void this.emitWithDebounce({
56+
credentialSourceId: credentialsProviderToTelemetryType(providerType),
57+
value: refreshed.length,
58+
})
4859
providers = providers.concat(refreshed)
4960
}
5061

5162
return providers
5263
}
53-
64+
private emitWithDebounce = cancellableDebounce(
65+
(m: AwsLoadCredentials) => telemetry.aws_loadCredentials.emit(m),
66+
100
67+
).promise
5468
/**
5569
* Returns a map of `CredentialsProviderId` string-forms to object-forms,
5670
* from all credential sources. Only available providers are returned.
5771
*/
72+
@withTelemetryContext({ name: 'getCredentialProviderNames', class: credentialsProviderManagerClassName })
5873
public async getCredentialProviderNames(): Promise<{ [key: string]: CredentialsId }> {
5974
const m: { [key: string]: CredentialsId } = {}
6075
for (const o of await this.getAllCredentialsProviders()) {

packages/core/src/test/techdebt.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,11 @@ describe('tech debt', function () {
3939
// This is relevant for the use of `fs.cpSync` in the copyFiles scripts.
4040
assert.ok(semver.lt(minNodejs, '18.0.0'), 'with node18+, we can remove the dependency on @types/node@18')
4141
})
42+
43+
it('remove debugging telemetry', async function () {
44+
fixByDate(
45+
'2025-02-11',
46+
'Remove debugging telemetry in `packages/core/src/auth/providers/credentialsProviderManager.ts`. Should only need to remove the `emit: true` in the decorator.'
47+
)
48+
})
4249
})

0 commit comments

Comments
 (0)