From dbdd1745ee67e8ed05e3c648ebbfa4775f4b425e Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 12 Nov 2022 01:35:12 -0500 Subject: [PATCH] Captures global state for queued events --- src/telemetry/telemetry.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/telemetry/telemetry.ts b/src/telemetry/telemetry.ts index bd83238..434f3db 100644 --- a/src/telemetry/telemetry.ts +++ b/src/telemetry/telemetry.ts @@ -29,6 +29,7 @@ interface QueuedEvent { type: 'sendEvent'; name: string; data?: Record; + global: Map; startTime: TimeInput; endTime: TimeInput; } @@ -102,18 +103,19 @@ export class TelemetryService implements Disposable { container.debugging, ); - this.provider.setGlobalAttributes(this.globalAttributes); - if (this.eventQueue.length) { const queue = [...this.eventQueue]; this.eventQueue.length = 0; - for (const { type, name, data } of queue) { + for (const { type, name, data, global } of queue) { if (type === 'sendEvent') { + this.provider.setGlobalAttributes(global); this.provider.sendEvent(name, stripNullOrUndefinedAttributes(data)); } } } + + this.provider.setGlobalAttributes(this.globalAttributes); } sendEvent( @@ -122,13 +124,14 @@ export class TelemetryService implements Disposable { startTime?: TimeInput, endTime?: TimeInput, ): void { - if (!this.enabled) return; + if (!this._enabled) return; if (this.provider == null) { this.eventQueue.push({ type: 'sendEvent', name: name, data: data, + global: new Map([...this.globalAttributes]), startTime: startTime ?? Date.now(), endTime: endTime ?? Date.now(), });