Skip to content

Commit

Permalink
Fix 1ds appender (microsoft#152198)
Browse files Browse the repository at this point in the history
  • Loading branch information
lramos15 authored Jun 15, 2022
1 parent 6bd36f5 commit 9232ebb
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/vs/platform/telemetry/node/1dsAppender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ async function getClient(instrumentationKey: string): Promise<AppInsightsCore> {

export class OneDataSystemAppender implements ITelemetryAppender {

private _aiCore: AppInsightsCore | undefined;
private _iKey: string | undefined;
private _aiCoreOrKey: AppInsightsCore | string | undefined;
private _asyncAiCore: Promise<AppInsightsCore> | null;

constructor(
Expand All @@ -93,29 +92,28 @@ export class OneDataSystemAppender implements ITelemetryAppender {
}

if (typeof iKeyOrClientFactory === 'function') {
this._aiCore = iKeyOrClientFactory();
this._aiCoreOrKey = iKeyOrClientFactory();
} else {
this._iKey = iKeyOrClientFactory;
this._aiCoreOrKey = iKeyOrClientFactory;
}
this._asyncAiCore = null;
}

private _withAIClient(callback: (aiCore: AppInsightsCore) => void): void {
if (!this._aiCore) {
if (!this._aiCoreOrKey) {
return;
}

if (this._aiCore) {
callback(this._aiCore);
if (typeof this._aiCoreOrKey !== 'string') {
callback(this._aiCoreOrKey);
return;
}

if (this._iKey && !this._asyncAiCore) {
this._asyncAiCore = getClient(this._iKey);
this._iKey = undefined;
if (!this._asyncAiCore) {
this._asyncAiCore = getClient(this._aiCoreOrKey);
}

this._asyncAiCore?.then(
this._asyncAiCore.then(
(aiClient) => {
callback(aiClient);
},
Expand All @@ -127,7 +125,7 @@ export class OneDataSystemAppender implements ITelemetryAppender {
}

log(eventName: string, data?: any): void {
if (!this._aiCore) {
if (!this._aiCoreOrKey) {
return;
}
data = mixin(data, this._defaultData);
Expand All @@ -144,11 +142,11 @@ export class OneDataSystemAppender implements ITelemetryAppender {
}

flush(): Promise<any> {
if (this._aiCore) {
if (this._aiCoreOrKey) {
return new Promise(resolve => {
this._withAIClient((aiClient) => {
aiClient.unload(true, () => {
this._aiCore = undefined;
this._aiCoreOrKey = undefined;
resolve(undefined);
});
});
Expand Down

0 comments on commit 9232ebb

Please sign in to comment.