Skip to content

Commit

Permalink
Update @redhat-developer/vscode-redhat-telemetry to 0.2.0
Browse files Browse the repository at this point in the history
Closes redhat-developer#365

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Jul 23, 2021
1 parent c336c55 commit 2636c37
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Since 1.6.0:

With your approval, vscode-quarkus extension collects anonymous [usage data](USAGE_DATA.md) and sends it to Red Hat servers to help improve our products and services.
Read our [privacy statement](https://developers.redhat.com/article/tool-data-collection) to learn more.
This extension respects the `redhat.telemetry.enabled` setting, which you can learn more about at https://github.com/redhat-developer/vscode-commons#how-to-disable-telemetry-reporting
This extension respects the `redhat.telemetry.enabled` setting, which you can learn more about at https://github.com/redhat-developer/vscode-redhat-telemetry#how-to-disable-telemetry-reporting

## Articles

Expand Down
4 changes: 2 additions & 2 deletions USAGE_DATA.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# USAGE DATA

vscode-quarkus has opt-in telemetry collection, provided by [vscode-commons](https://github.com/redhat-developer/vscode-commons).
vscode-quarkus has opt-in telemetry collection, provided by [vscode-redhat-telemetry](https://github.com/redhat-developer/vscode-redhat-telemetry).

## What's included in the vscode-quarkus telemetry data

* vscode-quarkus emits telemetry events when the extension starts and stops,
which contain the common data mentioned on the
[vscode-commons page](https://github.com/redhat-developer/vscode-commons/blob/master/USAGE_DATA.md#common-data).
[vscode-redhat-telemetry page](https://github.com/redhat-developer/vscode-redhat-telemetry/blob/master/USAGE_DATA.md#common-data).
* vscode-quarkus emits telemetry events when a vscode-quarkus command runs successfully or fails.
The telemetry event contains the name of the command that is run, and whether it was a success or failure.
If the command fails, it also contains the error message, with any usernames and paths removed from the error message.
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"extensionDependencies": [
"redhat.vscode-microprofile",
"redhat.java",
"vscjava.vscode-java-debug",
"redhat.vscode-commons"
"vscjava.vscode-java-debug"
],
"contributes": {
"javaExtensions": [
Expand Down Expand Up @@ -297,7 +296,7 @@
"webpack-cli": "^3.3.2"
},
"dependencies": {
"@redhat-developer/vscode-redhat-telemetry": "0.0.18",
"@redhat-developer/vscode-redhat-telemetry": "^0.2.0",
"ejs": "^2.7.1",
"expand-home-dir": "0.0.3",
"find-up": "^4.1.0",
Expand Down
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { getTelemetryService, TelemetryService } from '@redhat-developer/vscode-redhat-telemetry';
import { TelemetryService } from '@redhat-developer/vscode-redhat-telemetry';
import * as path from 'path';
import { commands, ConfigurationChangeEvent, Disposable, ExtensionContext, languages, Terminal, TextDocument, window, workspace } from 'vscode';
import { registerVSCodeCommands } from './commands/registerCommands';
Expand All @@ -25,11 +25,11 @@ import quarkusProjectListener from './QuarkusProjectListener';
import { terminalCommandRunner } from './terminal/terminalCommandRunner';
import { WelcomeWebview } from './webviews/WelcomeWebview';
import { createTerminateDebugListener } from './wizards/debugging/terminateProcess';
import { initTelemetryService } from './utils/telemetryUtils';

export async function activate(context: ExtensionContext) {

const telemetryService: TelemetryService = await getTelemetryService(VSCODE_QUARKUS_EXTENSION_NAME);
await telemetryService.sendStartupEvent();
await initTelemetryService(context);

QuarkusContext.setContext(context);
displayWelcomePageIfNeeded(context);
Expand Down
28 changes: 23 additions & 5 deletions src/utils/telemetryUtils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import { getTelemetryService, TelemetryService } from "@redhat-developer/vscode-redhat-telemetry/lib";
import { VSCODE_QUARKUS_EXTENSION_NAME } from "../definitions/constants";
import { getRedHatService, TelemetryService } from "@redhat-developer/vscode-redhat-telemetry/lib";
import { ExtensionContext } from "vscode";

const CMD_SUCCEED_VALUE = "succeeded";
const CMD_FAIL_VALUE = "failed";

let telemetryService: TelemetryService;
let isTelemetryInit = false;

export async function initTelemetryService(context: ExtensionContext): Promise<void> {
if (isTelemetryInit) {
throw new Error('Telemetry already initialized');
}
telemetryService = await (await getRedHatService(context)).getTelemetryService();
telemetryService.sendStartupEvent();
isTelemetryInit = true;
}

/**
* Sends a telemetry event indicating that the given command ran successfully
*
* @param commandName the command that was executed
* @throws if the telemetry service has not been initialized yet
* @returns when the telemetry event has been sent
*/
export async function sendCommandSucceededTelemetry(commandName: string): Promise<void> {
Expand All @@ -19,6 +32,7 @@ export async function sendCommandSucceededTelemetry(commandName: string): Promis
*
* @param commandName the command that was executed
* @param msg the error message
* @throws if the telemetry service has not been initialized yet
* @returns when the telemetry event has been sent
*/
export async function sendCommandFailedTelemetry(commandName: string, msg?: string): Promise<void> {
Expand All @@ -30,10 +44,14 @@ export async function sendCommandFailedTelemetry(commandName: string, msg?: stri
*
* @param commandName the name of the command that was run
* @param suffix the suffix to add to the command to get the event name
* @throws if the telemetry service has not been initialized yet
* @returns when the telemetry event has been sent
*/
async function sendCommandTelemetry(commandName: string, succeeded: boolean, msg?: string) {
const telemetryService: TelemetryService = await getTelemetryService(VSCODE_QUARKUS_EXTENSION_NAME);
telemetryService.send({
async function sendCommandTelemetry(commandName: string, succeeded: boolean, msg?: string): Promise<void> {
if (!isTelemetryInit) {
throw new Error('Telemetry has not been initialized yet');
}
await telemetryService.send({
name: commandName,
properties: {
status: succeeded ? CMD_SUCCEED_VALUE : CMD_FAIL_VALUE,
Expand Down

0 comments on commit 2636c37

Please sign in to comment.