From d1990a5d9990c65fc334c66c273c17dc2f898076 Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Thu, 4 Apr 2024 09:25:11 -0700 Subject: [PATCH] fix: add telemetry logger Signed-off-by: Denis Golovin --- src/extension.ts | 19 +++++++++++++++++-- src/podman-cli.ts | 8 ++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 07265cbd..a86ce5f0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -34,6 +34,8 @@ import { SubscriptionManagerClient } from '@redhat-developer/rhsm-client'; import { isLinux } from './util'; import { SSOStatusBarItem } from './status-bar-item'; +export const TelemetryLogger = extensionApi.env.createTelemetryLogger(); + let authenticationServicePromise: Promise; let currentSession: extensionApi.AuthenticationSession | undefined; @@ -302,6 +304,10 @@ export async function activate(context: extensionApi.ExtensionContext): Promise< context.subscriptions.push(providerDisposable); const SignInCommand = extensionApi.commands.registerCommand('redhat.authentication.signin', async () => { + const telemetryData = { + successful: true, + }; + await signIntoRedHatDeveloperAccount(true); //for the use case when user logged out, vm activated and registry configured const registryAccess = extensionApi.window @@ -319,7 +325,9 @@ export async function activate(context: extensionApi.ExtensionContext): Promise< }, ) .then(() => false) - .catch(() => true); // required to force Promise.all() call keep waiting for all not failed calls + .catch((error) => { + return true; // required to force Promise.all() call keep waiting for all not failed calls + }); const vmActivation = extensionApi.window .withProgress( @@ -352,13 +360,19 @@ export async function activate(context: extensionApi.ExtensionContext): Promise< }, ) .then(() => false) - .catch(() => true); // required to force Promise.all() call keep waiting for all not failed calls + .catch((error) => { + return true; // required to force Promise.all() call keep waiting for all not failed calls + }); const failed = await Promise.all([registryAccess, vmActivation]); // wait for all fail or pass if (failed.some(fail => fail)) { removeSession(currentSession.id); // if at least one fail, remove session + telemetryData.successful = false; } + + TelemetryLogger.logUsage('signin', telemetryData); + }); const SignOutCommand = extensionApi.commands.registerCommand('redhat.authentication.signout', async () => { @@ -366,6 +380,7 @@ export async function activate(context: extensionApi.ExtensionContext): Promise< service.removeSession(currentSession!.id); onDidChangeSessions.fire({ added: [], removed: [currentSession!], changed: [] }); currentSession = undefined; + TelemetryLogger.logUsage('signout'); }); const SignUpCommand = extensionApi.commands.registerCommand('redhat.authentication.signup', async () => { diff --git a/src/podman-cli.ts b/src/podman-cli.ts index 279ef43f..bd71d951 100644 --- a/src/podman-cli.ts +++ b/src/podman-cli.ts @@ -17,6 +17,7 @@ ***********************************************************************/ import { isMac, isWindows } from './util'; import * as extensionApi from '@podman-desktop/api'; +import { TelemetryLogger } from './extension' const macosExtraPath = '/usr/local/bin:/opt/homebrew/bin:/opt/local/bin:/opt/podman/bin'; @@ -78,6 +79,8 @@ export async function runSubscriptionManager(): Promise { } catch (err) { const exitCode = (err as extensionApi.RunError).exitCode; console.error(`Subscription manager execution returned exit code: ${exitCode}`); + // do not send telemetry because it is a check for it to be installed and + // it might fail pretty often return exitCode; } } @@ -89,6 +92,7 @@ export async function runRpmInstallSubscriptionManager(): Promise