Migrate the legacy log to the telemetry wrapper (#866)

This commit is contained in:
Jinbo Wang 2020-08-20 17:16:46 +08:00 committed by GitHub
parent 766b602fc3
commit 27a6708f1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 86 additions and 34 deletions

View File

@ -6,7 +6,7 @@ import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";
import { instrumentOperation } from "vscode-extension-telemetry-wrapper";
import { instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
import * as anchor from "./anchor";
import { buildWorkspace } from "./build";
import { populateStepFilters, substituteFilterVariables } from "./classFilter";
@ -75,6 +75,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
return this.resolveAndValidateDebugConfiguration(folder, config);
} catch (ex) {
utility.showErrorMessage({
type: Type.EXCEPTION,
message: String((ex && ex.message) || ex),
});
return undefined;
@ -296,12 +297,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
return undefined;
}
const errorMessage = (ex && ex.message) || ex;
utility.showErrorMessageWithTroubleshooting({
message: String(errorMessage),
type: Type.EXCEPTION,
details: utility.formatErrorProperties(ex),
});
utility.showErrorMessageWithTroubleshooting(utility.convertErrorToMessage(ex));
return undefined;
}
}
@ -392,6 +388,12 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
const selectedFix: lsPlugin.IMainClassOption =
await this.showMainClassQuickPick(pickItems, "Please select main class<project name>.", false);
if (selectedFix) {
sendInfo(null, {
fix: "yes",
fixMessage: errors.join(os.EOL),
});
// Deprecated
logger.log(Type.USAGEDATA, {
fix: "yes",
fixMessage: errors.join(os.EOL),

View File

@ -13,6 +13,7 @@ import { NotificationBar } from "./customWidget";
import { initializeCodeLensProvider, startDebugging } from "./debugCodeLensProvider";
import { handleHotCodeReplaceCustomEvent, initializeHotCodeReplace, NO_BUTTON, YES_BUTTON } from "./hotCodeReplace";
import { JavaDebugAdapterDescriptorFactory } from "./javaDebugAdapterDescriptorFactory";
import { logJavaException, logJavaInfo } from "./javaLogger";
import { IMainMethod, resolveMainMethod } from "./languageServerPlugin";
import { logger, Type } from "./logger";
import { pickJavaProcess } from "./processPicker";
@ -27,11 +28,8 @@ export async function activate(context: vscode.ExtensionContext) {
}
function initializeExtension(operationId: string, context: vscode.ExtensionContext) {
// Deprecated
logger.initialize(context, true);
logger.log(Type.ACTIVATEEXTENSION, {}); // TODO: Activation belongs to usage data, remove this line.
logger.log(Type.USAGEDATA, {
description: "activateExtension",
});
registerDebugEventListener(context);
context.subscriptions.push(logger);
@ -90,6 +88,13 @@ function registerDebugEventListener(context: vscode.ExtensionContext) {
commonProperties[key] = String(entry[key]);
}
}
if (entry.scope === "exception") {
logJavaException(commonProperties);
} else {
logJavaInfo(commonProperties, measureProperties);
}
// Deprecated
logger.log(entry.scope === "exception" ? Type.EXCEPTION : Type.USAGEDATA, commonProperties, measureProperties);
});
}

View File

@ -5,7 +5,7 @@ import { DebugAdapterDescriptor, DebugAdapterDescriptorFactory, DebugAdapterExec
import { startDebugSession } from "./languageServerPlugin";
import { Type } from "./logger";
import { formatErrorProperties, showErrorMessageWithTroubleshooting } from "./utility";
import { convertErrorToMessage, showErrorMessageWithTroubleshooting } from "./utility";
export class JavaDebugAdapterDescriptorFactory implements DebugAdapterDescriptorFactory {
public async createDebugAdapterDescriptor(session: DebugSession, executable: DebugAdapterExecutable): Promise<DebugAdapterDescriptor> {
@ -23,17 +23,10 @@ export class JavaDebugAdapterDescriptorFactory implements DebugAdapterDescriptor
error = err;
}
let errorMessage = "Failed to start debug server.";
let details = {};
if (error) {
errorMessage = error.message || String(error);
details = formatErrorProperties(error);
}
showErrorMessageWithTroubleshooting({
message: errorMessage,
const message = error ? convertErrorToMessage(error) : {
type: Type.EXCEPTION,
details,
});
message: "Failed to start debug server.",
};
showErrorMessageWithTroubleshooting(message);
}
}

