Skip to content

Commit ff39cb3

Browse files
committed
Implement #51
1 parent 1bd0f0c commit ff39cb3

File tree

4 files changed

+36
-33
lines changed

4 files changed

+36
-33
lines changed

lib/telemetryReporter.d.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1+
/*---------------------------------------------------------
2+
* Copyright (C) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------*/
4+
5+
export interface TelemetryEventProperties {
6+
readonly [key: string]: string;
7+
}
8+
export interface TelemetryEventMeasurements {
9+
readonly [key: string]: number;
10+
}
111
export default class TelemetryReporter {
2-
constructor(extensionId: string, extensionVersion: string, key: string, firstParty?: boolean);
3-
sendTelemetryEvent(eventName: string, properties?: {
4-
[key: string]: string;
5-
}, measurements?: {
6-
[key: string]: number;
7-
}): void;
8-
sendTelemetryErrorEvent(eventName: string, properties?: {
9-
[key: string]: string;
10-
}, measurements?: {
11-
[key: string]: number;
12-
}, errorProps?: string[]): void;
13-
sendTelemetryException(error: Error, properties?: {
14-
[key: string]: string;
15-
}, measurements?: {
16-
[key: string]: number;
17-
}): void;
18-
dispose(): Promise<any>;
12+
constructor(extensionId: string, extensionVersion: string, key: string, firstParty?: boolean);
13+
sendTelemetryEvent(eventName: string, properties?: TelemetryEventProperties, measurements?: TelemetryEventMeasurements): void;
14+
sendTelemetryErrorEvent(eventName: string, properties?: TelemetryEventProperties, measurements?: TelemetryEventMeasurements): void;
15+
sendTelemetryException(error: Error, properties?: TelemetryEventProperties, measurements?: TelemetryEventMeasurements): void;
16+
dispose(): Promise<any>;
1917
}

src/browser/telemetryReporter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import * as vscode from "vscode";
66
import { ApplicationInsights } from "@microsoft/applicationinsights-web";
7-
import { BaseTelemtryReporter, ITelemetryAppender } from "../common/baseTelemetryReporter";
7+
import { AppenderData, BaseTelemtryReporter, ITelemetryAppender } from "../common/baseTelemetryReporter";
88

99
class WebAppInsightsAppender implements ITelemetryAppender {
1010
private _aiClient: ApplicationInsights | undefined;
@@ -43,14 +43,14 @@ class WebAppInsightsAppender implements ITelemetryAppender {
4343
}
4444
}
4545

