-
Notifications
You must be signed in to change notification settings - Fork 254
Add telemetry #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add telemetry #490
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2255495
#458 add telemetry
evidolob 610909d
fix test
evidolob d25ccc4
Merge branch 'master' of github.com:redhat-developer/vscode-yaml into…
evidolob 4e48fc5
Fix review comments
evidolob 449961d
fix build
evidolob f41a4a0
Rename test and constant
evidolob 89f08ae
fix typo
evidolob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Data collection | ||
|
|
||
| vscode-yaml has opt-in telemetry collection, provided by [vscode-commons](https://github.com/redhat-developer/vscode-commons). | ||
|
|
||
| ## What's included in the vscode-yaml telemetry data | ||
|
|
||
| - yaml-language-server start | ||
| - errors during yaml language server start | ||
| - any errors from LSP requests | ||
| - `kubernetes` schema usage | ||
|
|
||
| ## What's included in the general telemetry data | ||
|
|
||
| Please see the | ||
| [vscode-commons data collection information](https://github.com/redhat-developer/vscode-commons/blob/master/USAGE_DATA.md#other-extensions) | ||
| for information on what data it collects. | ||
|
|
||
| ## How to opt in or out | ||
|
|
||
| Use the `redhat.telemetry.enabled` setting in order to enable or disable telemetry collection. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Red Hat, Inc. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { TelemetryService } from '@redhat-developer/vscode-redhat-telemetry/lib'; | ||
| import { CloseAction, ErrorAction, ErrorHandler, Message } from 'vscode-languageclient/node'; | ||
| import * as vscode from 'vscode'; | ||
|
|
||
| export class TelemetryErrorHandler implements ErrorHandler { | ||
| private restarts: number[] = []; | ||
| constructor( | ||
| private readonly telemetry: TelemetryService, | ||
| private readonly name: string, | ||
| private readonly maxRestartCount: number | ||
| ) {} | ||
|
|
||
| error(error: Error, message: Message, count: number): ErrorAction { | ||
| this.telemetry.send({ name: 'yaml.lsp.error', properties: { jsonrpc: message.jsonrpc, error: error.message } }); | ||
| if (count && count <= 3) { | ||
| return ErrorAction.Continue; | ||
| } | ||
| return ErrorAction.Shutdown; | ||
| } | ||
| closed(): CloseAction { | ||
| this.restarts.push(Date.now()); | ||
| if (this.restarts.length <= this.maxRestartCount) { | ||
| return CloseAction.Restart; | ||
| } else { | ||
| const diff = this.restarts[this.restarts.length - 1] - this.restarts[0]; | ||
| if (diff <= 3 * 60 * 1000) { | ||
| vscode.window.showErrorMessage( | ||
| `The ${this.name} server crashed ${ | ||
| this.maxRestartCount + 1 | ||
| } times in the last 3 minutes. The server will not be restarted.` | ||
| ); | ||
| return CloseAction.DoNotRestart; | ||
| } else { | ||
| this.restarts.shift(); | ||
| return CloseAction.Restart; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export class TelemetryOutputChannel implements vscode.OutputChannel { | ||
| constructor(private readonly delegate: vscode.OutputChannel, private readonly telemetry: TelemetryService) {} | ||
|
|
||
| get name(): string { | ||
| return this.delegate.name; | ||
| } | ||
| append(value: string): void { | ||
| this.checkError(value); | ||
| this.delegate.append(value); | ||
| } | ||
| appendLine(value: string): void { | ||
| this.checkError(value); | ||
| this.delegate.appendLine(value); | ||
| } | ||
|
|
||
| private checkError(value: string): void { | ||
| if (value.startsWith('[Error') || value.startsWith(' Message: Request')) { | ||
| this.telemetry.send({ name: 'yaml.server.error', properties: { error: value } }); | ||
| } | ||
| } | ||
| clear(): void { | ||
| this.delegate.clear(); | ||
| } | ||
| show(preserveFocus?: boolean): void; | ||
| show(column?: vscode.ViewColumn, preserveFocus?: boolean): void; | ||
| show(column?: never, preserveFocus?: boolean): void { | ||
| this.delegate.show(column, preserveFocus); | ||
| } | ||
| hide(): void { | ||
| this.delegate.hide(); | ||
| } | ||
| dispose(): void { | ||
| this.delegate.dispose(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* -------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Red Hat, Inc. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| * ------------------------------------------------------------------------------------------ */ | ||
| import * as sinon from 'sinon'; | ||
| import * as sinonChai from 'sinon-chai'; | ||
| import * as chai from 'chai'; | ||
| import * as vscode from 'vscode'; | ||
| import { TelemetryErrorHandler, TelemetryOutputChannel } from '../src/telemetry'; | ||
| import { TelemetryEvent, TelemetryService } from '@redhat-developer/vscode-redhat-telemetry/lib/interfaces/telemetry'; | ||
|
|
||
| const expect = chai.expect; | ||
| chai.use(sinonChai); | ||
| class TelemetryStub implements TelemetryService { | ||
| sendStartupEvent(): Promise<void> { | ||
| throw new Error('Method not implemented.'); | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| send(event: TelemetryEvent): Promise<void> { | ||
| throw new Error('Method not implemented.'); | ||
| } | ||
| sendShutdownEvent(): Promise<void> { | ||
| throw new Error('Method not implemented.'); | ||
| } | ||
| flushQueue(): Promise<void> { | ||
| throw new Error('Method not implemented.'); | ||
| } | ||
| dispose(): Promise<void> { | ||
| throw new Error('Method not implemented.'); | ||
| } | ||
| } | ||
| describe('Telemetry Test', () => { | ||
| const sandbox = sinon.createSandbox(); | ||
| const testOutputChannel = vscode.window.createOutputChannel('YAML_TEST'); | ||
| afterEach(() => { | ||
| sandbox.restore(); | ||
| }); | ||
| describe('TelemetryOutputChannel', () => { | ||
| let telemetryChannel: TelemetryOutputChannel; | ||
| let outputChannel: sinon.SinonStubbedInstance<vscode.OutputChannel>; | ||
| let telemetry: sinon.SinonStubbedInstance<TelemetryService>; | ||
| beforeEach(() => { | ||
| outputChannel = sandbox.stub(testOutputChannel); | ||
| telemetry = sandbox.stub(new TelemetryStub()); | ||
| telemetryChannel = new TelemetryOutputChannel( | ||
| (outputChannel as unknown) as vscode.OutputChannel, | ||
| (telemetry as unknown) as TelemetryService | ||
| ); | ||
| }); | ||
|
|
||
| it('should delegate "append" method', () => { | ||
| telemetryChannel.append('Some'); | ||
| expect(outputChannel.append).calledOnceWith('Some'); | ||
| }); | ||
|
|
||
| it('should delegate "appendLine" method', () => { | ||
| telemetryChannel.appendLine('Some'); | ||
| expect(outputChannel.appendLine).calledOnceWith('Some'); | ||
| }); | ||
|
|
||
| it('should delegate "clear" method', () => { | ||
| telemetryChannel.clear(); | ||
| expect(outputChannel.clear).calledOnce; | ||
| }); | ||
|
|
||
| it('should delegate "dispose" method', () => { | ||
| telemetryChannel.dispose(); | ||
| expect(outputChannel.dispose).calledOnce; | ||
| }); | ||
|
|
||
| it('should delegate "hide" method', () => { | ||
| telemetryChannel.hide(); | ||
| expect(outputChannel.hide).calledOnce; | ||
| }); | ||
|
|
||
| it('should delegate "show" method', () => { | ||
| telemetryChannel.show(); | ||
| expect(outputChannel.show).calledOnce; | ||
| }); | ||
|
|
||
| it('should send telemetry if log error', () => { | ||
| telemetryChannel.append('[Error Some'); | ||
| expect(telemetry.send).calledOnceWith({ name: 'yaml.server.error', properties: { error: '[Error Some' } }); | ||
| }); | ||
|
|
||
| it('should send telemetry if log error2', () => { | ||
| telemetryChannel.appendLine('[Error Some'); | ||
| expect(telemetry.send).calledOnceWith({ name: 'yaml.server.error', properties: { error: '[Error Some' } }); | ||
|
evidolob marked this conversation as resolved.
|
||
| }); | ||
| }); | ||
|
|
||
| describe('TelemetryErrorHandler', () => { | ||
| let telemetry: sinon.SinonStubbedInstance<TelemetryService>; | ||
| let errorHandler: TelemetryErrorHandler; | ||
|
|
||
| beforeEach(() => { | ||
| telemetry = sandbox.stub(new TelemetryStub()); | ||
| errorHandler = new TelemetryErrorHandler(telemetry, 'YAML LS', 3); | ||
| }); | ||
|
|
||
| it('should log telemetry on error', () => { | ||
| errorHandler.error(new Error('Some'), { jsonrpc: 'Error message' }, 3); | ||
| expect(telemetry.send).calledOnceWith({ | ||
| name: 'yaml.lsp.error', | ||
| properties: { jsonrpc: 'Error message', error: 'Some' }, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.