Skip to content

Commit 8227ca0

Browse files
committed
Add stack_trace property to telemetry
Stack trace removes local folder root location from files in the stack trace. Signed-off-by: Denis Golovin [email protected]
1 parent 06a89ca commit 8227ca0

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

package-lock.json

Lines changed: 16 additions & 1 deletion
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
@@ -93,6 +93,7 @@
9393
"rxjs": "^6.5.3",
9494
"semver": "^6.3.0",
9595
"shelljs": "^0.8.3",
96+
"stacktrace-parser": "^0.1.10",
9697
"string-format": "^2.0.0",
9798
"tree-kill": "^1.2.2",
9899
"validator": "^12.2.0",

src/vscommand.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
/* eslint-disable @typescript-eslint/no-explicit-any */
77

88
import { commands, Disposable, window } from 'vscode';
9+
import * as stackTraceParser from 'stacktrace-parser';
910
import sendTelemetry from './telemetry';
11+
import { ExtenisonID } from './util/constants';
1012

1113
type VsCommandFunction = (...args: any[]) => Promise<any> | any;
1214

@@ -43,10 +45,20 @@ export async function registerCommands(...modules: string[]): Promise<Disposable
4345
};
4446
let result: any;
4547
const startTime = Date.now();
48+
let stackTrace = {};
4649
try {
4750
result = await Promise.resolve(cmd.method.call(null, ...params));
4851
displayResult(result);
4952
} catch (err) {
53+
if (err.stack) {
54+
const stack = stackTraceParser.parse(err.stack);
55+
if (stack.length > 0) {
56+
const files = stack.map((value) => `${value.file.substring(value.file.lastIndexOf(ExtenisonID)-1)}:${value.lineNumber}:${value.column}`);
57+
stackTrace = {
58+
'stack_trace': files.join('\n')
59+
};
60+
}
61+
}
5062
if (err instanceof VsCommandError) {
5163
// exception thrown by extension command with meaningful message
5264
// just show it and return
@@ -58,15 +70,15 @@ export async function registerCommands(...modules: string[]): Promise<Disposable
5870
// TODO: Wrap view title commands in try/catch and re-throw as VsCommandError
5971
// TODO: telemetry cannot send not known exception stacktrace or message
6072
// because it can contain user's sensitive information
61-
telemetryProps.error = 'Not extension declared exception happened';
6273
throw err;
6374
}
6475
} finally {
6576
telemetryProps.duration = Date.now() - startTime;
6677
telemetryProps.cancelled = result === null;
6778
if (result?.properties) {
68-
telemetryProps = {...telemetryProps, ...result.properties };
79+
telemetryProps = {...telemetryProps, ...result.properties};
6980
}
81+
telemetryProps = {...telemetryProps, ...stackTrace };
7082
sendTelemetry('command', telemetryProps);
7183
}
7284
});

0 commit comments

Comments
 (0)