From b6ff394ef8db7da8a23884383c1f1d36c58eda1e Mon Sep 17 00:00:00 2001 From: owent Date: Thu, 15 Aug 2024 23:10:54 +0800 Subject: [PATCH 1/2] Fix singal missing. --- .../periodic_exporting_metric_reader.cc | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc index 7ca2747337..cb2acf3c3c 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc @@ -106,19 +106,22 @@ bool PeriodicExportingMetricReader::CollectAndExportOnce() std::promise sender; auto receiver = sender.get_future(); - task_thread.reset(new std::thread([this, &cancel_export_for_timeout] { - this->Collect([this, &cancel_export_for_timeout](ResourceMetrics &metric_data) { - if (cancel_export_for_timeout.load(std::memory_order_acquire)) - { - OTEL_INTERNAL_LOG_ERROR( - "[Periodic Exporting Metric Reader] Collect took longer configured time: " - << this->export_timeout_millis_.count() << " ms, and timed out"); - return false; - } - this->exporter_->Export(metric_data); - return true; - }); - })); + task_thread.reset( + new std::thread([this, &cancel_export_for_timeout, sender = std::move(sender)] { + this->Collect([this, &cancel_export_for_timeout](ResourceMetrics &metric_data) { + if (cancel_export_for_timeout.load(std::memory_order_acquire)) + { + OTEL_INTERNAL_LOG_ERROR( + "[Periodic Exporting Metric Reader] Collect took longer configured time: " + << this->export_timeout_millis_.count() << " ms, and timed out"); + return false; + } + this->exporter_->Export(metric_data); + return true; + }); + + sender.set_value(); + })); std::future_status status; do From e388b553e472b93dd6cc6df9a94867c3d5a6b4f5 Mon Sep 17 00:00:00 2001 From: owent Date: Thu, 15 Aug 2024 23:49:27 +0800 Subject: [PATCH 2/2] Fix access --- sdk/src/metrics/export/periodic_exporting_metric_reader.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc index cb2acf3c3c..1ebfc2a1b6 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc @@ -120,7 +120,7 @@ bool PeriodicExportingMetricReader::CollectAndExportOnce() return true; }); - sender.set_value(); + const_cast &>(sender).set_value(); })); std::future_status status;