Skip to content

Commit b983dcf

Browse files
committed
fix(@opentelemetry/exporter-collector): remove fulfilled promises correctly
1 parent a2304c9 commit b983dcf

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/opentelemetry-exporter-collector/src/platform/browser/CollectorExporterBrowserBase.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,14 @@ export abstract class CollectorExporterBrowserBase<
6868
const serviceRequest = this.convert(items);
6969
const body = JSON.stringify(serviceRequest);
7070

71-
const promise = new Promise(resolve => {
71+
const promise = new Promise<void>(resolve => {
7272
const _onSuccess = (): void => {
7373
onSuccess();
74-
_onFinish();
74+
resolve();
7575
};
7676
const _onError = (error: collectorTypes.CollectorExporterError): void => {
7777
onError(error);
78-
_onFinish();
79-
};
80-
const _onFinish = () => {
8178
resolve();
82-
const index = this._sendingPromises.indexOf(promise);
83-
this._sendingPromises.splice(index, 1);
8479
};
8580

8681
if (this._useXHR) {
@@ -97,5 +92,10 @@ export abstract class CollectorExporterBrowserBase<
9792
}
9893
});
9994
this._sendingPromises.push(promise);
95+
const _onFinish = () => {
96+
const index = this._sendingPromises.indexOf(promise);
97+
this._sendingPromises.splice(index, 1);
98+
};
99+
promise.then(_onFinish);
100100
}
101101
}

packages/opentelemetry-exporter-collector/src/platform/node/CollectorExporterNodeBase.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export abstract class CollectorExporterNodeBase<
4040
httpAgentOptions: http.AgentOptions | https.AgentOptions = {};
4141
constructor(config: CollectorExporterNodeConfigBase = {}) {
4242
super(config);
43-
if ((config as any).metadata) {
43+
if ('metadata' in config) {
4444
this.logger.warn('Metadata cannot be set when using http');
4545
}
4646
this.headers =

0 commit comments

Comments
 (0)