Skip to content

Commit

Permalink
Add telemetry level string
Browse files Browse the repository at this point in the history
  • Loading branch information
lramos15 committed Jan 31, 2022
1 parent 85b6f1d commit e78f7b3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/telemetryReporter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export default class TelemetryReporter {
*/
constructor(extensionId: string, extensionVersion: string, key: string, firstParty?: boolean);

/**
* A string representation of the current level of telemetry being collected
*/
telemetryLevel: 'all' | 'error' | 'crash' | 'off';

/**
* Sends a telemetry event with the given properties and measurements
* Properties are sanitized on best-effort basis to remove sensitive data prior to sending.
Expand Down Expand Up @@ -55,5 +60,9 @@ export default class TelemetryReporter {
* @param measurements The set of measurements to add to the event in the form of a string key number value pair
*/
sendTelemetryException(error: Error, properties?: TelemetryEventProperties, measurements?: TelemetryEventMeasurements): void;

/**
* Disposes of the telemetry reporter. This flushes the remaining events and disposes of the telemetry client.
*/
dispose(): Promise<any>;
}
12 changes: 12 additions & 0 deletions src/common/baseTelemetryReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ export class BaseTelemetryReporter {
return cleanedObject;
}

public get telemetryLevel(): "all" | "error" | "crash" | "off" {
const telemetryLevel = getTelemetryLevel();
switch (telemetryLevel) {
case TelemetryLevel.ON:
return "all";
case TelemetryLevel.ERROR:
return "error";
case TelemetryLevel.OFF:
return "off";
}
}

/**
* Given an event name, some properties, and measurements sends a telemetry event.
* Properties are sanitized on best-effort basis to remove sensitive data prior to sending.
Expand Down
4 changes: 2 additions & 2 deletions src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export function getTelemetryLevel(): TelemetryLevel {

try {
const telemetryConfiguration = vscode.env.telemetryConfiguration;
if (telemetryConfiguration.isUsageEnabled) {
if (telemetryConfiguration.isUsageEnabled && telemetryConfiguration.isErrorsEnabled && telemetryConfiguration.isCrashEnabled) {
return TelemetryLevel.ON;
} else if (telemetryConfiguration.isErrorsEnabled) {
} else if (telemetryConfiguration.isErrorsEnabled && telemetryConfiguration.isCrashEnabled) {
return TelemetryLevel.ERROR;
} else {
return TelemetryLevel.OFF;
Expand Down

0 comments on commit e78f7b3

Please sign in to comment.