From 2cd0fb4eae913594a89d261dc8a7b077992f90b3 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 7 Jan 2025 12:17:02 +0100 Subject: [PATCH] Implement CMake WITH_THREAD_INSTRUMENTATION_PREVIEW flag. --- CHANGELOG.md | 6 ++++++ CMakeLists.txt | 4 ++++ api/CMakeLists.txt | 5 +++++ ci/do_ci.sh | 4 ++++ examples/otlp/http_instrumented_main.cc | 18 +++++++++++++++++- exporters/otlp/src/otlp_file_client.cc | 8 ++++++++ ext/src/http/client/curl/http_client_curl.cc | 8 ++++++++ .../sdk/common/thread_instrumentation.h | 5 +++++ sdk/src/logs/batch_log_record_processor.cc | 12 ++++++++++++ .../export/periodic_exporting_metric_reader.cc | 16 ++++++++++++++++ sdk/src/trace/batch_span_processor.cc | 12 ++++++++++++ 11 files changed, 97 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7e30353a9..089a9541a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,12 @@ New features: shows how to use the feature, and add application logic in the thread execution code path. + * Note that this feature is experimental, + protected by a WITH_THREAD_INSTRUMENTATION_PREVIEW + flag in CMake. Various runtime options structures, + as well as the thread instrumentation interface, + may change without notice before this feature is declared stable. + ## [1.18 2024-11-25] * [EXPORTER] Fix crash in ElasticsearchLogRecordExporter diff --git a/CMakeLists.txt b/CMakeLists.txt index 408ee43046..8c0f4d4a18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,6 +300,10 @@ option(WITH_ASYNC_EXPORT_PREVIEW "Whether to enable async export" OFF) option(WITH_METRICS_EXEMPLAR_PREVIEW "Whether to enable exemplar within metrics" OFF) +# Experimental, so behind feature flag by default +option(WITH_THREAD_INSTRUMENTATION_PREVIEW + "Whether to enable thread instrumentation" OFF) + option(OPENTELEMETRY_SKIP_DYNAMIC_LOADING_TESTS "Whether to build test libraries that are always linked as shared libs" OFF) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 78e97ad029..b3c97808f6 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -126,6 +126,11 @@ if(WITH_METRICS_EXEMPLAR_PREVIEW) INTERFACE ENABLE_METRICS_EXEMPLAR_PREVIEW) endif() +if(WITH_THREAD_INSTRUMENTATION_PREVIEW) + target_compile_definitions(opentelemetry_api + INTERFACE ENABLE_THREAD_INSTRUMENTATION_PREVIEW) +endif() + if(WITH_OTLP_HTTP_COMPRESSION) target_compile_definitions(opentelemetry_api INTERFACE ENABLE_OTLP_COMPRESSION_PREVIEW) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 11dbe4ef80..1e5dd59899 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -131,6 +131,7 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then -DOTELCPP_MAINTAINER_MODE=ON \ -DWITH_NO_DEPRECATED_CODE=ON \ -DWITH_OTLP_HTTP_COMPRESSION=ON \ + -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \ ${IWYU} \ "${SRC_DIR}" eval "$MAKE_COMMAND" @@ -153,6 +154,7 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then -DOTELCPP_MAINTAINER_MODE=ON \ -DWITH_NO_DEPRECATED_CODE=ON \ -DWITH_OTLP_HTTP_COMPRESSION=ON \ + -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \ ${IWYU} \ "${SRC_DIR}" eval "$MAKE_COMMAND" @@ -176,6 +178,7 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then -DOTELCPP_MAINTAINER_MODE=ON \ -DWITH_NO_DEPRECATED_CODE=ON \ -DWITH_OTLP_HTTP_COMPRESSION=ON \ + -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \ "${SRC_DIR}" make -k -j $(nproc) make test @@ -199,6 +202,7 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then -DWITH_ABI_VERSION_1=OFF \ -DWITH_ABI_VERSION_2=ON \ -DWITH_OTLP_HTTP_COMPRESSION=ON \ + -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \ ${IWYU} \ "${SRC_DIR}" eval "$MAKE_COMMAND" diff --git a/examples/otlp/http_instrumented_main.cc b/examples/otlp/http_instrumented_main.cc index 38f8850360..c156fc9e71 100644 --- a/examples/otlp/http_instrumented_main.cc +++ b/examples/otlp/http_instrumented_main.cc @@ -58,6 +58,8 @@ namespace std::mutex serialize; +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW + /** The purpose of MyThreadInstrumentation is to demonstrate how notifications are delivered to the application. @@ -143,6 +145,8 @@ class MyThreadInstrumentation : public opentelemetry::sdk::common::ThreadInstrum std::string priority_; }; +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ + opentelemetry::exporter::otlp::OtlpHttpExporterOptions tracer_opts; opentelemetry::exporter::otlp::OtlpHttpMetricExporterOptions meter_opts; opentelemetry::exporter::otlp::OtlpHttpLogRecordExporterOptions logger_opts; @@ -155,19 +159,23 @@ void InitTracer() { // Create OTLP exporter instance opentelemetry::exporter::otlp::OtlpHttpExporterRuntimeOptions exp_rt_opts; +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW auto exp_instr = std::shared_ptr( new MyThreadInstrumentation("OtlpHttpExporter", "trace-net", "high")); exp_rt_opts.thread_instrumentation = exp_instr; +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ auto exporter = opentelemetry::exporter::otlp::OtlpHttpExporterFactory::Create(tracer_opts, exp_rt_opts); // Create Processor instance opentelemetry::sdk::trace::BatchSpanProcessorOptions pro_opts; opentelemetry::sdk::trace::BatchSpanProcessorRuntimeOptions pro_rt_opts; +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW auto pro_instr = std::shared_ptr( new MyThreadInstrumentation("BatchSpanProcessor", "", "high")); pro_rt_opts.thread_instrumentation = pro_instr; - auto processor = opentelemetry::sdk::trace::BatchSpanProcessorFactory::Create( +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ + auto processor = opentelemetry::sdk::trace::BatchSpanProcessorFactory::Create( std::move(exporter), pro_opts, pro_rt_opts); // Create Provider instance @@ -196,9 +204,11 @@ void InitMetrics() { // Create OTLP exporter instance opentelemetry::exporter::otlp::OtlpHttpMetricExporterRuntimeOptions exp_rt_opts; +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW auto exp_instr = std::shared_ptr( new MyThreadInstrumentation("OtlpHttpMetricExporter", "metric-net", "medium")); exp_rt_opts.thread_instrumentation = exp_instr; +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ auto exporter = opentelemetry::exporter::otlp::OtlpHttpMetricExporterFactory::Create(meter_opts, exp_rt_opts); @@ -211,12 +221,14 @@ void InitMetrics() reader_options.export_timeout_millis = std::chrono::milliseconds(500); opentelemetry::sdk::metrics::PeriodicExportingMetricReaderRuntimeOptions reader_rt_opts; +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW auto reader_periodic_instr = std::shared_ptr( new MyThreadInstrumentation("PeriodicExportingMetricReader(periodic)", "", "medium")); auto reader_collect_instr = std::shared_ptr( new MyThreadInstrumentation("PeriodicExportingMetricReader(collect)", "", "medium")); reader_rt_opts.periodic_thread_instrumentation = reader_periodic_instr; reader_rt_opts.collect_thread_instrumentation = reader_collect_instr; +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ auto reader = opentelemetry::sdk::metrics::PeriodicExportingMetricReaderFactory::Create( std::move(exporter), reader_options, reader_rt_opts); @@ -247,18 +259,22 @@ void InitLogger() { // Create OTLP exporter instance opentelemetry::exporter::otlp::OtlpHttpLogRecordExporterRuntimeOptions exp_rt_opts; +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW auto exp_instr = std::shared_ptr( new MyThreadInstrumentation("OtlpHttpLogRecordExporter", "log-net", "low")); exp_rt_opts.thread_instrumentation = exp_instr; +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ auto exporter = opentelemetry::exporter::otlp::OtlpHttpLogRecordExporterFactory::Create( logger_opts, exp_rt_opts); // Create Processor instance opentelemetry::sdk::logs::BatchLogRecordProcessorOptions pro_opts; opentelemetry::sdk::logs::BatchLogRecordProcessorRuntimeOptions pro_rt_opts; +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW auto pro_instr = std::shared_ptr( new MyThreadInstrumentation("BatchLogRecordProcessor", "", "low")); pro_rt_opts.thread_instrumentation = pro_instr; +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ auto processor = opentelemetry::sdk::logs::BatchLogRecordProcessorFactory::Create( std::move(exporter), pro_opts, pro_rt_opts); diff --git a/exporters/otlp/src/otlp_file_client.cc b/exporters/otlp/src/otlp_file_client.cc index d299ad9af0..e59cbb04be 100644 --- a/exporters/otlp/src/otlp_file_client.cc +++ b/exporters/otlp/src/otlp_file_client.cc @@ -1453,10 +1453,12 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender std::chrono::system_clock::now(); std::size_t last_record_count = 0; +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (thread_instrumentation != nullptr) { thread_instrumentation->OnStart(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ while (true) { @@ -1472,20 +1474,24 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender break; } +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (thread_instrumentation != nullptr) { thread_instrumentation->BeforeWait(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ { std::unique_lock lk(concurrency_file->background_thread_waker_lock); concurrency_file->background_thread_waker_cv.wait_for(lk, flush_interval); } +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (thread_instrumentation != nullptr) { thread_instrumentation->AfterWait(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ { std::size_t current_record_count = @@ -1516,10 +1522,12 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender background_flush_thread.swap(concurrency_file->background_flush_thread); } +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (thread_instrumentation != nullptr) { thread_instrumentation->OnEnd(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ if (background_flush_thread && background_flush_thread->joinable()) { diff --git a/ext/src/http/client/curl/http_client_curl.cc b/ext/src/http/client/curl/http_client_curl.cc index 527d66af11..9b61e44aba 100644 --- a/ext/src/http/client/curl/http_client_curl.cc +++ b/ext/src/http/client/curl/http_client_curl.cc @@ -441,10 +441,12 @@ bool HttpClient::MaybeSpawnBackgroundThread() background_thread_.reset(new std::thread( [](HttpClient *self) { +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (self->background_thread_instrumentation_ != nullptr) { self->background_thread_instrumentation_->OnStart(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ int still_running = 1; std::chrono::system_clock::time_point last_free_job_timepoint = @@ -464,10 +466,12 @@ bool HttpClient::MaybeSpawnBackgroundThread() } else if (still_running || need_wait_more) { +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (self->background_thread_instrumentation_ != nullptr) { self->background_thread_instrumentation_->BeforeWait(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ // curl_multi_poll is added from libcurl 7.66.0, before 7.68.0, we can only wait util // timeout to do the rest jobs @@ -482,10 +486,12 @@ bool HttpClient::MaybeSpawnBackgroundThread() nullptr); #endif +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (self->background_thread_instrumentation_ != nullptr) { self->background_thread_instrumentation_->AfterWait(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ } do @@ -584,10 +590,12 @@ bool HttpClient::MaybeSpawnBackgroundThread() // If there is no pending jobs, we can stop the background thread. if (still_running == 0) { +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (self->background_thread_instrumentation_ != nullptr) { self->background_thread_instrumentation_->OnEnd(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ if (self->background_thread_) { diff --git a/sdk/include/opentelemetry/sdk/common/thread_instrumentation.h b/sdk/include/opentelemetry/sdk/common/thread_instrumentation.h index 1db45a478f..7886af71b5 100644 --- a/sdk/include/opentelemetry/sdk/common/thread_instrumentation.h +++ b/sdk/include/opentelemetry/sdk/common/thread_instrumentation.h @@ -74,12 +74,17 @@ class ThreadInstrumentation ThreadInstrumentation() = default; virtual ~ThreadInstrumentation() = default; +/* + * This feature is experimental, protected by a _PREVIEW flag. + */ +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW virtual void OnStart() {} virtual void OnEnd() {} virtual void BeforeWait() {} virtual void AfterWait() {} virtual void BeforeLoad() {} virtual void AfterLoad() {} +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ }; } // namespace common diff --git a/sdk/src/logs/batch_log_record_processor.cc b/sdk/src/logs/batch_log_record_processor.cc index e5cc700317..ed7f1a86d9 100644 --- a/sdk/src/logs/batch_log_record_processor.cc +++ b/sdk/src/logs/batch_log_record_processor.cc @@ -178,19 +178,23 @@ bool BatchLogRecordProcessor::ForceFlush(std::chrono::microseconds timeout) noex void BatchLogRecordProcessor::DoBackgroundWork() { +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->OnStart(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ auto timeout = scheduled_delay_millis_; while (true) { +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->BeforeWait(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ // Wait for `timeout` milliseconds std::unique_lock lk(synchronization_data_->cv_m); @@ -205,10 +209,12 @@ void BatchLogRecordProcessor::DoBackgroundWork() synchronization_data_->is_force_wakeup_background_worker.store(false, std::memory_order_release); +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->AfterWait(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ if (synchronization_data_->is_shutdown.load() == true) { @@ -225,18 +231,22 @@ void BatchLogRecordProcessor::DoBackgroundWork() timeout = scheduled_delay_millis_ - duration; } +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->OnEnd(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ } void BatchLogRecordProcessor::Export() { +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->BeforeLoad(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ do { @@ -277,10 +287,12 @@ void BatchLogRecordProcessor::Export() NotifyCompletion(notify_force_flush, exporter_, synchronization_data_); } while (true); +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->AfterLoad(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ } void BatchLogRecordProcessor::NotifyCompletion( diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc index 21ef276c8c..1bb9101618 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc @@ -91,26 +91,32 @@ void PeriodicExportingMetricReader::OnInitialized() noexcept void PeriodicExportingMetricReader::DoBackgroundWork() { +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->OnStart(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ do { auto start = std::chrono::steady_clock::now(); +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->BeforeLoad(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ auto status = CollectAndExportOnce(); +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->AfterLoad(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ if (!status) { @@ -121,10 +127,12 @@ void PeriodicExportingMetricReader::DoBackgroundWork() auto export_time_ms = std::chrono::duration_cast(end - start); auto remaining_wait_interval_ms = export_interval_millis_ - export_time_ms; +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->BeforeWait(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ std::unique_lock lk(cv_m_); cv_.wait_for(lk, remaining_wait_interval_ms, [this]() { @@ -136,17 +144,21 @@ void PeriodicExportingMetricReader::DoBackgroundWork() return IsShutdown(); }); +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->AfterWait(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ } while (IsShutdown() != true); +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->OnEnd(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ } bool PeriodicExportingMetricReader::CollectAndExportOnce() @@ -165,11 +177,13 @@ bool PeriodicExportingMetricReader::CollectAndExportOnce() task_thread.reset( new std::thread([this, &cancel_export_for_timeout, sender = std::move(sender)] { +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (collect_thread_instrumentation_ != nullptr) { collect_thread_instrumentation_->OnStart(); collect_thread_instrumentation_->BeforeLoad(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ this->Collect([this, &cancel_export_for_timeout](ResourceMetrics &metric_data) { if (cancel_export_for_timeout.load(std::memory_order_acquire)) @@ -185,11 +199,13 @@ bool PeriodicExportingMetricReader::CollectAndExportOnce() const_cast &>(sender).set_value(); +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (collect_thread_instrumentation_ != nullptr) { collect_thread_instrumentation_->AfterLoad(); collect_thread_instrumentation_->OnEnd(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ })); std::future_status status; diff --git a/sdk/src/trace/batch_span_processor.cc b/sdk/src/trace/batch_span_processor.cc index 1ab8173944..614de89818 100644 --- a/sdk/src/trace/batch_span_processor.cc +++ b/sdk/src/trace/batch_span_processor.cc @@ -171,19 +171,23 @@ bool BatchSpanProcessor::ForceFlush(std::chrono::microseconds timeout) noexcept void BatchSpanProcessor::DoBackgroundWork() { +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->OnStart(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ auto timeout = schedule_delay_millis_; while (true) { +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->BeforeWait(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ // Wait for `timeout` milliseconds std::unique_lock lk(synchronization_data_->cv_m); @@ -198,10 +202,12 @@ void BatchSpanProcessor::DoBackgroundWork() synchronization_data_->is_force_wakeup_background_worker.store(false, std::memory_order_release); +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->AfterWait(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ if (synchronization_data_->is_shutdown.load() == true) { @@ -218,18 +224,22 @@ void BatchSpanProcessor::DoBackgroundWork() timeout = schedule_delay_millis_ - duration; } +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->OnEnd(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ } void BatchSpanProcessor::Export() { +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->BeforeLoad(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ do { @@ -270,10 +280,12 @@ void BatchSpanProcessor::Export() NotifyCompletion(notify_force_flush, exporter_, synchronization_data_); } while (true); +#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW if (worker_thread_instrumentation_ != nullptr) { worker_thread_instrumentation_->AfterLoad(); } +#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */ } void BatchSpanProcessor::NotifyCompletion(