Skip to content

Commit

Permalink
Introduce 'sendRawTelemetryEvent'
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Oct 8, 2021
1 parent bb8286d commit 7d2d3e4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
14 changes: 14 additions & 0 deletions lib/telemetryReporter.d.ts
Expand Up @@ -5,6 +5,11 @@
export interface TelemetryEventProperties {
readonly [key: string]: string;
}

export interface TelemetryRawEventProperties {
readonly [key: string]: any;
}

export interface TelemetryEventMeasurements {
readonly [key: string]: number;
}
Expand All @@ -19,12 +24,21 @@ export default class TelemetryReporter {

/**
* Sends a telemetry event with the given properties and measurements
* Properties are sanitized on best-effort basis to remove sensitive data prior to sending.
* @param eventName The name of the event
* @param properties The set of properties to add to the event in the form of a string key value pair
* @param measurements The set of measurements to add to the event in the form of a string key number value pair
*/
sendTelemetryEvent(eventName: string, properties?: TelemetryEventProperties, measurements?: TelemetryEventMeasurements): void;

/**
* Sends a raw (unsanitized) telemetry event with the given properties and measurements
* @param eventName The name of the event
* @param properties The set of properties to add to the event in the form of a string key value pair
* @param measurements The set of measurements to add to the event in the form of a string key number value pair
*/
sendRawTelemetryEvent(eventName: string, properties?: TelemetryRawEventProperties, measurements?: TelemetryEventMeasurements): void;

/**
* Sends a telemetry error event with the given properties, measurements, and errorProps
* @param eventName The name of the event
Expand Down
20 changes: 17 additions & 3 deletions src/common/baseTelemetryReporter.ts
Expand Up @@ -3,11 +3,11 @@
*--------------------------------------------------------*/

import * as vscode from "vscode";
import type { TelemetryEventMeasurements, TelemetryEventProperties } from "../../lib/telemetryReporter";
import type { TelemetryEventMeasurements, TelemetryEventProperties, TelemetryRawEventProperties } from "../../lib/telemetryReporter";
import { getTelemetryLevel, TelemetryLevel } from "./util";

export interface AppenderData {
properties?: TelemetryEventProperties,
properties?: TelemetryRawEventProperties,
measurements?: TelemetryEventMeasurements
}
export interface ITelemetryAppender {
Expand Down Expand Up @@ -261,7 +261,8 @@ export class BaseTelemtryReporter {
}

/**
* Given an event name, some properties, and measurements sends a teleemtry event
* 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.
* @param eventName The name of the event
* @param properties The properties to send with the event
* @param measurements The measurements (numeric values) to send with the event
Expand All @@ -274,6 +275,19 @@ export class BaseTelemtryReporter {
}
}

/**
* Given an event name, some properties, and measurements sends a raw (unsanitized) telemetry event
* @param eventName The name of the event
* @param properties The properties to send with the event
* @param measurements The measurements (numeric values) to send with the event
*/
public sendRawTelemetryEvent(eventName: string, properties?: TelemetryRawEventProperties, measurements?: TelemetryEventMeasurements): void {
if (this.userOptIn && eventName !== "") {
properties = { ...properties, ...this.getCommonProperties() };
this.telemetryAppender.logEvent(`${this.extensionId}/${eventName}`, { properties: properties, measurements: measurements });
}
}

/**
* Given an event name, some properties, and measurements sends an error event
* @param eventName The name of the event
Expand Down

0 comments on commit 7d2d3e4

Please sign in to comment.