Skip to content

Commit 366ec1c

Browse files
committed
Cleanup some unneccesary code
1 parent 0cb3115 commit 366ec1c

File tree

2 files changed

+20
-44
lines changed

2 files changed

+20
-44
lines changed

src/common/baseTelemetryAppender.ts

+17-41
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ export interface BaseTelemetryClient {
1313

1414
export interface ITelemetryAppender {
1515
logEvent(eventName: string, data?: AppenderData): void;
16-
logEventDangerously(eventName: string, data?: AppenderData): void;
1716
logException(exception: Error, data?: AppenderData): void;
18-
logExceptionDangerously(exception: Error, data?: AppenderData): void;
1917
flush(): void | Promise<void>;
2018
instantiateAppender(): void;
2119
}
2220

21+
enum InstantiationStatus {
22+
NOT_INSTANTIATED,
23+
INSTANTIATING,
24+
INSTANTIATED,
25+
}
26+
2327
export class BaseTelemetryAppender implements ITelemetryAppender {
2428
// Whether or not the client has been instantiated
25-
private _isInstantiated = false;
29+
private _instantiationStatus: InstantiationStatus = InstantiationStatus.NOT_INSTANTIATED;
2630
private _telemetryClient: BaseTelemetryClient | undefined;
2731

2832
// Queues used to store events until the appender is ready
@@ -43,61 +47,29 @@ export class BaseTelemetryAppender implements ITelemetryAppender {
4347

4448
/**
4549
* Sends the event to the passed in telemetry client
50+
* The appender does no telemetry level checks as those are done by the reporter.
4651
* @param eventName The name of the event to log
4752
* @param data The data contanied in the event
4853
*/
4954
logEvent(eventName: string, data?: AppenderData): void {
5055
if (!this._telemetryClient) {
51-
if (!this._isInstantiated && getTelemetryLevel() === TelemetryLevel.ON) {
56+
if (this._instantiationStatus !== InstantiationStatus.INSTANTIATED) {
5257
this._eventQueue.push({ eventName, data });
5358
}
5459
return;
5560
}
5661
this._telemetryClient.logEvent(eventName, data);
5762
}
5863

59-
/**
60-
* **DANGEROUS**: Logs an event regardless of telemetry level.
61-
* This should only be used in controlled environments i.e. CI pipelines
62-
* @param eventName The named of the event to log
63-
* @param data The data contained in the event
64-
*/
65-
logEventDangerously(eventName: string, data?: AppenderData): void {
66-
if (!this._telemetryClient) {
67-
return;
68-
}
69-
if (!this._isInstantiated) {
70-
this._eventQueue.push({ eventName, data });
71-
} else {
72-
this._telemetryClient.logEvent(eventName, data);
73-
}
74-
}
75-
76-
/**
77-
* **DANGEROUS**: Logs an exception regardless of telemetry level.
78-
* This should only be used in controlled environments i.e. CI pipelines
79-
* @param exception The exception to log
80-
* @param data The data associated with the exception
81-
*/
82-
logExceptionDangerously(exception: Error, data?: AppenderData): void {
83-
if (!this._telemetryClient) {
84-
return;
85-
}
86-
if (!this._isInstantiated) {
87-
this._exceptionQueue.push({ exception, data });
88-
} else {
89-
this._telemetryClient.logException(exception, data);
90-
}
91-
}
92-
9364
/**
9465
* Sends an exception to the passed in telemetry client
66+
* The appender does no telemetry level checks as those are done by the reporter.
9567
* @param exception The exception to collect
9668
* @param data Data associated with the exception
9769
*/
9870
logException(exception: Error, data?: AppenderData): void {
9971
if (!this._telemetryClient) {
100-
if (!this._isInstantiated && getTelemetryLevel() !== TelemetryLevel.OFF) {
72+
if (this._instantiationStatus !== InstantiationStatus.INSTANTIATED) {
10173
this._exceptionQueue.push({ exception, data });
10274
}
10375
return;
@@ -130,16 +102,20 @@ export class BaseTelemetryAppender implements ITelemetryAppender {
130102
* Instantiates the telemetry client to make the appender "active"
131103
*/
132104
instantiateAppender(): void {
133-
if (this._isInstantiated) {
105+
if (this._instantiationStatus !== InstantiationStatus.NOT_INSTANTIATED) {
134106
return;
135107
}
108+
this._instantiationStatus = InstantiationStatus.INSTANTIATING;
136109
// Call the client factory to get the client and then let it know it's instatntiated
137110
this._clientFactory(this._key).then(client => {
138111
this._telemetryClient = client;
139-
this._isInstantiated = true;
112+
this._instantiationStatus = InstantiationStatus.INSTANTIATED;
140113
this._flushQueues();
141114
}).catch(err => {
142115
console.error(err);
116+
// If it failed to instntiate, then we don't want to try again.
117+
// So we mark it as instantiated. See #94
118+
this._instantiationStatus = InstantiationStatus.INSTANTIATED;
143119
});
144120
}
145121
}

src/common/baseTelemetryReporter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export class BaseTelemetryReporter {
304304
properties = this.removePropertiesWithPossibleUserInfo(cleanProperties);
305305
}
306306
eventName = `${this.extensionId}/${eventName}`;
307-
dangerous ? this.telemetryAppender.logEventDangerously(eventName, { properties, measurements }) : this.telemetryAppender.logEvent(eventName, { properties, measurements });
307+
this.telemetryAppender.logEvent(eventName, { properties, measurements });
308308
}
309309
}
310310

@@ -377,7 +377,7 @@ export class BaseTelemetryReporter {
377377
});
378378
properties = this.removePropertiesWithPossibleUserInfo(cleanProperties);
379379
}
380-
dangerous ? this.telemetryAppender.logEventDangerously(eventName, { properties, measurements }) : this.telemetryAppender.logEvent(eventName, { properties, measurements });
380+
this.telemetryAppender.logEvent(eventName, { properties, measurements });
381381
}
382382
}
383383

@@ -432,7 +432,7 @@ export class BaseTelemetryReporter {
432432
}
433433
properties = this.removePropertiesWithPossibleUserInfo(cleanProperties);
434434
}
435-
dangerous ? this.telemetryAppender.logExceptionDangerously(error, { properties, measurements }) : this.telemetryAppender.logException(error, { properties, measurements });
435+
this.telemetryAppender.logException(error, { properties, measurements });
436436
}
437437
}
438438

0 commit comments

Comments
 (0)