Add telemetry to App

This commit is contained in:
Koen Vlaswinkel
2023-06-14 11:03:16 +02:00
parent fefb2f6694
commit 959728d1ca
4 changed files with 22 additions and 0 deletions

View File

@@ -4,11 +4,13 @@ import { AppEventEmitter } from "./events";
import { NotificationLogger } from "./logging";
import { Memento } from "./memento";
import { AppCommandManager } from "./commands";
import { AppTelemetry } from "./telemetry";
export interface App {
createEventEmitter<T>(): AppEventEmitter<T>;
readonly mode: AppMode;
readonly logger: NotificationLogger;
readonly telemetry?: AppTelemetry;
readonly subscriptions: Disposable[];
readonly extensionPath: string;
readonly globalStoragePath: string;

View File

@@ -9,6 +9,8 @@ import { VSCodeAppEventEmitter } from "./events";
import { AppCommandManager, QueryServerCommandManager } from "../commands";
import { createVSCodeCommandManager } from "./commands";
import { AppEnvironmentContext } from "./environment-context";
import { AppTelemetry } from "../telemetry";
import { telemetryListener } from "./telemetry";
export class ExtensionApp implements App {
public readonly credentials: VSCodeCredentials;
@@ -59,6 +61,10 @@ export class ExtensionApp implements App {
return extLogger;
}
public get telemetry(): AppTelemetry | undefined {
return telemetryListener;
}
public createEventEmitter<T>(): AppEventEmitter<T> {
return new VSCodeAppEventEmitter<T>();
}

View File

@@ -9,6 +9,8 @@ import { Credentials } from "../../src/common/authentication";
import { AppCommandManager } from "../../src/common/commands";
import { createMockCommandManager } from "./commandsMock";
import { NotificationLogger } from "../../src/common";
import { AppTelemetry } from "../../src/common/telemetry";
import { createMockTelemetryReporter } from "./telemetryMock";
export function createMockApp({
extensionPath = "/mock/extension/path",
@@ -20,6 +22,7 @@ export function createMockApp({
commands = createMockCommandManager(),
environment = createMockEnvironmentContext(),
logger = createMockLogger(),
telemetry = createMockTelemetryReporter(),
}: {
extensionPath?: string;
workspaceStoragePath?: string;
@@ -30,10 +33,12 @@ export function createMockApp({
commands?: AppCommandManager;
environment?: EnvironmentContext;
logger?: NotificationLogger;
telemetry?: AppTelemetry;
}): App {
return {
mode: AppMode.Test,
logger,
telemetry,
subscriptions: [],
extensionPath,
workspaceStoragePath,

View File

@@ -0,0 +1,9 @@
import { AppTelemetry } from "../../src/common/telemetry";
export function createMockTelemetryReporter(): AppTelemetry {
return {
sendCommandUsage: jest.fn(),
sendUIInteraction: jest.fn(),
sendError: jest.fn(),
};
}