Skip to content

Commit

Permalink
Improve telemetry (#543)
Browse files Browse the repository at this point in the history
* Improve telemetry

Signed-off-by: Yevhen Vydolob <[email protected]>

* Fix test

Signed-off-by: Yevhen Vydolob <[email protected]>

* fix timestamp removing

Signed-off-by: Yevhen Vydolob <[email protected]>
  • Loading branch information
evidolob authored Jul 8, 2021
1 parent 5647b42 commit 02a7c5a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
33 changes: 32 additions & 1 deletion src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class TelemetryErrorHandler implements ErrorHandler {
}
}

const errorMassagesToSkip = [{ text: 'Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED', contains: true }];

export class TelemetryOutputChannel implements vscode.OutputChannel {
constructor(private readonly delegate: vscode.OutputChannel, private readonly telemetry: TelemetryService) {}

Expand All @@ -60,9 +62,38 @@ export class TelemetryOutputChannel implements vscode.OutputChannel {

private checkError(value: string): void {
if (value.startsWith('[Error') || value.startsWith(' Message: Request')) {
this.telemetry.send({ name: 'yaml.server.error', properties: { error: value } });
if (this.isNeedToSkip(value)) {
return;
}
this.telemetry.send({ name: 'yaml.server.error', properties: { error: this.createErrorMessage(value) } });
}
}

private isNeedToSkip(value: string): boolean {
for (const skip of errorMassagesToSkip) {
if (skip.contains) {
if (value.includes(skip.text)) {
return true;
}
} else {
const starts = value.startsWith(skip.text);
if (starts) {
return true;
}
}
}

return false;
}

private createErrorMessage(value: string): string {
if (value.startsWith('[Error')) {
value = value.substr(value.indexOf(']') + 1, value.length).trim();
}

return value;
}

clear(): void {
this.delegate.clear();
}
Expand Down
15 changes: 11 additions & 4 deletions test/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,20 @@ describe('Telemetry Test', () => {
});

it('should send telemetry if log error in "append"', () => {
telemetryChannel.append('[Error Some');
expect(telemetry.send).calledOnceWith({ name: 'yaml.server.error', properties: { error: '[Error Some' } });
telemetryChannel.append('[Error] Some');
expect(telemetry.send).calledOnceWith({ name: 'yaml.server.error', properties: { error: 'Some' } });
});

it('should send telemetry if log error on "appendLine"', () => {
telemetryChannel.appendLine('[Error Some');
expect(telemetry.send).calledOnceWith({ name: 'yaml.server.error', properties: { error: '[Error Some' } });
telemetryChannel.appendLine('[Error] Some error');
expect(telemetry.send).calledOnceWith({ name: 'yaml.server.error', properties: { error: 'Some error' } });
});

it("shouldn't send telemetry if error should be skipped", () => {
telemetryChannel.append(
"[Error - 15:10:33] (node:25052) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification."
);
expect(telemetry.send).not.called;
});
});

Expand Down

0 comments on commit 02a7c5a

Please sign in to comment.