Skip to content

Commit e22a721

Browse files
authored
add telemetry wrapper for common operations. (#71)
* add telemetry wrapper for common operations.
1 parent b8fe9db commit e22a721

File tree

6 files changed

+103
-20
lines changed

6 files changed

+103
-20
lines changed

package-lock.json

Lines changed: 63 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"find-java-home": "^0.2.0",
114114
"fs-extra": "^7.0.0",
115115
"vscode-extension-telemetry": "0.0.22",
116+
"vscode-extension-telemetry-wrapper": "^0.3.3",
116117
"xml2js": "^0.4.19"
117118
}
118119
}

src/extension.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,32 @@
22
// Licensed under the MIT license.
33

44
import { commands, ExtensionContext } from "vscode";
5+
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation } from "vscode-extension-telemetry-wrapper";
56
import { Commands } from "./commands";
67
import { ProjectController } from "./controllers/projectController";
78
import { Services } from "./services";
89
import { Settings } from "./settings";
9-
import { Telemetry } from "./telemetry";
10-
import { DependencyExplorer } from "./views/depedencyExplorer";
10+
import { DependencyExplorer } from "./views/dependencyExplorer";
1111

12-
export function activate(context: ExtensionContext) {
13-
Telemetry.sendEvent("activateExtension", {});
12+
export async function activate(context: ExtensionContext): Promise<any> {
13+
await initializeFromJsonFile(context.asAbsolutePath("./package.json"));
14+
return instrumentOperation("activation", activateExtension)(context);
15+
}
1416

17+
function activateExtension(operationId: string, context: ExtensionContext) {
1518
commands.executeCommand("setContext", "extensionActivated", true);
1619

1720
Services.initialize(context);
1821
Settings.initialize(context);
1922

2023
const projectController: ProjectController = new ProjectController(context);
21-
context.subscriptions.push(commands.registerCommand(Commands.JAVA_PROJECT_CREATE, async () => { projectController.createJavaProject(); }));
24+
const instrumented = instrumentOperation(Commands.JAVA_PROJECT_CREATE, () => projectController.createJavaProject());
25+
context.subscriptions.push(commands.registerCommand(Commands.JAVA_PROJECT_CREATE, instrumented));
2226

2327
context.subscriptions.push(new DependencyExplorer(context));
2428
}
29+
30+
// this method is called when your extension is deactivated
31+
export async function deactivate() {
32+
await disposeTelemetryWrapper();
33+
}

src/views/dependencyDataProvider.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
commands, Event, EventEmitter, ExtensionContext, ProviderResult, Range,
66
Selection, TextEditorRevealType, TreeDataProvider, TreeItem, Uri, window, workspace,
77
} from "vscode";
8+
import { instrumentOperation } from "vscode-extension-telemetry-wrapper";
89
import { Commands } from "../commands";
910
import { Jdtls } from "../java/jdtls";
1011
import { INodeData, NodeKind } from "../java/nodeData";
1112
import { Telemetry } from "../telemetry";
12-
import { DataNode } from "./dataNode";
1313
import { ExplorerNode } from "./explorerNode";
1414
import { ProjectNode } from "./projectNode";
1515
import { WorkspaceNode } from "./workspaceNode";
@@ -24,9 +24,12 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
2424
private _rootItems: ExplorerNode[] = null;
2525

2626
constructor(public readonly context: ExtensionContext) {
27-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_REFRESH, this.refresh, this));
28-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_OPEN_FILE, this.openFile, this));
29-
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_OUTLINE, this.goToOutline, this));
27+
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_REFRESH,
28+
instrumentOperation(Commands.VIEW_PACKAGE_REFRESH, () => this.refresh())));
29+
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_OPEN_FILE,
30+
instrumentOperation(Commands.VIEW_PACKAGE_OPEN_FILE, (_operationId, uri) => this.openFile(uri))));
31+
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_OUTLINE,
32+
instrumentOperation(Commands.VIEW_PACKAGE_OUTLINE, (_operationId, uri, range) => this.goToOutline(uri, range))));
3033
}
3134

3235
public refresh() {
@@ -36,14 +39,12 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
3639

3740
public openFile(uri: string) {
3841
return workspace.openTextDocument(Uri.parse(uri)).then((res) => {
39-
Telemetry.sendEvent("open source file");
4042
return window.showTextDocument(res);
4143
});
4244
}
4345

4446
public goToOutline(uri: string, range: Range): Thenable<{}> {
4547
return this.openFile(uri).then((editor) => {
46-
Telemetry.sendEvent("view package outline");
4748
editor.revealRange(range, TextEditorRevealType.Default);
4849
editor.selection = new Selection(range.start, range.start);
4950
return commands.executeCommand("workbench.action.focusActiveEditorGroup");
File renamed without changes.

src/views/typeRootNode.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
import { Command, commands, DocumentSymbol, SymbolInformation, TextDocument, ThemeIcon, Uri, workspace } from "vscode";
5+
import { createUuid, sendOperationEnd, sendOperationStart } from "vscode-extension-telemetry-wrapper";
56
import { Commands } from "../commands";
67
import { INodeData } from "../java/nodeData";
78
import { ITypeRootNodeData, TypeRootKind } from "../java/typeRootNodeData";
@@ -62,11 +63,23 @@ export class TypeRootNode extends DataNode {
6263
return Settings.showOutline();
6364
}
6465

65-
private getSymbols(document: TextDocument): Thenable<SymbolInformation[] | DocumentSymbol[]> {
66-
return commands.executeCommand<SymbolInformation[]>(
67-
"vscode.executeDocumentSymbolProvider",
68-
document.uri,
69-
);
66+
private async getSymbols(document: TextDocument): Promise<SymbolInformation[] | DocumentSymbol[]> {
67+
let error;
68+
const operationId = createUuid();
69+
const startAt: number = Date.now();
70+
sendOperationStart(operationId, "vscode.executeDocumentSymbolProvider");
71+
try {
72+
return await commands.executeCommand<SymbolInformation[]>(
73+
"vscode.executeDocumentSymbolProvider",
74+
document.uri,
75+
);
76+
} catch (err) {
77+
error = err;
78+
throw err;
79+
} finally {
80+
const duration = Date.now() - startAt;
81+
sendOperationEnd(operationId, "vscode.executeDocumentSymbolProvider", duration, error);
82+
}
7083
}
7184

7285
private buildSymbolTree(symbols: SymbolInformation[]): Map<string, SymbolInformation[]> {

0 commit comments

Comments
 (0)