46-
public logEvent(eventName: string, data: any): void {
46+
public logEvent(eventName: string, data: AppenderData): void {
4747
if (!this._aiClient) {
4848
return;
4949
}
5050
this._aiClient.trackEvent({ name: eventName }, { ...data.properties, ...data.measurements });
5151
}
5252

53-
public logException(exception: Error, data: any): void {
53+
public logException(exception: Error, data: AppenderData): void {
5454
if (!this._aiClient) {
5555
return;
5656
}

src/common/baseTelemetryReporter.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
*--------------------------------------------------------*/
44

55
import * as vscode from "vscode";
6+
import type { TelemetryEventMeasurements, TelemetryEventProperties } from "../../lib/telemetryReporter";
67

8+
export interface AppenderData {
9+
properties?: TelemetryEventProperties,
10+
measurements?: TelemetryEventMeasurements
11+
}
712
export interface ITelemetryAppender {
8-
logEvent(eventName: string, data?: any): void;
9-
logException(exception: Error, data?: any): void;
13+
logEvent(eventName: string, data?: AppenderData): void;
14+
logException(exception: Error, data?: AppenderData): void;
1015
flush(): void | Promise<void>;
1116
}
1217

@@ -133,7 +138,7 @@ export class BaseTelemtryReporter {
133138
// __GDPR__COMMON__ "common.uikind" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
134139
// __GDPR__COMMON__ "common.remotename" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
135140
// __GDPR__COMMON__ "common.isnewappinstall" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
136-
private getCommonProperties(): { [key: string]: string } {
141+
private getCommonProperties(): TelemetryEventProperties {
137142
const commonProperties = Object.create(null);
138143
commonProperties["common.os"] = this.osShim.platform;
139144
commonProperties["common.platformversion"] = (this.osShim.release || "").replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, "$1$2$3");
@@ -221,7 +226,7 @@ export class BaseTelemtryReporter {
221226
return updatedStack;
222227
}
223228

224-
private removePropertiesWithPossibleUserInfo(properties: { [key: string]: string } | undefined): { [key: string]: string } | undefined {
229+
private removePropertiesWithPossibleUserInfo(properties: TelemetryEventProperties | undefined): TelemetryEventProperties | undefined {
225230
if (typeof properties !== "object") {
226231
return;
227232
}
@@ -257,7 +262,7 @@ export class BaseTelemtryReporter {
257262
* @param properties The properties to send with the event
258263
* @param measurements The measurements (numeric values) to send with the event
259264
*/
260-
public sendTelemetryEvent(eventName: string, properties?: { [key: string]: string }, measurements?: { [key: string]: number }): void {
265+
public sendTelemetryEvent(eventName: string, properties?: TelemetryEventProperties, measurements?: TelemetryEventMeasurements): void {
261266
if (this.userOptIn && eventName !== "") {
262267
properties = { ...properties, ...this.getCommonProperties() };
263268
const cleanProperties = this.cloneAndChange(properties, (_key: string, prop: string) => this.anonymizeFilePaths(prop, this.firstParty));
@@ -299,7 +304,7 @@ export class BaseTelemtryReporter {
299304
* @param properties The properties to send with the event
300305
* @param measurements The measurements (numeric values) to send with the event
301306
*/
302-
public sendTelemetryException(error: Error, properties?: { [key: string]: string }, measurements?: { [key: string]: number }): void {
307+
public sendTelemetryException(error: Error, properties?: TelemetryEventProperties, measurements?: TelemetryEventMeasurements): void {
303308
if (this.shouldSendErrorTelemetry() && this.userOptIn && error) {
304309
properties = { ...properties, ...this.getCommonProperties() };
305310
const cleanProperties = this.cloneAndChange(properties, (_key: string, prop: string) => this.anonymizeFilePaths(prop, this.firstParty));

src/node/telemetryReporter.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as os from "os";
66
import * as vscode from "vscode";
77
import * as appInsights from "applicationinsights";
8-
import { BaseTelemtryReporter, ITelemetryAppender } from "../common/baseTelemetryReporter";
8+
import { AppenderData, BaseTelemtryReporter, ITelemetryAppender } from "../common/baseTelemetryReporter";
99

1010
class AppInsightsAppender implements ITelemetryAppender {
1111

@@ -39,25 +39,25 @@ class AppInsightsAppender implements ITelemetryAppender {
3939
}
4040
}
4141

42-
logEvent(eventName: string, data?: any): void {
42+
logEvent(eventName: string, data?: AppenderData): void {
4343
if (!this._appInsightsClient) {
4444
return;
4545
}
4646
this._appInsightsClient.trackEvent({
4747
name: eventName,
48-
properties: data.properties,
49-
measurements: data.measurements
48+
properties: data?.properties,
49+
measurements: data?.measurements
5050
});
5151
}
5252

53-
logException(exception: Error, data?: any): void {
53+
logException(exception: Error, data?: AppenderData): void {
5454
if (!this._appInsightsClient) {
5555
return;
5656
}
5757
this._appInsightsClient.trackException({
5858
exception,
59-
properties: data.properties,
60-
measurements: data.measurements
59+
properties: data?.properties,
60+
measurements: data?.measurements
6161
});
6262
}
6363

0 commit comments

Comments
 (0)