From 1a94129b09efea5f3c6eb85b26d8e70bf0c322d3 Mon Sep 17 00:00:00 2001 From: Srinath Padmanabhan Date: Thu, 19 Feb 2026 10:14:56 -0800 Subject: [PATCH] fix(telemetry): correct onboarding and token storage metrics This commit addresses two issues with telemetry recording: 1. The metric was missing the attribute, causing a TypeScript error when was called. The attribute has been added back to the metric definition. 2. The metric was being incorrectly called on every token refresh. This has been corrected by removing the calls from the token refresh listener and refactoring the valid success paths to call a new helper function to avoid code duplication. --- packages/core/src/code_assist/oauth2.ts | 22 ++++++++-------------- packages/core/src/telemetry/metrics.ts | 1 + 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/core/src/code_assist/oauth2.ts b/packages/core/src/code_assist/oauth2.ts index 3cf4d432e0..f842d8cbd9 100644 --- a/packages/core/src/code_assist/oauth2.ts +++ b/packages/core/src/code_assist/oauth2.ts @@ -115,6 +115,12 @@ async function initOauthClient( authType: AuthType, config: Config, ): Promise { + const recordOnboardingEndIfApplicable = () => { + if (authType === AuthType.LOGIN_WITH_GOOGLE) { + recordOnboardingEnd(config); + } + }; + const credentials = await fetchCachedCredentials(); if ( @@ -170,10 +176,6 @@ async function initOauthClient( } await triggerPostAuthCallbacks(tokens); - - if (authType === AuthType.LOGIN_WITH_GOOGLE) { - recordOnboardingEnd(config); - } }); if (credentials) { @@ -199,10 +201,6 @@ async function initOauthClient( debugLogger.log('Loaded cached credentials.'); await triggerPostAuthCallbacks(credentials as Credentials); - if (authType === AuthType.LOGIN_WITH_GOOGLE) { - recordOnboardingEnd(config); - } - return client; } } catch (error) { @@ -287,9 +285,7 @@ async function initOauthClient( } await triggerPostAuthCallbacks(client.credentials); - if (authType === AuthType.LOGIN_WITH_GOOGLE) { - recordOnboardingEnd(config); - } + recordOnboardingEndIfApplicable(); } else { // In Zed integration, we skip the interactive consent and directly open the browser if (!config.getExperimentalZedIntegration()) { @@ -396,9 +392,7 @@ async function initOauthClient( }); await triggerPostAuthCallbacks(client.credentials); - if (authType === AuthType.LOGIN_WITH_GOOGLE) { - recordOnboardingEnd(config); - } + recordOnboardingEndIfApplicable(); } return client; diff --git a/packages/core/src/telemetry/metrics.ts b/packages/core/src/telemetry/metrics.ts index 8b44bb8e28..347497dd2e 100644 --- a/packages/core/src/telemetry/metrics.ts +++ b/packages/core/src/telemetry/metrics.ts @@ -259,6 +259,7 @@ const COUNTER_DEFINITIONS = { assign: (c: Counter) => (tokenStorageTypeCounter = c), // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion attributes: {} as { + type: string; forced: boolean; }, },