30
src/javaLogger.ts Normal file
View File

@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { sendError, sendInfo, sendOperationError } from "vscode-extension-telemetry-wrapper";
export function logJavaException(errorProperties: any): void {
/**
* A sample errorProperties from Java code.
* {
* "description": "Failed to attach to remote debuggee VM. Reason: java.net.ConnectException: Connection refused: connect",
* "message": "Failed to attach to remote debuggee VM. Reason: java.net.ConnectException: Connection refused: connect",
* "stackTrace": "[{\"declaringClass\":\"com.microsoft.java.debug.core.adapter.AdapterUtils\", ...]",
* "debugSessionid": "5680f12b-5b5f-4ac0-bda3-d1dbc3c12c10",
* }
*/
const { debugSessionId, description, message, stackTrace } = errorProperties;
sendOperationError(debugSessionId, "debugSession", {
name: "JavaException",
message: description || message,
stack: stackTrace,
});
}
export function logJavaInfo(commonProperties: any, measureProperties?: any): void {
if (measureProperties && measureProperties.duration !== undefined) {
sendInfo(commonProperties.debugSessionId, commonProperties, measureProperties);
} else {
sendInfo(commonProperties.debugSessionId, commonProperties);
}
}

View File

@ -3,7 +3,7 @@
import * as path from "path";
import * as vscode from "vscode";
import { setUserError } from "vscode-extension-telemetry-wrapper";
import { sendError, sendInfo, setUserError } from "vscode-extension-telemetry-wrapper";
import { logger, Type } from "./logger";
const TROUBLESHOOTING_LINK = "https://github.com/Microsoft/vscode-java-debug/blob/master/Troubleshooting.md";
@ -28,14 +28,10 @@ export class JavaExtensionNotEnabledError extends Error {
}
}
interface IProperties {
[key: string]: string;
}
interface ILoggingMessage {
message: string;
type?: Type;
details?: IProperties;
message: string;
stack?: string;
}
interface ITroubleshootingMessage extends ILoggingMessage {
@ -47,11 +43,22 @@ function logMessage(message: ILoggingMessage): void {
return;
}
if (message.details) {
logger.log(message.type, message.details);
if (message.type === Type.EXCEPTION || message.type === Type.USAGEERROR) {
const error: Error = {
name: "error",
message: message.message,
stack: message.stack,
};
if (message.type === Type.USAGEERROR) {
setUserError(error);
}
sendError(error);
} else {
logger.logMessage(message.type, message.message);
sendInfo(null, { message: message.message });
}
// Deprecated
logger.log(message.type, { message: message.message, stack: message.stack });
}
export async function showInformationMessage(message: ILoggingMessage, ...items: string[]): Promise<string | undefined> {
@ -95,6 +102,12 @@ function handleTroubleshooting(choice: string, message: string, anchor: string):
export function openTroubleshootingPage(message: string, anchor: string) {
vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(anchor ? `${TROUBLESHOOTING_LINK}#${anchor}` : TROUBLESHOOTING_LINK));
sendInfo(null, {
troubleshooting: "yes",
troubleshootingMessage: message,
});
// Deprecated
logger.log(Type.USAGEDATA, {
troubleshooting: "yes",
troubleshootingMessage: message,
@ -122,7 +135,16 @@ async function installJavaExtension() {
}
}
export function formatErrorProperties(ex: any): IProperties {
export function convertErrorToMessage(err: Error): ILoggingMessage {
const properties = formatErrorProperties(err);
return {
type: Type.EXCEPTION,
message: properties.message,
stack: properties.stackTrace,
};
}
function formatErrorProperties(ex: any): any {
const exception = (ex && ex.data && ex.data.cause)
|| { stackTrace: (ex && ex.stack), detailMessage: String((ex && ex.message) || ex || "Unknown exception") };