Skip to content

Commit

Permalink
Update vscode-redhat-telemetry to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sudhirverma committed Jun 23, 2021
1 parent 0e5b03b commit d27660b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
15 changes: 8 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@
},
"dependencies": {
"@kubernetes/client-node": "^0.12.2",
"@redhat-developer/vscode-redhat-telemetry": "^0.1.1",
"@redhat-developer/vscode-redhat-telemetry": "^0.2.0",
"axios": "^0.21.1",
"binary-search": "^1.3.5",
"byline": "^5.0.0",
Expand Down
6 changes: 2 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ import { TriggerTemplate } from './tekton/triggertemplate';
import { TektonHubTasksViewProvider } from './hub/hub-view';
import { registerLogDocumentProvider } from './util/log-in-editor';
import { openTaskRunTemplate } from './tekton/taskruntemplate';
import sendTelemetry, { telemetryLogError, TelemetryProperties } from './telemetry';
import sendTelemetry, { startTelemetry, telemetryLogError, TelemetryProperties } from './telemetry';
import { cli, createCliCommand } from './cli';
import { getVersion, tektonVersionType } from './util/tknversion';
import { TektonNode } from './tree-view/tekton-node';
import { checkClusterStatus } from './util/check-cluster-status';
import { getRedHatService } from '@redhat-developer/vscode-redhat-telemetry';
import { getClusterVersions } from './cluster-version';

export let contextGlobalState: vscode.ExtensionContext;
Expand All @@ -48,8 +47,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>

contextGlobalState = context;
migrateFromTkn018();
const telemetry = await (await getRedHatService(context)).getTelemetryService();
telemetry.sendStartupEvent();
startTelemetry(context);

const hubViewProvider = new TektonHubTasksViewProvider(context.extensionUri);

Expand Down
25 changes: 14 additions & 11 deletions src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/

import { getTelemetryService, TelemetryEvent, TelemetryService } from '@redhat-developer/vscode-redhat-telemetry';
import { getRedHatService, TelemetryEvent, TelemetryService } from '@redhat-developer/vscode-redhat-telemetry';
import { ExtensionContext } from 'vscode';
import { hideClusterInfo } from './util/hideclusterinformation';
import { getStderrString } from './util/stderrstring';

let telemetryService: TelemetryService;

export interface TelemetryProperties {
identifier?: string;
version?: string;
Expand All @@ -17,7 +20,15 @@ export interface TelemetryProperties {
mission?: string;
}

const telemetryService: Promise<TelemetryService> = getTelemetryService('redhat.vscode-tekton-pipelines');
export async function startTelemetry(context: ExtensionContext): Promise<void> {
try {
const redHatService = await getRedHatService(context);
telemetryService = await redHatService.getTelemetryService();
} catch (error) {
console.log(`${error}`);
}
return telemetryService?.sendStartupEvent();
}

export function telemetryProperties(commandId: string): TelemetryProperties {
return {
Expand All @@ -34,10 +45,6 @@ export async function telemetryLogError(identifier: string, result: string | Err
}
}

export async function getTelemetryServiceInstance(): Promise<TelemetryService> {
return telemetryService;
}

export function createTrackingEvent(name: string, properties = {}): TelemetryEvent {
return {
type: 'track',
Expand All @@ -55,9 +62,5 @@ export function telemetryLog(identifier: string, message?: string): void {
}

export default async function sendTelemetry(actionName: string, properties?: TelemetryProperties): Promise<void> {
const service = await getTelemetryServiceInstance();
if (actionName === 'activation') {
return service?.sendStartupEvent();
}
return service?.send(createTrackingEvent(actionName, properties));
return telemetryService?.send(createTrackingEvent(actionName, properties));
}

0 comments on commit d27660b

Please sign in to comment.