From 0c61fc27b28da5c99b1bf8dd99db0c3e1fa5d6c4 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Thu, 19 Sep 2019 12:45:18 -0700 Subject: [PATCH] feat(exporter-jaeger): flush data before shutdown (#282) --- packages/opentelemetry-exporter-jaeger/src/jaeger.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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. */