From 9dbebb64cca9fec5c08e99c2626698cce4ac8b6b Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 5 Dec 2024 14:22:25 +0100 Subject: [PATCH] Fixes #3187 --- .../opentelemetry/exporters/memory/in_memory_span_exporter.h | 5 +++++ sdk/include/opentelemetry/sdk/logs/exporter.h | 2 +- sdk/include/opentelemetry/sdk/logs/logger_provider.h | 2 +- sdk/include/opentelemetry/sdk/metrics/meter_context.h | 2 +- sdk/include/opentelemetry/sdk/metrics/meter_provider.h | 2 +- sdk/include/opentelemetry/sdk/metrics/push_metric_exporter.h | 2 +- sdk/include/opentelemetry/sdk/trace/exporter.h | 4 ++-- sdk/include/opentelemetry/sdk/trace/processor.h | 4 ++-- sdk/include/opentelemetry/sdk/trace/tracer_provider.h | 2 +- sdk/src/logs/logger_provider.cc | 4 ++-- sdk/src/metrics/meter_context.cc | 5 ++--- sdk/src/metrics/meter_provider.cc | 4 ++-- sdk/src/trace/tracer_provider.cc | 4 ++-- 13 files changed, 23 insertions(+), 19 deletions(-) diff --git a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h index 6be83113ce..8d3918f907 100644 --- a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h +++ b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h @@ -75,6 +75,11 @@ class InMemorySpanExporter final : public opentelemetry::sdk::trace::SpanExporte return sdk::common::ExportResult::kSuccess; } + virtual bool ForceFlush(std::chrono::microseconds /* timeout */) noexcept override + { + return true; + } + /** * @param timeout an optional value containing the timeout of the exporter * note: passing custom timeout values is not currently supported for this exporter diff --git a/sdk/include/opentelemetry/sdk/logs/exporter.h b/sdk/include/opentelemetry/sdk/logs/exporter.h index 15e848f351..5e83fe4609 100644 --- a/sdk/include/opentelemetry/sdk/logs/exporter.h +++ b/sdk/include/opentelemetry/sdk/logs/exporter.h @@ -51,7 +51,7 @@ class OPENTELEMETRY_EXPORT LogRecordExporter * Force flush the log records pushed into this log exporter. */ virtual bool ForceFlush( - std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; + std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept = 0; /** * Marks the exporter as ShutDown and cleans up any resources as required. diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider.h b/sdk/include/opentelemetry/sdk/logs/logger_provider.h index dd2a52789d..b3e217e2e8 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider.h @@ -93,7 +93,7 @@ class OPENTELEMETRY_EXPORT LoggerProvider final : public opentelemetry::logs::Lo /** * Shutdown the log processor associated with this log provider. */ - bool Shutdown() noexcept; + bool Shutdown(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; /** * Force flush the log processor associated with this log provider. diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_context.h b/sdk/include/opentelemetry/sdk/metrics/meter_context.h index fe85fe04cc..8a19cd7466 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_context.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_context.h @@ -147,7 +147,7 @@ class MeterContext : public std::enable_shared_from_this /** * Shutdown the Collectors associated with this meter provider. */ - bool Shutdown() noexcept; + bool Shutdown(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; private: opentelemetry::sdk::resource::Resource resource_; diff --git a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h index c34f16e0a1..46b4efc93c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter_provider.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter_provider.h @@ -110,7 +110,7 @@ class OPENTELEMETRY_EXPORT MeterProvider final : public opentelemetry::metrics:: /** * Shutdown the meter provider. */ - bool Shutdown() noexcept; + bool Shutdown(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; /** * Force flush the meter provider. diff --git a/sdk/include/opentelemetry/sdk/metrics/push_metric_exporter.h b/sdk/include/opentelemetry/sdk/metrics/push_metric_exporter.h index 409a826ca9..9c5e6ad2b6 100644 --- a/sdk/include/opentelemetry/sdk/metrics/push_metric_exporter.h +++ b/sdk/include/opentelemetry/sdk/metrics/push_metric_exporter.h @@ -53,7 +53,7 @@ class PushMetricExporter * @return return the status of the operation. */ virtual bool Shutdown( - std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept = 0; + std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept = 0; }; } // namespace metrics } // namespace sdk diff --git a/sdk/include/opentelemetry/sdk/trace/exporter.h b/sdk/include/opentelemetry/sdk/trace/exporter.h index 8f207e89f2..ab3b39da9f 100644 --- a/sdk/include/opentelemetry/sdk/trace/exporter.h +++ b/sdk/include/opentelemetry/sdk/trace/exporter.h @@ -48,12 +48,12 @@ class OPENTELEMETRY_EXPORT SpanExporter /** * Export all spans that have been exported. - * @param timeout an optional timeout, the default timeout of 0 means that no + * @param timeout an optional timeout, the default timeout means that no * timeout is applied. * @return return true when all data are exported, and false when timeout */ virtual bool ForceFlush( - std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; + std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept = 0; /** * Shut down the exporter. diff --git a/sdk/include/opentelemetry/sdk/trace/processor.h b/sdk/include/opentelemetry/sdk/trace/processor.h index 3701422eb5..951c2ec6b3 100644 --- a/sdk/include/opentelemetry/sdk/trace/processor.h +++ b/sdk/include/opentelemetry/sdk/trace/processor.h @@ -56,7 +56,7 @@ class OPENTELEMETRY_EXPORT SpanProcessor /** * Export all ended spans that have not yet been exported. - * @param timeout an optional timeout, the default timeout of 0 means that no + * @param timeout an optional timeout, the default timeout means that no * timeout is applied. */ virtual bool ForceFlush( @@ -67,7 +67,7 @@ class OPENTELEMETRY_EXPORT SpanProcessor * exported before shutdown. After the call to Shutdown, subsequent calls to * OnStart, OnEnd, ForceFlush or Shutdown will return immediately without * doing anything. - * @param timeout an optional timeout, the default timeout of 0 means that no + * @param timeout an optional timeout, the default timeout means that no * timeout is applied. */ virtual bool Shutdown( diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index 44d5840558..250a948a96 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -101,7 +101,7 @@ class OPENTELEMETRY_EXPORT TracerProvider final : public opentelemetry::trace::T /** * Shutdown the span processor associated with this tracer provider. */ - bool Shutdown() noexcept; + bool Shutdown(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; /** * Force flush the span processor associated with this tracer provider. diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 46bf1ade33..14febdf721 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -118,9 +118,9 @@ const opentelemetry::sdk::resource::Resource &LoggerProvider::GetResource() cons return context_->GetResource(); } -bool LoggerProvider::Shutdown() noexcept +bool LoggerProvider::Shutdown(std::chrono::microseconds timeout) noexcept { - return context_->Shutdown(); + return context_->Shutdown(timeout); } bool LoggerProvider::ForceFlush(std::chrono::microseconds timeout) noexcept diff --git a/sdk/src/metrics/meter_context.cc b/sdk/src/metrics/meter_context.cc index 15e689706a..31dd1af8b1 100644 --- a/sdk/src/metrics/meter_context.cc +++ b/sdk/src/metrics/meter_context.cc @@ -138,16 +138,15 @@ void MeterContext::RemoveMeter(nostd::string_view name, meters_.swap(filtered_meters); } -bool MeterContext::Shutdown() noexcept +bool MeterContext::Shutdown(std::chrono::microseconds timeout) noexcept { bool result = true; // Shutdown only once. if (!shutdown_latch_.test_and_set(std::memory_order_acquire)) { - for (auto &collector : collectors_) { - bool status = std::static_pointer_cast(collector)->Shutdown(); + bool status = std::static_pointer_cast(collector)->Shutdown(timeout); result = result && status; } if (!result) diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 4f2ca4b44f..1c70fc2ed3 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -132,9 +132,9 @@ void MeterProvider::SetExemplarFilter(metrics::ExemplarFilterType exemplar_filte /** * Shutdown the meter provider. */ -bool MeterProvider::Shutdown() noexcept +bool MeterProvider::Shutdown(std::chrono::microseconds timeout) noexcept { - return context_->Shutdown(); + return context_->Shutdown(timeout); } /** diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index 3b5462a083..346178f2a2 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -125,9 +125,9 @@ const resource::Resource &TracerProvider::GetResource() const noexcept return context_->GetResource(); } -bool TracerProvider::Shutdown() noexcept +bool TracerProvider::Shutdown(std::chrono::microseconds timeout) noexcept { - return context_->Shutdown(); + return context_->Shutdown(timeout); } bool TracerProvider::ForceFlush(std::chrono::microseconds timeout) noexcept