diff --git a/packages/opentelemetry-exporter-jaeger/src/jaeger.ts b/packages/opentelemetry-exporter-jaeger/src/jaeger.ts index 55b28ba23ed..f6977c07f68 100644 --- a/packages/opentelemetry-exporter-jaeger/src/jaeger.ts +++ b/packages/opentelemetry-exporter-jaeger/src/jaeger.ts @@ -55,7 +55,15 @@ export class JaegerExporter implements SpanExporter { /** Shutdown exporter. */ shutdown(): void { - this._sender.close(); + this._sender.flush((numSpans: number, err?: string) => { + if (err) { + this._logger.error(`failed to flush span: ${err}`); + } + }); + // Sleeping 2 seconds before closing the sender's connection to ensure all spans are flushed. + setTimeout(() => { + this._sender.close(); + }, 2000); } /** Transform spans and sends to Jaeger service. */