Merge pull request #2513 from github/koesie10/show-telemetry-without-vscode
Make the `showAndLogExceptionWithTelemetry` function work without the `vscode` module
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { NotificationLogger } from "./notification-logger";
|
||||
import { AppTelemetry } from "../telemetry";
|
||||
import { RedactableError } from "../../pure/errors";
|
||||
|
||||
export interface ShowAndLogOptions {
|
||||
/**
|
||||
@@ -87,3 +89,28 @@ async function internalShowAndLog(
|
||||
void logger.log(fullMessage || message);
|
||||
await fn.bind(logger)(message);
|
||||
}
|
||||
|
||||
interface ShowAndLogExceptionOptions extends ShowAndLogOptions {
|
||||
/** Custom properties to include in the telemetry report. */
|
||||
extraTelemetryProperties?: { [key: string]: string };
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an error message, log it to the console, and emit redacted information as telemetry
|
||||
*
|
||||
* @param logger The logger that will receive the message.
|
||||
* @param telemetry The telemetry instance to use for reporting.
|
||||
* @param error The error to show. Only redacted information will be included in the telemetry.
|
||||
* @param options See individual fields on `ShowAndLogExceptionOptions` type.
|
||||
*
|
||||
* @return A promise that resolves to the selected item or undefined when being dismissed.
|
||||
*/
|
||||
export async function showAndLogExceptionWithTelemetry(
|
||||
logger: NotificationLogger,
|
||||
telemetry: AppTelemetry | undefined,
|
||||
error: RedactableError,
|
||||
options: ShowAndLogExceptionOptions = {},
|
||||
): Promise<void> {
|
||||
telemetry?.sendError(error, options.extraTelemetryProperties);
|
||||
return showAndLogErrorMessage(logger, error.fullMessage, options);
|
||||
}
|
||||
|
||||
10
extensions/ql-vscode/src/common/telemetry.ts
Normal file
10
extensions/ql-vscode/src/common/telemetry.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { RedactableError } from "../pure/errors";
|
||||
|
||||
export interface AppTelemetry {
|
||||
sendCommandUsage(name: string, executionTime: number, error?: Error): void;
|
||||
sendUIInteraction(name: string): void;
|
||||
sendError(
|
||||
error: RedactableError,
|
||||
extraProperties?: { [key: string]: string },
|
||||
): void;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
extLogger,
|
||||
NotificationLogger,
|
||||
showAndLogWarningMessage,
|
||||
showAndLogExceptionWithTelemetry,
|
||||
} from "../logging";
|
||||
import {
|
||||
asError,
|
||||
@@ -12,8 +13,8 @@ import {
|
||||
} from "../../pure/helpers-pure";
|
||||
import { redactableError } from "../../pure/errors";
|
||||
import { UserCancellationException } from "./progress";
|
||||
import { telemetryListener } from "../../telemetry";
|
||||
import { showAndLogExceptionWithTelemetry } from "./logging";
|
||||
import { telemetryListener } from "./telemetry";
|
||||
import { AppTelemetry } from "../telemetry";
|
||||
|
||||
/**
|
||||
* Create a command manager for VSCode, wrapping registerCommandWithErrorHandling
|
||||
@@ -21,9 +22,12 @@ import { showAndLogExceptionWithTelemetry } from "./logging";
|
||||
*/
|
||||
export function createVSCodeCommandManager<
|
||||
Commands extends Record<string, CommandFunction>,
|
||||
>(logger?: NotificationLogger): CommandManager<Commands> {
|
||||
>(
|
||||
logger?: NotificationLogger,
|
||||
telemetry?: AppTelemetry,
|
||||
): CommandManager<Commands> {
|
||||
return new CommandManager((commandId, task) => {
|
||||
return registerCommandWithErrorHandling(commandId, task, logger);
|
||||
return registerCommandWithErrorHandling(commandId, task, logger, telemetry);
|
||||
}, wrapExecuteCommand);
|
||||
}
|
||||
|
||||
@@ -34,11 +38,13 @@ export function createVSCodeCommandManager<
|
||||
* @param task The task to run. It is passed directly to `commands.registerCommand`. Any
|
||||
* arguments to the command handler are passed on to the task.
|
||||
* @param logger The logger to use for error reporting.
|
||||
* @param telemetry The telemetry listener to use for error reporting.
|
||||
*/
|
||||
export function registerCommandWithErrorHandling(
|
||||
commandId: string,
|
||||
task: (...args: any[]) => Promise<any>,
|
||||
logger: NotificationLogger = extLogger,
|
||||
telemetry: AppTelemetry | undefined = telemetryListener,
|
||||
): Disposable {
|
||||
return commands.registerCommand(commandId, async (...args: any[]) => {
|
||||
const startTime = Date.now();
|
||||
@@ -64,7 +70,7 @@ export function registerCommandWithErrorHandling(
|
||||
const fullMessage = errorStack
|
||||
? `${errorMessage.fullMessage}\n${errorStack}`
|
||||
: errorMessage.fullMessage;
|
||||
void showAndLogExceptionWithTelemetry(logger, errorMessage, {
|
||||
void showAndLogExceptionWithTelemetry(logger, telemetry, errorMessage, {
|
||||
fullMessage,
|
||||
extraTelemetryProperties: {
|
||||
command: commandId,
|
||||
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
getErrorMessage,
|
||||
getErrorStack,
|
||||
} from "../../pure/helpers-pure";
|
||||
import { extLogger } from "../logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "./logging";
|
||||
import { extLogger, showAndLogExceptionWithTelemetry } from "../logging";
|
||||
import { telemetryListener } from "./telemetry";
|
||||
|
||||
export async function tryOpenExternalFile(
|
||||
commandManager: AppCommandManager,
|
||||
@@ -36,6 +36,7 @@ the file in the file explorer and dragging it into the workspace.`,
|
||||
} catch (e) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
asError(e),
|
||||
)`Failed to reveal file in OS: ${getErrorMessage(e)}`,
|
||||
@@ -45,6 +46,7 @@ the file in the file explorer and dragging it into the workspace.`,
|
||||
} else {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(asError(e))`Could not open file ${fileLocation}`,
|
||||
{
|
||||
fullMessage: `${getErrorMessage(e)}\n${getErrorStack(e)}`,
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import {
|
||||
NotificationLogger,
|
||||
showAndLogErrorMessage,
|
||||
ShowAndLogOptions,
|
||||
} from "../logging";
|
||||
import { RedactableError } from "../../pure/errors";
|
||||
import { telemetryListener } from "../../telemetry";
|
||||
|
||||
interface ShowAndLogExceptionOptions extends ShowAndLogOptions {
|
||||
/** Custom properties to include in the telemetry report. */
|
||||
extraTelemetryProperties?: { [key: string]: string };
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an error message, log it to the console, and emit redacted information as telemetry
|
||||
*
|
||||
* @param logger The logger that will receive the message.
|
||||
* @param error The error to show. Only redacted information will be included in the telemetry.
|
||||
* @param options See individual fields on `ShowAndLogExceptionOptions` type.
|
||||
*
|
||||
* @return A promise that resolves to the selected item or undefined when being dismissed.
|
||||
*/
|
||||
export async function showAndLogExceptionWithTelemetry(
|
||||
logger: NotificationLogger,
|
||||
error: RedactableError,
|
||||
options: ShowAndLogExceptionOptions = {},
|
||||
): Promise<void> {
|
||||
telemetryListener?.sendError(error, options.extraTelemetryProperties);
|
||||
return showAndLogErrorMessage(logger, error.fullMessage, options);
|
||||
}
|
||||
@@ -13,13 +13,14 @@ import {
|
||||
LOG_TELEMETRY,
|
||||
isIntegrationTestMode,
|
||||
isCanary,
|
||||
} from "./config";
|
||||
} from "../../config";
|
||||
import * as appInsights from "applicationinsights";
|
||||
import { extLogger } from "./common";
|
||||
import { UserCancellationException } from "./common/vscode/progress";
|
||||
import { showBinaryChoiceWithUrlDialog } from "./common/vscode/dialog";
|
||||
import { RedactableError } from "./pure/errors";
|
||||
import { extLogger } from "../index";
|
||||
import { UserCancellationException } from "./progress";
|
||||
import { showBinaryChoiceWithUrlDialog } from "./dialog";
|
||||
import { RedactableError } from "../../pure/errors";
|
||||
import { SemVer } from "semver";
|
||||
import { AppTelemetry } from "../telemetry";
|
||||
|
||||
// Key is injected at build time through the APP_INSIGHTS_KEY environment variable.
|
||||
const key = "REPLACE-APP-INSIGHTS-KEY";
|
||||
@@ -54,7 +55,10 @@ const baseDataPropertiesToRemove = [
|
||||
|
||||
const NOT_SET_CLI_VERSION = "not-set";
|
||||
|
||||
export class TelemetryListener extends ConfigListener {
|
||||
export class ExtensionTelemetryListener
|
||||
extends ConfigListener
|
||||
implements AppTelemetry
|
||||
{
|
||||
static relevantSettings = [ENABLE_TELEMETRY, CANARY_FEATURES];
|
||||
|
||||
private reporter?: TelemetryReporter;
|
||||
@@ -152,7 +156,7 @@ export class TelemetryListener extends ConfigListener {
|
||||
void this.reporter?.dispose();
|
||||
}
|
||||
|
||||
sendCommandUsage(name: string, executionTime: number, error?: Error) {
|
||||
sendCommandUsage(name: string, executionTime: number, error?: Error): void {
|
||||
if (!this.reporter) {
|
||||
return;
|
||||
}
|
||||
@@ -174,7 +178,7 @@ export class TelemetryListener extends ConfigListener {
|
||||
);
|
||||
}
|
||||
|
||||
sendUIInteraction(name: string) {
|
||||
sendUIInteraction(name: string): void {
|
||||
if (!this.reporter) {
|
||||
return;
|
||||
}
|
||||
@@ -193,7 +197,7 @@ export class TelemetryListener extends ConfigListener {
|
||||
sendError(
|
||||
error: RedactableError,
|
||||
extraProperties?: { [key: string]: string },
|
||||
) {
|
||||
): void {
|
||||
if (!this.reporter) {
|
||||
return;
|
||||
}
|
||||
@@ -272,16 +276,16 @@ export class TelemetryListener extends ConfigListener {
|
||||
/**
|
||||
* The global Telemetry instance
|
||||
*/
|
||||
export let telemetryListener: TelemetryListener | undefined;
|
||||
export let telemetryListener: ExtensionTelemetryListener | undefined;
|
||||
|
||||
export async function initializeTelemetry(
|
||||
extension: Extension<any>,
|
||||
ctx: ExtensionContext,
|
||||
): Promise<TelemetryListener> {
|
||||
): Promise<ExtensionTelemetryListener> {
|
||||
if (telemetryListener !== undefined) {
|
||||
throw new Error("Telemetry is already initialized");
|
||||
}
|
||||
telemetryListener = new TelemetryListener(
|
||||
telemetryListener = new ExtensionTelemetryListener(
|
||||
extension.id,
|
||||
extension.packageJSON.version,
|
||||
key,
|
||||
@@ -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>();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
QueryCompareResult,
|
||||
} from "../pure/interface-types";
|
||||
import { extLogger, Logger } from "../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/logging";
|
||||
import { CodeQLCliServer } from "../codeql-cli/cli";
|
||||
import { DatabaseManager } from "../databases/local-databases";
|
||||
import { jumpToLocation } from "../databases/local-databases/locations";
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
AbstractWebview,
|
||||
WebviewPanelConfig,
|
||||
} from "../common/vscode/abstract-webview";
|
||||
import { telemetryListener } from "../telemetry";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
import { redactableError } from "../pure/errors";
|
||||
|
||||
interface ComparePair {
|
||||
@@ -152,6 +152,7 @@ export class CompareView extends AbstractWebview<
|
||||
case "unhandledError":
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
msg.error,
|
||||
)`Unhandled error in result comparison view: ${msg.error.message}`,
|
||||
|
||||
@@ -17,7 +17,10 @@ import {
|
||||
} from "../pure/interface-types";
|
||||
import { ProgressUpdate } from "../common/vscode/progress";
|
||||
import { QueryRunner } from "../query-server";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
showAndLogErrorMessage,
|
||||
} from "../common/logging";
|
||||
import { outputFile, pathExists, readFile } from "fs-extra";
|
||||
import { load as loadYaml } from "js-yaml";
|
||||
import { DatabaseItem, DatabaseManager } from "../databases/local-databases";
|
||||
@@ -42,7 +45,6 @@ import {
|
||||
} from "./auto-model";
|
||||
import { showLlmGeneration } from "../config";
|
||||
import { getAutoModelUsages } from "./auto-model-usages-query";
|
||||
import { showAndLogErrorMessage } from "../common/logging";
|
||||
|
||||
export class DataExtensionsEditorView extends AbstractWebview<
|
||||
ToDataExtensionsEditorMessage,
|
||||
@@ -276,6 +278,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
|
||||
} catch (err) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
this.app.logger,
|
||||
this.app.telemetry,
|
||||
redactableError(
|
||||
asError(err),
|
||||
)`Failed to load external API usages: ${getErrorMessage(err)}`,
|
||||
@@ -342,6 +345,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
|
||||
} catch (e: unknown) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
this.app.logger,
|
||||
this.app.telemetry,
|
||||
redactableError(
|
||||
asError(e),
|
||||
)`Failed to generate flow model: ${getErrorMessage(e)}`,
|
||||
@@ -476,6 +480,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
|
||||
if (e instanceof RequestError && e.status === 429) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
this.app.logger,
|
||||
this.app.telemetry,
|
||||
redactableError(e)`Rate limit hit, please try again soon.`,
|
||||
);
|
||||
return null;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { writeFile } from "fs-extra";
|
||||
import { dump as dumpYaml } from "js-yaml";
|
||||
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
|
||||
import { extLogger, TeeLogger } from "../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/logging";
|
||||
import { isQueryLanguage } from "../common/query-language";
|
||||
import { CancellationToken } from "vscode";
|
||||
import { CodeQLCliServer } from "../codeql-cli/cli";
|
||||
@@ -14,6 +14,7 @@ import { fetchExternalApiQueries } from "./queries";
|
||||
import { QueryResultType } from "../pure/new-messages";
|
||||
import { join } from "path";
|
||||
import { redactableError } from "../pure/errors";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
|
||||
export type RunQueryOptions = {
|
||||
cliServer: Pick<CodeQLCliServer, "resolveQlpacks">;
|
||||
@@ -42,6 +43,7 @@ export async function runQuery({
|
||||
if (!isQueryLanguage(databaseItem.language)) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError`Unsupported database language ${databaseItem.language}`,
|
||||
);
|
||||
return;
|
||||
@@ -51,6 +53,7 @@ export async function runQuery({
|
||||
if (!query) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError`No external API usage query found for language ${databaseItem.language}`,
|
||||
);
|
||||
return;
|
||||
@@ -107,6 +110,7 @@ export async function runQuery({
|
||||
if (completedQuery.resultType !== QueryResultType.SUCCESS) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError`External API usage query failed: ${
|
||||
completedQuery.message ?? "No message"
|
||||
}`,
|
||||
@@ -130,6 +134,7 @@ export async function readQueryResults({
|
||||
if (bqrsInfo["result-sets"].length !== 1) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError`Expected exactly one result set, got ${bqrsInfo["result-sets"].length}`,
|
||||
);
|
||||
return undefined;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { basename } from "path";
|
||||
import { QueryRunner } from "../query-server";
|
||||
import { CodeQLCliServer } from "../codeql-cli/cli";
|
||||
import { extLogger, TeeLogger } from "../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/logging";
|
||||
import { extensiblePredicateDefinitions } from "./predicates";
|
||||
import { ProgressCallback } from "../common/vscode/progress";
|
||||
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
|
||||
@@ -18,6 +18,7 @@ import { file } from "tmp-promise";
|
||||
import { writeFile } from "fs-extra";
|
||||
import { dump } from "js-yaml";
|
||||
import { qlpackOfDatabase } from "../language-support";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
|
||||
type FlowModelOptions = {
|
||||
cliServer: CodeQLCliServer;
|
||||
@@ -82,6 +83,7 @@ async function getModeledMethodsFromFlow(
|
||||
if (queryPath === undefined) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError`Failed to find ${type} query`,
|
||||
);
|
||||
return [];
|
||||
@@ -117,6 +119,7 @@ async function getModeledMethodsFromFlow(
|
||||
if (queryResult.resultType !== QueryResultType.SUCCESS) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError`Failed to run ${basename(queryPath)} query: ${
|
||||
queryResult.message ?? "No message"
|
||||
}`,
|
||||
@@ -130,6 +133,7 @@ async function getModeledMethodsFromFlow(
|
||||
if (bqrsInfo["result-sets"].length !== 1) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError`Expected exactly one result set, got ${
|
||||
bqrsInfo["result-sets"].length
|
||||
} for ${basename(queryPath)}`,
|
||||
|
||||
@@ -32,7 +32,10 @@ import {
|
||||
isLikelyDatabaseRoot,
|
||||
isLikelyDbLanguageFolder,
|
||||
} from "./local-databases/db-contents-heuristics";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
showAndLogErrorMessage,
|
||||
} from "../common/logging";
|
||||
import {
|
||||
importArchiveDatabase,
|
||||
promptImportGithubDatabase,
|
||||
@@ -48,7 +51,6 @@ import {
|
||||
createMultiSelectionCommand,
|
||||
createSingleSelectionCommand,
|
||||
} from "../common/vscode/selection-commands";
|
||||
import { showAndLogErrorMessage } from "../common/logging";
|
||||
|
||||
enum SortOrder {
|
||||
NameAsc = "NameAsc",
|
||||
@@ -280,6 +282,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
} catch (e) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
this.app.logger,
|
||||
this.app.telemetry,
|
||||
redactableError(
|
||||
asError(e),
|
||||
)`Failed to choose and set database: ${getErrorMessage(e)}`,
|
||||
@@ -420,6 +423,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
} catch (e) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
this.app.logger,
|
||||
this.app.telemetry,
|
||||
redactableError(
|
||||
asError(e),
|
||||
)`Failed to delete orphaned database: ${getErrorMessage(e)}`,
|
||||
@@ -449,6 +453,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
} catch (e: unknown) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
this.app.logger,
|
||||
this.app.telemetry,
|
||||
redactableError(
|
||||
asError(e),
|
||||
)`Failed to choose and set database: ${getErrorMessage(e)}`,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import vscode, { ExtensionContext } from "vscode";
|
||||
import { extLogger, Logger } from "../../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
|
||||
import { DisposableObject } from "../../pure/disposable-object";
|
||||
import { App } from "../../common/app";
|
||||
import { QueryRunner } from "../../query-server";
|
||||
@@ -29,6 +29,7 @@ import { remove } from "fs-extra";
|
||||
import { containsPath } from "../../pure/files";
|
||||
import { DatabaseChangedEvent, DatabaseEventKind } from "./database-events";
|
||||
import { DatabaseResolver } from "./database-resolver";
|
||||
import { telemetryListener } from "../../common/vscode/telemetry";
|
||||
|
||||
/**
|
||||
* The name of the key in the workspaceState dictionary in which we
|
||||
@@ -413,6 +414,7 @@ export class DatabaseManager extends DisposableObject {
|
||||
// database list had an unexpected type - nothing to be done?
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
asError(e),
|
||||
)`Database list loading failed: ${getErrorMessage(e)}`,
|
||||
|
||||
@@ -80,7 +80,12 @@ import {
|
||||
ProgressReporter,
|
||||
queryServerLogger,
|
||||
} from "./common";
|
||||
import { showAndLogExceptionWithTelemetry } from "./common/vscode/logging";
|
||||
import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
showAndLogErrorMessage,
|
||||
showAndLogInformationMessage,
|
||||
showAndLogWarningMessage,
|
||||
} from "./common/logging";
|
||||
import { QueryHistoryManager } from "./query-history/query-history-manager";
|
||||
import { CompletedLocalQueryInfo } from "./query-results";
|
||||
import {
|
||||
@@ -90,7 +95,10 @@ import {
|
||||
import { QLTestAdapterFactory } from "./query-testing/test-adapter";
|
||||
import { TestUIService } from "./query-testing/test-ui";
|
||||
import { CompareView } from "./compare/compare-view";
|
||||
import { initializeTelemetry } from "./telemetry";
|
||||
import {
|
||||
initializeTelemetry,
|
||||
telemetryListener,
|
||||
} from "./common/vscode/telemetry";
|
||||
import { ProgressCallback, withProgress } from "./common/vscode/progress";
|
||||
import { CodeQlStatusBarHandler } from "./status-bar";
|
||||
import { getPackagingCommands } from "./packaging";
|
||||
@@ -126,11 +134,6 @@ import { TestRunner } from "./query-testing/test-runner";
|
||||
import { TestManagerBase } from "./query-testing/test-manager-base";
|
||||
import { NewQueryRunner, QueryRunner, QueryServerClient } from "./query-server";
|
||||
import { QueriesModule } from "./queries-panel/queries-module";
|
||||
import {
|
||||
showAndLogErrorMessage,
|
||||
showAndLogInformationMessage,
|
||||
showAndLogWarningMessage,
|
||||
} from "./common/logging";
|
||||
|
||||
/**
|
||||
* extension.ts
|
||||
@@ -1134,6 +1137,7 @@ async function showResultsForComparison(
|
||||
} catch (e) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(asError(e))`Failed to show results: ${getErrorMessage(
|
||||
e,
|
||||
)}`,
|
||||
@@ -1159,16 +1163,16 @@ function addUnhandledRejectionListener() {
|
||||
)`Unhandled error: ${getErrorMessage(error)}`;
|
||||
// Add a catch so that showAndLogExceptionWithTelemetry fails, we avoid
|
||||
// triggering "unhandledRejection" and avoid an infinite loop
|
||||
showAndLogExceptionWithTelemetry(extLogger, message).catch(
|
||||
(telemetryError: unknown) => {
|
||||
void extLogger.log(
|
||||
`Failed to send error telemetry: ${getErrorMessage(
|
||||
telemetryError,
|
||||
)}`,
|
||||
);
|
||||
void extLogger.log(message.fullMessage);
|
||||
},
|
||||
);
|
||||
showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
message,
|
||||
).catch((telemetryError: unknown) => {
|
||||
void extLogger.log(
|
||||
`Failed to send error telemetry: ${getErrorMessage(telemetryError)}`,
|
||||
);
|
||||
void extLogger.log(message.fullMessage);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ import { asError, getErrorMessage } from "../../pure/helpers-pure";
|
||||
import { redactableError } from "../../pure/errors";
|
||||
import { AstViewerCommands } from "../../common/commands";
|
||||
import { extLogger } from "../../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
|
||||
import { telemetryListener } from "../../common/vscode/telemetry";
|
||||
|
||||
export interface AstItem {
|
||||
id: BqrsId;
|
||||
@@ -147,6 +148,7 @@ export class AstViewer extends DisposableObject {
|
||||
(error: unknown) =>
|
||||
showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
asError(error),
|
||||
)`Failed to reveal AST: ${getErrorMessage(error)}`,
|
||||
@@ -211,6 +213,7 @@ export class AstViewer extends DisposableObject {
|
||||
(error: unknown) =>
|
||||
showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
asError(error),
|
||||
)`Failed to reveal AST: ${getErrorMessage(error)}`,
|
||||
|
||||
@@ -18,12 +18,13 @@ import {
|
||||
import { CodeQLCliServer } from "../../codeql-cli/cli";
|
||||
import { DatabaseItem } from "../../databases/local-databases";
|
||||
import { extLogger, TeeLogger } from "../../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
|
||||
import { CancellationToken } from "vscode";
|
||||
import { ProgressCallback } from "../../common/vscode/progress";
|
||||
import { CoreCompletedQuery, QueryRunner } from "../../query-server";
|
||||
import { redactableError } from "../../pure/errors";
|
||||
import { QLPACK_FILENAMES } from "../../pure/ql";
|
||||
import { telemetryListener } from "../../common/vscode/telemetry";
|
||||
|
||||
export async function qlpackOfDatabase(
|
||||
cli: Pick<CodeQLCliServer, "resolveQlpacks">,
|
||||
@@ -102,7 +103,7 @@ current library path (tried searching the following packs: ${joinedPacksToSearch
|
||||
Try upgrading the CodeQL libraries. If that doesn't work, then ${keyTypeName} queries are not yet available \
|
||||
for this language.`;
|
||||
|
||||
void showAndLogExceptionWithTelemetry(extLogger, error);
|
||||
void showAndLogExceptionWithTelemetry(extLogger, telemetryListener, error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ import { getErrorMessage } from "../pure/helpers-pure";
|
||||
import { redactableError } from "../pure/errors";
|
||||
import { AppCommandManager, QueryEditorCommands } from "../common/commands";
|
||||
import { extLogger } from "../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/logging";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
|
||||
type QueryEditorOptions = {
|
||||
commandManager: AppCommandManager;
|
||||
@@ -80,9 +81,14 @@ async function previewQueryHelp(
|
||||
)
|
||||
? redactableError`Could not generate markdown from ${pathToQhelp}: Bad formatting in .qhelp file.`
|
||||
: redactableError`Could not open a preview of the generated file (${absolutePathToMd}).`;
|
||||
void showAndLogExceptionWithTelemetry(extLogger, errorMessage, {
|
||||
fullMessage: `${errorMessage}\n${getErrorMessage(e)}`,
|
||||
});
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
errorMessage,
|
||||
{
|
||||
fullMessage: `${errorMessage}\n${getErrorMessage(e)}`,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { BaseLogger, extLogger, Logger } from "../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
showAndLogWarningMessage,
|
||||
} from "../common/logging";
|
||||
import { CoreQueryResults } from "../query-server";
|
||||
import { QueryHistoryManager } from "../query-history/query-history-manager";
|
||||
import { DatabaseItem } from "../databases/local-databases";
|
||||
@@ -17,8 +20,8 @@ import { CodeQLCliServer } from "../codeql-cli/cli";
|
||||
import { QueryResultType } from "../pure/new-messages";
|
||||
import { redactableError } from "../pure/errors";
|
||||
import { LocalQueries } from "./local-queries";
|
||||
import { showAndLogWarningMessage } from "../common/logging";
|
||||
import { tryGetQueryMetadata } from "../codeql-cli/query-metadata";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
|
||||
function formatResultMessage(result: CoreQueryResults): string {
|
||||
switch (result.resultType) {
|
||||
@@ -154,7 +157,11 @@ export class LocalQueryRun {
|
||||
const message = results.message
|
||||
? redactableError`Failed to run query: ${results.message}`
|
||||
: redactableError`Failed to run query`;
|
||||
void showAndLogExceptionWithTelemetry(extLogger, message);
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
message,
|
||||
);
|
||||
}
|
||||
const message = formatResultMessage(results);
|
||||
const successful = results.resultType === QueryResultType.SUCCESS;
|
||||
|
||||
@@ -41,7 +41,7 @@ import {
|
||||
ParsedResultSets,
|
||||
} from "../pure/interface-types";
|
||||
import { extLogger, Logger } from "../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/logging";
|
||||
import {
|
||||
CompletedQueryInfo,
|
||||
interpretResultsSarif,
|
||||
@@ -71,7 +71,7 @@ import {
|
||||
} from "../common/vscode/abstract-webview";
|
||||
import { isCanary, PAGE_SIZE } from "../config";
|
||||
import { HistoryItemLabelProvider } from "../query-history/history-item-label-provider";
|
||||
import { telemetryListener } from "../telemetry";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
import { redactableError } from "../pure/errors";
|
||||
import { ResultsViewCommands } from "../common/commands";
|
||||
|
||||
@@ -320,6 +320,7 @@ export class ResultsView extends AbstractWebview<
|
||||
case "unhandledError":
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
msg.error,
|
||||
)`Unhandled error in results view: ${msg.error.message}`,
|
||||
@@ -331,6 +332,7 @@ export class ResultsView extends AbstractWebview<
|
||||
} catch (e) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
asError(e),
|
||||
)`Error handling message from results view: ${getErrorMessage(e)}`,
|
||||
@@ -381,6 +383,7 @@ export class ResultsView extends AbstractWebview<
|
||||
if (this._displayedQuery === undefined) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError`Failed to sort results since evaluation info was unknown.`,
|
||||
);
|
||||
return;
|
||||
@@ -400,6 +403,7 @@ export class ResultsView extends AbstractWebview<
|
||||
if (this._displayedQuery === undefined) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError`Failed to sort results since evaluation info was unknown.`,
|
||||
);
|
||||
return;
|
||||
@@ -811,6 +815,7 @@ export class ResultsView extends AbstractWebview<
|
||||
// trying to render uninterpreted results anyway.
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
asError(e),
|
||||
)`Showing raw results instead of interpreted ones due to an error. ${getErrorMessage(
|
||||
|
||||
@@ -7,12 +7,15 @@ import {
|
||||
withProgress,
|
||||
} from "../common/vscode/progress";
|
||||
import { extLogger } from "../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
showAndLogInformationMessage,
|
||||
} from "../common/logging";
|
||||
import { asError, getErrorStack } from "../pure/helpers-pure";
|
||||
import { redactableError } from "../pure/errors";
|
||||
import { PACKS_BY_QUERY_LANGUAGE } from "../common/query-language";
|
||||
import { PackagingCommands } from "../common/commands";
|
||||
import { showAndLogInformationMessage } from "../common/logging";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
|
||||
type PackagingOptions = {
|
||||
cliServer: CodeQLCliServer;
|
||||
@@ -92,6 +95,7 @@ export async function handleDownloadPacks(
|
||||
} catch (error) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
asError(error),
|
||||
)`Unable to download all packs. See log for more details.`,
|
||||
|
||||
@@ -13,7 +13,8 @@ import { asError, getErrorMessage } from "../pure/helpers-pure";
|
||||
import { redactableError } from "../pure/errors";
|
||||
import { EvalLogViewerCommands } from "../common/commands";
|
||||
import { extLogger } from "../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/logging";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
|
||||
export interface EvalLogTreeItem {
|
||||
label?: string;
|
||||
@@ -111,6 +112,7 @@ export class EvalLogViewer extends DisposableObject {
|
||||
(err: unknown) =>
|
||||
showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
asError(err),
|
||||
)`Failed to reveal tree view: ${getErrorMessage(err)}`,
|
||||
|
||||
@@ -13,7 +13,8 @@ import { QueryHistoryDto, QueryHistoryItemDto } from "./query-history-dto";
|
||||
import { mapQueryHistoryToDomainModel } from "./query-history-dto-mapper";
|
||||
import { mapQueryHistoryToDto } from "./query-history-domain-mapper";
|
||||
import { extLogger } from "../../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
|
||||
import { telemetryListener } from "../../common/vscode/telemetry";
|
||||
|
||||
const ALLOWED_QUERY_HISTORY_VERSIONS = [1, 2];
|
||||
|
||||
@@ -32,6 +33,7 @@ export async function readQueryHistoryFromFile(
|
||||
if (!ALLOWED_QUERY_HISTORY_VERSIONS.includes(obj.version)) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError`Can't parse query history. Unsupported query history format: v${obj.version}.`,
|
||||
);
|
||||
return [];
|
||||
@@ -68,6 +70,7 @@ export async function readQueryHistoryFromFile(
|
||||
} catch (e) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(asError(e))`Error loading query history.`,
|
||||
{
|
||||
fullMessage: `Error loading query history.\n${getErrorStack(e)}`,
|
||||
|
||||
@@ -13,7 +13,10 @@ import { tmpDir } from "../../tmp-dir";
|
||||
import { ProgressCallback } from "../../common/vscode/progress";
|
||||
import { QueryMetadata } from "../../pure/interface-types";
|
||||
import { extLogger, Logger } from "../../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
|
||||
import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
showAndLogWarningMessage,
|
||||
} from "../../common/logging";
|
||||
import * as messages from "../../pure/legacy-messages";
|
||||
import * as newMessages from "../../pure/new-messages";
|
||||
import * as qsClient from "./query-server-client";
|
||||
@@ -23,8 +26,8 @@ import { QueryEvaluationInfo, QueryOutputDir } from "../../run-queries-shared";
|
||||
import { redactableError } from "../../pure/errors";
|
||||
import { CoreQueryResults, CoreQueryTarget } from "../query-runner";
|
||||
import { Position } from "../../pure/messages-shared";
|
||||
import { showAndLogWarningMessage } from "../../common/logging";
|
||||
import { ensureDirSync } from "fs-extra";
|
||||
import { telemetryListener } from "../../common/vscode/telemetry";
|
||||
|
||||
const upgradesTmpDir = join(tmpDir.name, "upgrades");
|
||||
ensureDirSync(upgradesTmpDir);
|
||||
@@ -386,6 +389,7 @@ export async function compileAndRunQueryAgainstDatabaseCore(
|
||||
} catch (e) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
asError(e),
|
||||
)`Couldn't resolve available ML models for ${qlProgram.queryPath}. Running the query without any ML models: ${e}.`,
|
||||
@@ -444,7 +448,11 @@ export async function compileAndRunQueryAgainstDatabaseCore(
|
||||
? redactableError`${result.message}`
|
||||
: redactableError`Failed to run query`;
|
||||
void extLogger.log(error.fullMessage);
|
||||
void showAndLogExceptionWithTelemetry(extLogger, error);
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
error,
|
||||
);
|
||||
}
|
||||
|
||||
return translateLegacyResult(result);
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
UserCancellationException,
|
||||
} from "../../common/vscode/progress";
|
||||
import { extLogger } from "../../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
|
||||
import * as messages from "../../pure/legacy-messages";
|
||||
import * as qsClient from "./query-server-client";
|
||||
import * as tmp from "tmp-promise";
|
||||
@@ -14,6 +14,7 @@ import { dirname } from "path";
|
||||
import { DatabaseItem } from "../../databases/local-databases";
|
||||
import { asError, getErrorMessage } from "../../pure/helpers-pure";
|
||||
import { redactableError } from "../../pure/errors";
|
||||
import { telemetryListener } from "../../common/vscode/telemetry";
|
||||
|
||||
/**
|
||||
* Maximum number of lines to include from database upgrade message,
|
||||
@@ -207,6 +208,7 @@ export async function upgradeDatabaseExplicit(
|
||||
} catch (e) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
asError(e),
|
||||
)`Compilation of database upgrades failed: ${getErrorMessage(e)}`,
|
||||
@@ -222,6 +224,7 @@ export async function upgradeDatabaseExplicit(
|
||||
: redactableError`[no error message available]`;
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError`Compilation of database upgrades failed: ${error}`,
|
||||
);
|
||||
return;
|
||||
@@ -256,6 +259,7 @@ export async function upgradeDatabaseExplicit(
|
||||
} catch (e) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(asError(e))`Database upgrade failed: ${getErrorMessage(
|
||||
e,
|
||||
)}`,
|
||||
|
||||
@@ -6,9 +6,12 @@ import { asError, getErrorMessage } from "../pure/helpers-pure";
|
||||
import { redactableError } from "../pure/errors";
|
||||
import { access } from "fs-extra";
|
||||
import { BaseLogger, extLogger } from "../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
showAndLogWarningMessage,
|
||||
} from "../common/logging";
|
||||
import { DisposableObject } from "../pure/disposable-object";
|
||||
import { showAndLogWarningMessage } from "../common/logging";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
|
||||
async function isFileAccessible(uri: Uri): Promise<boolean> {
|
||||
try {
|
||||
@@ -87,6 +90,7 @@ export class TestRunner extends DisposableObject {
|
||||
// So we need to display the error message ourselves and then rethrow.
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(asError(e))`Cannot remove database ${
|
||||
database.name
|
||||
}: ${getErrorMessage(e)}`,
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
WebviewPanelConfig,
|
||||
} from "../common/vscode/abstract-webview";
|
||||
import { assertNever } from "../pure/helpers-pure";
|
||||
import { telemetryListener } from "../telemetry";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
import {
|
||||
FromDataFlowPathsMessage,
|
||||
ToDataFlowPathsMessage,
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
import { DataFlowPaths } from "./shared/data-flow-paths";
|
||||
import { redactableError } from "../pure/errors";
|
||||
import { extLogger } from "../common";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/logging";
|
||||
|
||||
export class DataFlowPathsView extends AbstractWebview<
|
||||
ToDataFlowPathsMessage,
|
||||
@@ -61,6 +61,7 @@ export class DataFlowPathsView extends AbstractWebview<
|
||||
case "unhandledError":
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
redactableError(
|
||||
msg.error,
|
||||
)`Unhandled error in data flow paths view: ${msg.error.message}`,
|
||||
|
||||
@@ -71,8 +71,8 @@ import {
|
||||
} from "./repo-states-store";
|
||||
import { GITHUB_AUTH_PROVIDER_ID } from "../common/vscode/authentication";
|
||||
import { FetchError } from "node-fetch";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
showAndLogInformationMessage,
|
||||
showAndLogWarningMessage,
|
||||
} from "../common/logging";
|
||||
@@ -329,6 +329,7 @@ export class VariantAnalysisManager
|
||||
if (!this.variantAnalyses.get(variantAnalysisId)) {
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
this.app.logger,
|
||||
this.app.telemetry,
|
||||
redactableError`No variant analysis found with id: ${variantAnalysisId}.`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ import {
|
||||
AbstractWebview,
|
||||
WebviewPanelConfig,
|
||||
} from "../common/vscode/abstract-webview";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
|
||||
import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
showAndLogWarningMessage,
|
||||
} from "../common/logging";
|
||||
import {
|
||||
FromVariantAnalysisMessage,
|
||||
ToVariantAnalysisMessage,
|
||||
@@ -18,7 +21,7 @@ import {
|
||||
VariantAnalysisViewInterface,
|
||||
VariantAnalysisViewManager,
|
||||
} from "./variant-analysis-view-manager";
|
||||
import { telemetryListener } from "../telemetry";
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
import { redactableError } from "../pure/errors";
|
||||
import { DataFlowPathsView } from "./data-flow-paths-view";
|
||||
import { DataFlowPaths } from "./shared/data-flow-paths";
|
||||
@@ -27,7 +30,6 @@ import {
|
||||
getVariantAnalysisDefaultResultsFilter,
|
||||
getVariantAnalysisDefaultResultsSort,
|
||||
} from "../config";
|
||||
import { showAndLogWarningMessage } from "../common/logging";
|
||||
|
||||
export class VariantAnalysisView
|
||||
extends AbstractWebview<ToVariantAnalysisMessage, FromVariantAnalysisMessage>
|
||||
@@ -164,6 +166,7 @@ export class VariantAnalysisView
|
||||
case "unhandledError":
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
this.app.logger,
|
||||
this.app.telemetry,
|
||||
redactableError(
|
||||
msg.error,
|
||||
)`Unhandled error in variant analysis results view: ${msg.error.message}`,
|
||||
|
||||
@@ -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,
|
||||
|
||||
9
extensions/ql-vscode/test/__mocks__/telemetryMock.ts
Normal file
9
extensions/ql-vscode/test/__mocks__/telemetryMock.ts
Normal 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(),
|
||||
};
|
||||
}
|
||||
@@ -5,15 +5,16 @@ import { CodeQLCliServer } from "../../../../src/codeql-cli/cli";
|
||||
import { getErrorMessage } from "../../../../src/pure/helpers-pure";
|
||||
|
||||
import * as log from "../../../../src/common/logging/notifications";
|
||||
import * as vscodeLog from "../../../../src/common/vscode/logging";
|
||||
import {
|
||||
handleDownloadPacks,
|
||||
handleInstallPackDependencies,
|
||||
} from "../../../../src/packaging";
|
||||
import { mockedQuickPickItem } from "../../utils/mocking.helpers";
|
||||
import { getActivatedExtension } from "../../global.helper";
|
||||
import { showAndLogInformationMessage } from "../../../../src/common/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../../../src/common/vscode/logging";
|
||||
import {
|
||||
showAndLogInformationMessage,
|
||||
showAndLogExceptionWithTelemetry,
|
||||
} from "../../../../src/common/logging";
|
||||
|
||||
describe("Packaging commands", () => {
|
||||
let cli: CodeQLCliServer;
|
||||
@@ -35,7 +36,7 @@ describe("Packaging commands", () => {
|
||||
.spyOn(window, "showInputBox")
|
||||
.mockResolvedValue(undefined);
|
||||
showAndLogExceptionWithTelemetrySpy = jest
|
||||
.spyOn(vscodeLog, "showAndLogExceptionWithTelemetry")
|
||||
.spyOn(log, "showAndLogExceptionWithTelemetry")
|
||||
.mockResolvedValue(undefined);
|
||||
showAndLogInformationMessageSpy = jest
|
||||
.spyOn(log, "showAndLogInformationMessage")
|
||||
@@ -82,7 +83,7 @@ describe("Packaging commands", () => {
|
||||
|
||||
expect(showAndLogExceptionWithTelemetrySpy).toHaveBeenCalled();
|
||||
expect(
|
||||
showAndLogExceptionWithTelemetrySpy.mock.calls[0][1].fullMessage,
|
||||
showAndLogExceptionWithTelemetrySpy.mock.calls[0][2].fullMessage,
|
||||
).toEqual("Unable to download all packs. See log for more details.");
|
||||
});
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ import { readdir, readFile } from "fs-extra";
|
||||
import { load } from "js-yaml";
|
||||
import { dirname, join } from "path";
|
||||
import { fetchExternalApiQueries } from "../../../../src/data-extensions-editor/queries";
|
||||
import * as vscodeLog from "../../../../src/common/vscode/logging";
|
||||
import * as log from "../../../../src/common/logging/notifications";
|
||||
import { RedactableError } from "../../../../src/pure/errors";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../../../src/common/vscode/logging";
|
||||
import { showAndLogExceptionWithTelemetry } from "../../../../src/common/logging";
|
||||
|
||||
function createMockUri(path = "/a/b/c/foo"): Uri {
|
||||
return {
|
||||
@@ -140,7 +140,7 @@ describe("readQueryResults", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
showAndLogExceptionWithTelemetrySpy = jest.spyOn(
|
||||
vscodeLog,
|
||||
log,
|
||||
"showAndLogExceptionWithTelemetry",
|
||||
);
|
||||
});
|
||||
@@ -153,6 +153,7 @@ describe("readQueryResults", () => {
|
||||
expect(await readQueryResults(options)).toBeUndefined();
|
||||
expect(showAndLogExceptionWithTelemetrySpy).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
undefined,
|
||||
expect.any(RedactableError),
|
||||
);
|
||||
});
|
||||
@@ -186,6 +187,7 @@ describe("readQueryResults", () => {
|
||||
expect(await readQueryResults(options)).toBeUndefined();
|
||||
expect(showAndLogExceptionWithTelemetrySpy).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
undefined,
|
||||
expect.any(RedactableError),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -6,9 +6,9 @@ import {
|
||||
window,
|
||||
} from "vscode";
|
||||
import {
|
||||
TelemetryListener,
|
||||
ExtensionTelemetryListener,
|
||||
telemetryListener as globalTelemetryListener,
|
||||
} from "../../../src/telemetry";
|
||||
} from "../../../src/common/vscode/telemetry";
|
||||
import { UserCancellationException } from "../../../src/common/vscode/progress";
|
||||
import { ENABLE_TELEMETRY } from "../../../src/config";
|
||||
import { createMockExtensionContext } from "./index";
|
||||
@@ -25,7 +25,7 @@ describe("telemetry reporting", () => {
|
||||
let originalTelemetryGlobal: boolean | undefined;
|
||||
let isCanary: string;
|
||||
let ctx: ExtensionContext;
|
||||
let telemetryListener: TelemetryListener;
|
||||
let telemetryListener: ExtensionTelemetryListener;
|
||||
|
||||
let sendTelemetryEventSpy: jest.SpiedFunction<
|
||||
typeof TelemetryReporter.prototype.sendTelemetryEvent
|
||||
@@ -81,7 +81,7 @@ describe("telemetry reporting", () => {
|
||||
await enableTelemetry("telemetry", true);
|
||||
await enableTelemetry("codeQL.telemetry", true);
|
||||
|
||||
telemetryListener = new TelemetryListener(
|
||||
telemetryListener = new ExtensionTelemetryListener(
|
||||
"my-id",
|
||||
"1.2.3",
|
||||
"fake-key",
|
||||
|
||||
Reference in New Issue
Block a user