Skip to content

Commit

Permalink
fix: add telemetry logger
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Golovin <[email protected]>
  • Loading branch information
dgolovin committed Apr 10, 2024
1 parent 592526e commit d1990a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RedHatAuthenticationService>;
let currentSession: extensionApi.AuthenticationSession | undefined;

Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -352,20 +360,27 @@ 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 () => {
const service = await getAuthenticationService();
service.removeSession(currentSession!.id);
onDidChangeSessions.fire({ added: [], removed: [currentSession!], changed: [] });
currentSession = undefined;
TelemetryLogger.logUsage('signout');
});

const SignUpCommand = extensionApi.commands.registerCommand('redhat.authentication.signup', async () => {
Expand Down
8 changes: 8 additions & 0 deletions src/podman-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -78,6 +79,8 @@ export async function runSubscriptionManager(): Promise<number | undefined> {
} 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;
}
}
Expand All @@ -89,6 +92,7 @@ export async function runRpmInstallSubscriptionManager(): Promise<number | undef
} catch (err) {
const exitCode = (err as extensionApi.RunError).exitCode;
console.error(`Subscription manager installation returned exit code: ${exitCode}`);
TelemetryLogger.logError('subscriptionManagerInstallationError', {error: String(err)});
return exitCode;
}
}
Expand All @@ -100,6 +104,8 @@ export async function runSubscriptionManagerActivationStatus(): Promise<number |
} catch (err) {
const exitCode = (err as extensionApi.RunError).exitCode;
console.error(`Subscription manager subscription activation check returned exit code: ${exitCode}`);
// do not send telemetry because it is a check for subscription status and
// it might fail pretty often
return exitCode;
}
}
Expand All @@ -117,6 +123,7 @@ export async function runSubscriptionManagerRegister(
} catch (err) {
const exitCode = (err as extensionApi.RunError).exitCode;
console.error(`Subscription manager registration returned exit code: ${exitCode}`);
TelemetryLogger.logError('subscriptionManagerRegisterError', {error: String(err)});
return exitCode;
}
}
Expand All @@ -128,6 +135,7 @@ export async function runSubscriptionManagerUnregister(): Promise<number | undef
} catch (err) {
const exitCode = (err as extensionApi.RunError).exitCode;
console.error(`Subscription manager registration returned exit code: ${exitCode}`);
TelemetryLogger.logError('subscriptionManagerUnregisterError', {error: String(err)});
return exitCode;
}
}
Expand Down

0 comments on commit d1990a5

Please sign in to comment.