diff --git a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_exporter.h b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_exporter.h index ad61281b7f..50e763e0c2 100644 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_exporter.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_exporter.h @@ -95,8 +95,10 @@ class ElasticsearchLogExporter final : public opentelemetry::sdk::logs::LogExpor * @param result_callback callback function accepting ExportResult as argument */ void Export( - const opentelemetry::nostd::span> &records, - nostd::function_ref result_callback) noexcept override; + const opentelemetry::nostd::span> + &records, + nostd::function_ref result_callback) noexcept + override; /** * Shutdown this exporter. diff --git a/exporters/elasticsearch/src/es_log_exporter.cc b/exporters/elasticsearch/src/es_log_exporter.cc index 892405e002..991678d6b9 100644 --- a/exporters/elasticsearch/src/es_log_exporter.cc +++ b/exporters/elasticsearch/src/es_log_exporter.cc @@ -110,7 +110,6 @@ class ResponseHandler : public http_client::EventHandler bool console_debug_ = false; }; - /** * This class handles the async response message from the Elasticsearch request */ @@ -121,20 +120,18 @@ class AsyncResponseHandler : public http_client::EventHandler * Creates a response handler, that by default doesn't display to console */ AsyncResponseHandler( - std::shared_ptr session, - nostd::function_ref result_callback, - bool console_debug = false) - : console_debug_{console_debug} - , session_{std::move(session)} - , result_callback_{result_callback} {} + std::shared_ptr session, + nostd::function_ref result_callback, + bool console_debug = false) + : console_debug_{console_debug}, + session_{std::move(session)}, + result_callback_{result_callback} + {} /** * Cleans up the session in the destructor. */ - ~AsyncResponseHandler() - { - session_->FinishSession(); - } + ~AsyncResponseHandler() { session_->FinishSession(); } /** * Automatically called when the response is received @@ -147,10 +144,12 @@ class AsyncResponseHandler : public http_client::EventHandler if (body_.find("\"failed\" : 0") == std::string::npos) { OTEL_INTERNAL_LOG_ERROR( - "[ES Trace Exporter] Logs were not written to Elasticsearch correctly, response body: " - << body_); + "[ES Trace Exporter] Logs were not written to Elasticsearch correctly, response body: " + << body_); result_callback_(sdk::common::ExportResult::kFailure); - } else { + } + else + { result_callback_(sdk::common::ExportResult::kSuccess); } } @@ -194,7 +193,6 @@ class AsyncResponseHandler : public http_client::EventHandler bool console_debug_ = false; }; - ElasticsearchLogExporter::ElasticsearchLogExporter() : options_{ElasticsearchExporterOptions()}, http_client_{new ext::http::client::curl::HttpClient()} @@ -284,8 +282,9 @@ sdk::common::ExportResult ElasticsearchLogExporter::Export( } void ElasticsearchLogExporter::Export( - const opentelemetry::nostd::span> &records, - nostd::function_ref result_callback) noexcept + const opentelemetry::nostd::span> + &records, + nostd::function_ref result_callback) noexcept { // Return failure if this exporter has been shutdown if (isShutdown()) @@ -322,8 +321,8 @@ void ElasticsearchLogExporter::Export( request->SetBody(body_vec); // Send the request - auto handler = std::make_shared( - session, result_callback, options_.console_debug_); + auto handler = + std::make_shared(session, result_callback, options_.console_debug_); session->SendRequest(handler); } diff --git a/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h b/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h index c2e17b97ff..eb3b4bd621 100644 --- a/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h +++ b/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h @@ -66,11 +66,9 @@ class JaegerExporter final : public opentelemetry::sdk::trace::SpanExporter * @param spans a span of unique pointers to span recordables * @param result_callback callback function accepting ExportResult as argument */ - void Export( - const nostd::span> &spans, - nostd::function_ref result_callback) - noexcept override; - + void Export(const nostd::span> &spans, + nostd::function_ref + result_callback) noexcept override; /** * Shutdown the exporter. diff --git a/exporters/jaeger/src/jaeger_exporter.cc b/exporters/jaeger/src/jaeger_exporter.cc index 60d8a80db9..4a028773ca 100644 --- a/exporters/jaeger/src/jaeger_exporter.cc +++ b/exporters/jaeger/src/jaeger_exporter.cc @@ -71,14 +71,12 @@ sdk_common::ExportResult JaegerExporter::Export( } void JaegerExporter::Export( - const nostd::span> &spans, - nostd::function_ref result_callback) - noexcept + const nostd::span> &spans, + nostd::function_ref result_callback) noexcept { OTEL_INTERNAL_LOG_WARN(" async not supported. Making sync interface call"); auto status = Export(spans); result_callback(status); - } void JaegerExporter::InitializeEndpoint() 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 73f090215a..3ebd3b8e89 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 @@ -71,8 +71,7 @@ class InMemorySpanExporter final : public opentelemetry::sdk::trace::SpanExporte */ void Export( const nostd::span> &spans, - nostd::function_ref result_callback) - noexcept override + nostd::function_ref result_callback) noexcept override { OTEL_INTERNAL_LOG_WARN(" async not supported. Making sync interface call"); auto status = Export(spans); diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/log_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/log_exporter.h index 2a1f7b6aa2..017d967c70 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/log_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/log_exporter.h @@ -42,10 +42,9 @@ class OStreamLogExporter final : public opentelemetry::sdk::logs::LogExporter /** * Exports a span of logs sent from the processor asynchronously. */ - void Export( - const opentelemetry::nostd::span> &records, - opentelemetry::nostd::function_ref result_callback) - noexcept; + void Export(const opentelemetry::nostd::span> &records, + opentelemetry::nostd::function_ref + result_callback) noexcept; /** * Marks the OStream Log Exporter as shut down. diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h index d23a92f77f..5af47280be 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h @@ -39,9 +39,10 @@ class OStreamSpanExporter final : public opentelemetry::sdk::trace::SpanExporter &spans) noexcept override; void Export( - const opentelemetry::nostd::span> &spans, - opentelemetry::nostd::function_ref result_callback) - noexcept override; + const opentelemetry::nostd::span> + &spans, + opentelemetry::nostd::function_ref + result_callback) noexcept override; bool Shutdown( std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override; diff --git a/exporters/ostream/src/log_exporter.cc b/exporters/ostream/src/log_exporter.cc index cc97073123..39d5dab4a3 100644 --- a/exporters/ostream/src/log_exporter.cc +++ b/exporters/ostream/src/log_exporter.cc @@ -181,9 +181,9 @@ sdk::common::ExportResult OStreamLogExporter::Export( } void OStreamLogExporter::Export( - const opentelemetry::nostd::span> &records, - opentelemetry::nostd::function_ref result_callback) - noexcept + const opentelemetry::nostd::span> &records, + opentelemetry::nostd::function_ref + result_callback) noexcept { // Do not have async support auto result = Export(records); diff --git a/exporters/ostream/src/span_exporter.cc b/exporters/ostream/src/span_exporter.cc index 2a97f830c3..24fcf6007b 100644 --- a/exporters/ostream/src/span_exporter.cc +++ b/exporters/ostream/src/span_exporter.cc @@ -97,8 +97,9 @@ sdk::common::ExportResult OStreamSpanExporter::Export( } void OStreamSpanExporter::Export( - const opentelemetry::nostd::span> &spans, - opentelemetry::nostd::function_ref result_callback) noexcept + const opentelemetry::nostd::span> &spans, + opentelemetry::nostd::function_ref + result_callback) noexcept { auto result = Export(spans); result_callback(result); diff --git a/exporters/otlp/src/otlp_grpc_exporter.cc b/exporters/otlp/src/otlp_grpc_exporter.cc index b06e788388..f191580b7f 100644 --- a/exporters/otlp/src/otlp_grpc_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_exporter.cc @@ -144,14 +144,13 @@ sdk::common::ExportResult OtlpGrpcExporter::Export( } void OtlpGrpcExporter::Export( - const nostd::span> &spans, - nostd::function_ref result_callback) - noexcept + const nostd::span> &spans, + nostd::function_ref result_callback) noexcept { - OTEL_INTERNAL_LOG_WARN("[OTLP TRACE GRPC Exporter] async not supported. Making sync interface call"); + OTEL_INTERNAL_LOG_WARN( + "[OTLP TRACE GRPC Exporter] async not supported. Making sync interface call"); auto status = Export(spans); result_callback(status); - } bool OtlpGrpcExporter::Shutdown(std::chrono::microseconds timeout) noexcept diff --git a/exporters/otlp/src/otlp_grpc_log_exporter.cc b/exporters/otlp/src/otlp_grpc_log_exporter.cc index 91e2a56e85..b56f8d9caa 100644 --- a/exporters/otlp/src/otlp_grpc_log_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_log_exporter.cc @@ -162,10 +162,11 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcLogExporter::Export( } void OtlpGrpcLogExporter::Export( - const nostd::span> &logs, - nostd::function_ref result_callback) noexcept + const nostd::span> &logs, + nostd::function_ref result_callback) noexcept { - OTEL_INTERNAL_LOG_WARN("[OTLP LOG GRPC Exporter] async not supported. Making sync interface call"); + OTEL_INTERNAL_LOG_WARN( + "[OTLP LOG GRPC Exporter] async not supported. Making sync interface call"); auto status = Export(logs); result_callback(status); } diff --git a/exporters/otlp/src/otlp_http_exporter.cc b/exporters/otlp/src/otlp_http_exporter.cc index 452fa89094..1262533283 100644 --- a/exporters/otlp/src/otlp_http_exporter.cc +++ b/exporters/otlp/src/otlp_http_exporter.cc @@ -13,7 +13,6 @@ #include "opentelemetry/sdk/common/global_log_handler.h" - namespace nostd = opentelemetry::nostd; OPENTELEMETRY_BEGIN_NAMESPACE @@ -60,8 +59,8 @@ opentelemetry::sdk::common::ExportResult OtlpHttpExporter::Export( } void OtlpHttpExporter::Export( - const nostd::span> &spans, - nostd::function_ref result_callback) noexcept + const nostd::span> &spans, + nostd::function_ref result_callback) noexcept { OTEL_INTERNAL_LOG_WARN(" async not supported. Making sync interface call"); auto status = Export(spans); diff --git a/exporters/otlp/src/otlp_http_log_exporter.cc b/exporters/otlp/src/otlp_http_log_exporter.cc index 734d6ecc48..bda33b4e31 100644 --- a/exporters/otlp/src/otlp_http_log_exporter.cc +++ b/exporters/otlp/src/otlp_http_log_exporter.cc @@ -60,8 +60,8 @@ opentelemetry::sdk::common::ExportResult OtlpHttpLogExporter::Export( } void OtlpHttpLogExporter::Export( - const nostd::span> &logs, - nostd::function_ref result_callback) noexcept + const nostd::span> &logs, + nostd::function_ref result_callback) noexcept { OTEL_INTERNAL_LOG_WARN(" async not supported. Making sync interface call"); auto status = Export(logs); diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index ef9f824733..04d37ea0b9 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -138,8 +138,8 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTest) auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, - report_trace_id](std::shared_ptr callback) { + .WillOnce([&mock_session, report_trace_id]( + std::shared_ptr callback) { auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); auto resource_span = *check_json["resource_spans"].begin(); auto instrumentation_library_span = *resource_span["instrumentation_library_spans"].begin(); @@ -217,8 +217,8 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTest) auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, - report_trace_id](std::shared_ptr callback) { + .WillOnce([&mock_session, report_trace_id]( + std::shared_ptr callback) { opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); diff --git a/exporters/otlp/test/otlp_http_log_exporter_test.cc b/exporters/otlp/test/otlp_http_log_exporter_test.cc index c7f52db214..07d7e33f33 100644 --- a/exporters/otlp/test/otlp_http_log_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_exporter_test.cc @@ -148,8 +148,8 @@ TEST_F(OtlpHttpLogExporterTestPeer, ExportJsonIntegrationTest) auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, - report_span_id](std::shared_ptr callback) { + .WillOnce([&mock_session, report_trace_id, report_span_id]( + std::shared_ptr callback) { auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); auto resource_logs = *check_json["resource_logs"].begin(); auto instrumentation_library_span = *resource_logs["instrumentation_library_logs"].begin(); @@ -232,8 +232,8 @@ TEST_F(OtlpHttpLogExporterTestPeer, ExportBinaryIntegrationTest) auto mock_session = std::static_pointer_cast(no_send_client->session_); EXPECT_CALL(*mock_session, SendRequest) - .WillOnce([&mock_session, report_trace_id, - report_span_id](std::shared_ptr callback) { + .WillOnce([&mock_session, report_trace_id, report_span_id]( + std::shared_ptr callback) { opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h index 810ac288e9..3ac8c04028 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h @@ -83,10 +83,9 @@ class ZipkinExporter final : public opentelemetry::sdk::trace::SpanExporter * @param spans a span of unique pointers to span recordables * @param result_callback callback function accepting ExportResult as argument */ - void Export( - const nostd::span> &spans, - nostd::function_ref result_callback) - noexcept override; + void Export(const nostd::span> &spans, + nostd::function_ref + result_callback) noexcept override; /** * Shut down the exporter. diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index e3341945c8..050ed4c9a8 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -94,9 +94,8 @@ sdk::common::ExportResult ZipkinExporter::Export( } void ZipkinExporter::Export( - const nostd::span> &spans, - nostd::function_ref result_callback) - noexcept + const nostd::span> &spans, + nostd::function_ref result_callback) noexcept { OTEL_INTERNAL_LOG_WARN("[ZIPKIN EXPORTER] async not supported. Making sync interface call"); auto status = Export(spans); diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index 3b48d2aa1e..7085a1da33 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -226,7 +226,6 @@ TEST_F(BasicCurlHttpTests, SendPostRequest) session_manager->CancelAllSessions(); session_manager->FinishAllSessions(); - } TEST_F(BasicCurlHttpTests, RequestTimeout) diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h b/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h index ba2df5d5a5..569f530430 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h @@ -122,7 +122,8 @@ class BatchLogProcessor : public LogProcessor const bool is_export_async_; /* Synchronization primitives */ - std::condition_variable cv_, force_flush_cv_, async_shutdown_cv_;; + std::condition_variable cv_, force_flush_cv_, async_shutdown_cv_; + ; std::mutex cv_m_, force_flush_cv_m_, shutdown_m_, async_shutdown_m_; /* The buffer/queue to which the ended logs are added */ diff --git a/sdk/include/opentelemetry/sdk/logs/exporter.h b/sdk/include/opentelemetry/sdk/logs/exporter.h index 86f121d581..05990471d0 100644 --- a/sdk/include/opentelemetry/sdk/logs/exporter.h +++ b/sdk/include/opentelemetry/sdk/logs/exporter.h @@ -46,7 +46,6 @@ class LogExporter virtual sdk::common::ExportResult Export( const nostd::span> &records) noexcept = 0; - /** * Exports asynchronously the batch of log records to their export destination * @param records a span of unique pointers to log records diff --git a/sdk/include/opentelemetry/sdk/logs/simple_log_processor.h b/sdk/include/opentelemetry/sdk/logs/simple_log_processor.h index b377b86fc8..28fcca78a6 100644 --- a/sdk/include/opentelemetry/sdk/logs/simple_log_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/simple_log_processor.h @@ -28,7 +28,8 @@ class SimpleLogProcessor : public LogProcessor { public: - explicit SimpleLogProcessor(std::unique_ptr &&exporter, bool is_export_async = false); + explicit SimpleLogProcessor(std::unique_ptr &&exporter, + bool is_export_async = false); virtual ~SimpleLogProcessor() = default; std::unique_ptr MakeRecordable() noexcept override; @@ -48,7 +49,7 @@ class SimpleLogProcessor : public LogProcessor opentelemetry::common::SpinLockMutex lock_; // The atomic boolean flag to ensure the ShutDown() function is only called once std::atomic_flag shutdown_latch_ = ATOMIC_FLAG_INIT; - bool is_export_async_ = false; + bool is_export_async_ = false; }; } // namespace logs } // namespace sdk diff --git a/sdk/include/opentelemetry/sdk/trace/simple_processor.h b/sdk/include/opentelemetry/sdk/trace/simple_processor.h index df70b99e41..982a432e0c 100644 --- a/sdk/include/opentelemetry/sdk/trace/simple_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/simple_processor.h @@ -31,9 +31,9 @@ class SimpleSpanProcessor : public SpanProcessor * Initialize a simple span processor. * @param exporter the exporter used by the span processor */ - explicit SimpleSpanProcessor(std::unique_ptr &&exporter, bool is_export_async = false) noexcept - : exporter_(std::move(exporter)) - , is_export_async_(is_export_async) + explicit SimpleSpanProcessor(std::unique_ptr &&exporter, + bool is_export_async = false) noexcept + : exporter_(std::move(exporter)), is_export_async_(is_export_async) {} std::unique_ptr MakeRecordable() noexcept override @@ -49,16 +49,19 @@ class SimpleSpanProcessor : public SpanProcessor { nostd::span> batch(&span, 1); const std::lock_guard locked(lock_); - if (is_export_async_ == false) { + if (is_export_async_ == false) + { if (exporter_->Export(batch) == sdk::common::ExportResult::kFailure) { /* Once it is defined how the SDK does logging, an error should be * logged in this case. */ } - } else { - exporter_->Export(batch, [](sdk::common::ExportResult result){ + } + else + { + exporter_->Export(batch, [](sdk::common::ExportResult result) { /* Log the result - */ + */ return true; }); } @@ -87,7 +90,7 @@ class SimpleSpanProcessor : public SpanProcessor std::unique_ptr exporter_; opentelemetry::common::SpinLockMutex lock_; std::atomic_flag shutdown_latch_ = ATOMIC_FLAG_INIT; - bool is_export_async_ = false; + bool is_export_async_ = false; }; } // namespace trace } // namespace sdk diff --git a/sdk/src/logs/batch_log_processor.cc b/sdk/src/logs/batch_log_processor.cc index a66368661b..7d8782f115 100644 --- a/sdk/src/logs/batch_log_processor.cc +++ b/sdk/src/logs/batch_log_processor.cc @@ -154,12 +154,14 @@ void BatchLogProcessor::Export(const bool was_force_flush_called) }); }); - if (is_export_async_ == false) { + if (is_export_async_ == false) + { exporter_->Export( nostd::span>(records_arr.data(), records_arr.size())); NotifyForceFlushCompletion(was_force_flush_called); } - else { + else + { exporter_->Export( nostd::span>(records_arr.data(), records_arr.size()), [this, was_force_flush_called](sdk::common::ExportResult result) { @@ -203,7 +205,8 @@ void BatchLogProcessor::WaitForShutdownCompletion() void BatchLogProcessor::NotifyShutdownCompletion() { // Notify the thread which is waiting on shutdown to complete. - if (is_shutdown_.load() == true) { + if (is_shutdown_.load() == true) + { is_async_shutdown_notified_.store(true); async_shutdown_cv_.notify_one(); } diff --git a/sdk/src/logs/simple_log_processor.cc b/sdk/src/logs/simple_log_processor.cc index dbafd29fc2..e16a5e631e 100644 --- a/sdk/src/logs/simple_log_processor.cc +++ b/sdk/src/logs/simple_log_processor.cc @@ -16,9 +16,9 @@ namespace logs * Initialize a simple log processor. * @param exporter the configured exporter where log records are sent */ -SimpleLogProcessor::SimpleLogProcessor(std::unique_ptr &&exporter, bool is_export_async) - : exporter_(std::move(exporter)) - , is_export_async_(is_export_async) +SimpleLogProcessor::SimpleLogProcessor(std::unique_ptr &&exporter, + bool is_export_async) + : exporter_(std::move(exporter)), is_export_async_(is_export_async) {} std::unique_ptr SimpleLogProcessor::MakeRecordable() noexcept @@ -36,15 +36,18 @@ void SimpleLogProcessor::OnReceive(std::unique_ptr &&record) noexcep // Get lock to ensure Export() is never called concurrently const std::lock_guard locked(lock_); - if (is_export_async_ == false) { + if (is_export_async_ == false) + { if (exporter_->Export(batch) != sdk::common::ExportResult::kSuccess) { /* Alert user of the failed export */ } - } else { - exporter_->Export(batch, [](sdk::common::ExportResult result){ + } + else + { + exporter_->Export(batch, [](sdk::common::ExportResult result) { /* Log the result - */ + */ return true; }); } diff --git a/sdk/src/trace/batch_span_processor.cc b/sdk/src/trace/batch_span_processor.cc index 41546e994f..a5a54d6218 100644 --- a/sdk/src/trace/batch_span_processor.cc +++ b/sdk/src/trace/batch_span_processor.cc @@ -161,20 +161,22 @@ void BatchSpanProcessor::Export(const bool was_force_flush_called) /* Call the sync Export when force flush was called, even if is_export_async_ is true. */ - if (is_export_async_ == false || was_force_flush_called == true) { + if (is_export_async_ == false || was_force_flush_called == true) + { exporter_->Export(nostd::span>(spans_arr.data(), spans_arr.size())); NotifyForceFlushCompletion(was_force_flush_called); } - else { + else + { exporter_->Export(nostd::span>(spans_arr.data(), spans_arr.size()), - [this, was_force_flush_called](sdk::common::ExportResult result) { - // TODO: Print result - NotifyForceFlushCompletion(was_force_flush_called); - // If export was called due to shutdown, notify the worker thread - NotifyShutdownCompletion(); - return true; - }); + [this, was_force_flush_called](sdk::common::ExportResult result) { + // TODO: Print result + NotifyForceFlushCompletion(was_force_flush_called); + // If export was called due to shutdown, notify the worker thread + NotifyShutdownCompletion(); + return true; + }); } } @@ -208,7 +210,8 @@ void BatchSpanProcessor::WaitForShutdownCompletion() void BatchSpanProcessor::NotifyShutdownCompletion() { // Notify the thread which is waiting on shutdown to complete. - if (is_shutdown_.load() == true) { + if (is_shutdown_.load() == true) + { is_async_shutdown_notified_.store(true); async_shutdown_cv_.notify_one(); } diff --git a/sdk/test/logs/batch_log_processor_test.cc b/sdk/test/logs/batch_log_processor_test.cc index c75ff72899..55850bf414 100644 --- a/sdk/test/logs/batch_log_processor_test.cc +++ b/sdk/test/logs/batch_log_processor_test.cc @@ -55,10 +55,11 @@ class MockLogExporter final : public LogExporter return ExportResult::kSuccess; } - void Export(const opentelemetry::nostd::span> &records, - opentelemetry::nostd::function_ref result_callback) noexcept override + void Export( + const opentelemetry::nostd::span> &records, + opentelemetry::nostd::function_ref result_callback) noexcept override { - auto th = std::thread([this, records, result_callback](){ + auto th = std::thread([this, records, result_callback]() { auto result = Export(records); result_callback(result); }); @@ -99,11 +100,10 @@ class BatchLogProcessorTest : public testing::Test // ::testing::Test const size_t max_export_batch_size = 512, const bool is_export_async = false) { - return std::shared_ptr( - new BatchLogProcessor(std::unique_ptr(new MockLogExporter( - logs_received, is_shutdown, is_export_completed, export_delay)), - max_queue_size, scheduled_delay_millis, max_export_batch_size, - is_export_async)); + return std::shared_ptr(new BatchLogProcessor( + std::unique_ptr( + new MockLogExporter(logs_received, is_shutdown, is_export_completed, export_delay)), + max_queue_size, scheduled_delay_millis, max_export_batch_size, is_export_async)); } }; @@ -156,12 +156,12 @@ TEST_F(BatchLogProcessorTest, TestAsyncShutdown) const std::chrono::milliseconds export_delay(0); const std::chrono::milliseconds scheduled_delay_millis(5000); const size_t max_export_batch_size = 512; - const size_t max_queue_size = 2048; - const bool is_export_async = true; + const size_t max_queue_size = 2048; + const bool is_export_async = true; auto batch_processor = GetMockProcessor(logs_received, is_shutdown, is_export_completed, - export_delay, scheduled_delay_millis, max_queue_size, max_export_batch_size, - is_export_async); + export_delay, scheduled_delay_millis, max_queue_size, + max_export_batch_size, is_export_async); // Create a few test log records and send them to the processor const int num_logs = 3; @@ -243,14 +243,14 @@ TEST_F(BatchLogProcessorTest, TestAsyncForceFlush) const std::chrono::milliseconds export_delay(0); const std::chrono::milliseconds scheduled_delay_millis(5000); const size_t max_export_batch_size = 512; - const size_t max_queue_size = 2048; - const bool is_export_async = true; + const size_t max_queue_size = 2048; + const bool is_export_async = true; auto batch_processor = GetMockProcessor(logs_received, is_shutdown, is_export_completed, - export_delay, scheduled_delay_millis, max_queue_size, max_export_batch_size, - is_export_async); + export_delay, scheduled_delay_millis, max_queue_size, + max_export_batch_size, is_export_async); - const int num_logs = 2048; + const int num_logs = 2048; for (int i = 0; i < num_logs; ++i) { diff --git a/sdk/test/logs/simple_log_processor_test.cc b/sdk/test/logs/simple_log_processor_test.cc index 2a86910c94..8b8efa6636 100644 --- a/sdk/test/logs/simple_log_processor_test.cc +++ b/sdk/test/logs/simple_log_processor_test.cc @@ -55,7 +55,7 @@ class TestExporter final : public LogExporter // Dummy Async Export implementation void Export(const nostd::span> &records, - nostd::function_ref result_callback) noexcept override + nostd::function_ref result_callback) noexcept override { auto result = Export(records); result_callback(result); @@ -146,7 +146,7 @@ class FailShutDownExporter final : public LogExporter } void Export(const nostd::span> &records, - nostd::function_ref result_callback) noexcept override + nostd::function_ref result_callback) noexcept override { result_callback(ExportResult::kSuccess); } diff --git a/sdk/test/trace/batch_span_processor_test.cc b/sdk/test/trace/batch_span_processor_test.cc index fc6f5f4441..91561ac658 100644 --- a/sdk/test/trace/batch_span_processor_test.cc +++ b/sdk/test/trace/batch_span_processor_test.cc @@ -60,7 +60,7 @@ class MockSpanExporter final : public sdk::trace::SpanExporter const nostd::span> &spans, nostd::function_ref result_callback) noexcept override { - auto th = std::thread([this, spans, result_callback](){ + auto th = std::thread([this, spans, result_callback]() { auto result = Export(spans); result_callback(result); }); diff --git a/sdk/test/trace/simple_processor_test.cc b/sdk/test/trace/simple_processor_test.cc index b46339ebad..b8bad5962d 100644 --- a/sdk/test/trace/simple_processor_test.cc +++ b/sdk/test/trace/simple_processor_test.cc @@ -51,10 +51,9 @@ class RecordShutdownExporter final : public SpanExporter return ExportResult::kSuccess; } - void Export( - const opentelemetry::nostd::span> &spans, - opentelemetry::nostd::function_ref result_callback) - noexcept override + void Export(const opentelemetry::nostd::span> &spans, + opentelemetry::nostd::function_ref + result_callback) noexcept override { result_callback(ExportResult::kSuccess); }