From 5f211bc2a3136aedff98a00dabf74900dcedd1fd Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Tue, 26 Jul 2022 07:15:52 +0200 Subject: [PATCH] remove promise hack --- packages/otel-exporter-jaeger/src/index.ts | 18 +----------------- .../otel-exporter-trace-otlp-grpc/src/index.ts | 18 +----------------- .../otel-exporter-trace-otlp-http/src/index.ts | 18 +----------------- 3 files changed, 3 insertions(+), 51 deletions(-) diff --git a/packages/otel-exporter-jaeger/src/index.ts b/packages/otel-exporter-jaeger/src/index.ts index e54e015..9e9276b 100644 --- a/packages/otel-exporter-jaeger/src/index.ts +++ b/packages/otel-exporter-jaeger/src/index.ts @@ -38,23 +38,7 @@ export const makeJaegerTracingSpanExporter = M.gen(function* (_) { const spanExporter = yield* _( pipe( T.succeedWith(() => new JaegerExporter(config)), - M.make((p) => - // NOTE Unfortunately this workaround/"hack" is currently needed since Otel doesn't yet provide a graceful - // way to shutdown. - // - // Related issue: https://github.com/open-telemetry/opentelemetry-js/issues/987 - pipe( - T.sleep(2_000), - T.zipRight(T.promise(() => p.shutdown())), - T.zipRight( - T.effectAsync((cb) => { - p["_sender"]["_client"].once("close", () => { - cb(T.unit) - }) - }) - ) - ) - ) + M.make((p) => T.promise(() => p.shutdown())) ) ) diff --git a/packages/otel-exporter-trace-otlp-grpc/src/index.ts b/packages/otel-exporter-trace-otlp-grpc/src/index.ts index 49d181f..870687d 100644 --- a/packages/otel-exporter-trace-otlp-grpc/src/index.ts +++ b/packages/otel-exporter-trace-otlp-grpc/src/index.ts @@ -38,23 +38,7 @@ export const makeTracingSpanExporter = M.gen(function* (_) { const spanExporter = yield* _( pipe( T.succeedWith(() => new OTLPTraceExporter(config)), - // NOTE Unfortunately this workaround/"hack" is currently needed since Otel doesn't yet provide a graceful - // way to shutdown. - // - // Related issue: https://github.com/open-telemetry/opentelemetry-js/issues/987 - M.make((p) => - T.gen(function* (_) { - while (1) { - yield* _(T.sleep(0)) - const promises = p["_sendingPromises"] as any[] - if (promises.length > 0) { - yield* _(T.result(T.promise(() => Promise.all(promises)))) - } else { - break - } - } - }) - ) + M.make((p) => T.promise(() => p.shutdown())) ) ) diff --git a/packages/otel-exporter-trace-otlp-http/src/index.ts b/packages/otel-exporter-trace-otlp-http/src/index.ts index e289b0a..c73c5ec 100644 --- a/packages/otel-exporter-trace-otlp-http/src/index.ts +++ b/packages/otel-exporter-trace-otlp-http/src/index.ts @@ -38,23 +38,7 @@ export const makeTracingSpanExporter = M.gen(function* (_) { const spanExporter = yield* _( pipe( T.succeedWith(() => new OTLPTraceExporter(config)), - // NOTE Unfortunately this workaround/"hack" is currently needed since Otel doesn't yet provide a graceful - // way to shutdown. - // - // Related issue: https://github.com/open-telemetry/opentelemetry-js/issues/987 - M.make((p) => - T.gen(function* (_) { - while (1) { - yield* _(T.sleep(0)) - const promises = p["_sendingPromises"] as any[] - if (promises.length > 0) { - yield* _(T.result(T.promise(() => Promise.all(promises)))) - } else { - break - } - } - }) - ) + M.make((p) => T.promise(() => p.shutdown())) ) )