From 72f8ccee5e05e78bd2e4e6e78878aa3c302d4f59 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Fri, 8 May 2026 20:17:29 +0000 Subject: [PATCH 01/22] [EXPORTER] Add WITH_CUSTOM_HTTP_CLIENT option --- CMakeLists.txt | 18 +++++++++++++----- exporters/otlp/CMakeLists.txt | 15 ++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dffc2c453..df9e138289 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,6 +160,11 @@ option( option(WITH_CURL_LOGGING "Whether to enable select CURL verbosity in OTel logs" OFF) +option( + WITH_CUSTOM_HTTP_CLIENT + "Enable a custom HTTP client instead of the default CURL backend" + OFF) + option(WITH_ZIPKIN "Whether to include the Zipkin exporter in the SDK" OFF) option(WITH_PROMETHEUS "Whether to include the Prometheus Client in the SDK" @@ -274,11 +279,13 @@ include(GNUInstallDirs) # Do we need HTTP CLIENT CURL ? # -if(WITH_OTLP_HTTP - OR WITH_ELASTICSEARCH - OR WITH_ZIPKIN - OR BUILD_W3CTRACECONTEXT_TEST - OR WITH_EXAMPLES_HTTP) +if(WITH_CUSTOM_HTTP_CLIENT) + set(WITH_HTTP_CLIENT_CURL OFF) +elseif(WITH_OTLP_HTTP + OR WITH_ELASTICSEARCH + OR WITH_ZIPKIN + OR BUILD_W3CTRACECONTEXT_TEST + OR WITH_EXAMPLES_HTTP) set(WITH_HTTP_CLIENT_CURL ON) else() set(WITH_HTTP_CLIENT_CURL OFF) @@ -501,6 +508,7 @@ message(STATUS "WITH_OTLP_GRPC: ${WITH_OTLP_GRPC}") message(STATUS "WITH_OTLP_HTTP: ${WITH_OTLP_HTTP}") message(STATUS "WITH_OTLP_FILE: ${WITH_OTLP_FILE}") message(STATUS "WITH_HTTP_CLIENT_CURL: ${WITH_HTTP_CLIENT_CURL}") +message(STATUS "WITH_CUSTOM_HTTP_CLIENT: ${WITH_CUSTOM_HTTP_CLIENT}") message(STATUS "WITH_ZIPKIN: ${WITH_ZIPKIN}") message(STATUS "WITH_PROMETHEUS: ${WITH_PROMETHEUS}") message(STATUS "WITH_ELASTICSEARCH: ${WITH_ELASTICSEARCH}") diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 2d53476be6..9177783389 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -318,13 +318,18 @@ if(WITH_OTLP_HTTP) opentelemetry_exporter_otlp_http_client PUBLIC opentelemetry_sdk opentelemetry_ext - # Links flags of opentelemetry_http_client_curl should be public when - # building internal components "$" PRIVATE "$" - "$" - "$" - "$") + "$") + + if(NOT WITH_CUSTOM_HTTP_CLIENT) + # Links flags of opentelemetry_http_client_curl should be public when + # building internal components + target_link_libraries( + opentelemetry_exporter_otlp_http_client + PRIVATE "$" + "$") + endif() target_include_directories( opentelemetry_exporter_otlp_http_client From 8fa20728e9646bb367d3634c8c6eb862b2181d29 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Mon, 11 May 2026 20:55:14 +0000 Subject: [PATCH 02/22] Fix formatting --- CMakeLists.txt | 17 ++++++++--------- exporters/otlp/CMakeLists.txt | 3 +-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df9e138289..accc44d105 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,10 +160,8 @@ option( option(WITH_CURL_LOGGING "Whether to enable select CURL verbosity in OTel logs" OFF) -option( - WITH_CUSTOM_HTTP_CLIENT - "Enable a custom HTTP client instead of the default CURL backend" - OFF) +option(WITH_CUSTOM_HTTP_CLIENT + "Enable a custom HTTP client instead of the default CURL backend" OFF) option(WITH_ZIPKIN "Whether to include the Zipkin exporter in the SDK" OFF) @@ -281,11 +279,12 @@ include(GNUInstallDirs) if(WITH_CUSTOM_HTTP_CLIENT) set(WITH_HTTP_CLIENT_CURL OFF) -elseif(WITH_OTLP_HTTP - OR WITH_ELASTICSEARCH - OR WITH_ZIPKIN - OR BUILD_W3CTRACECONTEXT_TEST - OR WITH_EXAMPLES_HTTP) +elseif( + WITH_OTLP_HTTP + OR WITH_ELASTICSEARCH + OR WITH_ZIPKIN + OR BUILD_W3CTRACECONTEXT_TEST + OR WITH_EXAMPLES_HTTP) set(WITH_HTTP_CLIENT_CURL ON) else() set(WITH_HTTP_CLIENT_CURL OFF) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 9177783389..38e3b282c9 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -316,8 +316,7 @@ if(WITH_OTLP_HTTP) target_link_libraries( opentelemetry_exporter_otlp_http_client - PUBLIC opentelemetry_sdk - opentelemetry_ext + PUBLIC opentelemetry_sdk opentelemetry_ext "$" PRIVATE "$" "$") From 87a12da7c72ce2ad6da2c2c47e1b000a24a56e9d Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Mon, 11 May 2026 20:57:19 +0000 Subject: [PATCH 03/22] Add opentelemetry_http_client interface library --- examples/http/CMakeLists.txt | 22 ++++++++++--------- exporters/elasticsearch/CMakeLists.txt | 2 +- exporters/otlp/CMakeLists.txt | 12 ++++------ exporters/zipkin/CMakeLists.txt | 2 +- ext/src/CMakeLists.txt | 11 ++++++++++ .../CMakeLists.txt | 14 +++++++----- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/examples/http/CMakeLists.txt b/examples/http/CMakeLists.txt index 0aff680302..218fc7a23e 100644 --- a/examples/http/CMakeLists.txt +++ b/examples/http/CMakeLists.txt @@ -1,15 +1,17 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -add_executable(http_client client.cc) -add_executable(http_server server.cc) +if(NOT WITH_CUSTOM_HTTP_CLIENT) + add_executable(http_client client.cc) + add_executable(http_server server.cc) -target_link_libraries( - http_client - PRIVATE opentelemetry-cpp::trace opentelemetry-cpp::http_client_curl - opentelemetry-cpp::ostream_span_exporter CURL::libcurl) + target_link_libraries( + http_client + PRIVATE opentelemetry-cpp::trace opentelemetry-cpp::http_client_curl + opentelemetry-cpp::ostream_span_exporter CURL::libcurl) -target_link_libraries( - http_server - PRIVATE opentelemetry-cpp::trace opentelemetry-cpp::http_client_curl - opentelemetry-cpp::ostream_span_exporter) + target_link_libraries( + http_server + PRIVATE opentelemetry-cpp::trace opentelemetry-cpp::http_client_curl + opentelemetry-cpp::ostream_span_exporter) +endif() diff --git a/exporters/elasticsearch/CMakeLists.txt b/exporters/elasticsearch/CMakeLists.txt index 7341ec4cfc..cfd4ce01db 100644 --- a/exporters/elasticsearch/CMakeLists.txt +++ b/exporters/elasticsearch/CMakeLists.txt @@ -17,7 +17,7 @@ target_include_directories( target_link_libraries( opentelemetry_exporter_elasticsearch_logs - PUBLIC opentelemetry_trace opentelemetry_logs opentelemetry_http_client_curl + PUBLIC opentelemetry_trace opentelemetry_logs opentelemetry_http_client nlohmann_json::nlohmann_json) otel_add_component( diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 38e3b282c9..fa167b0d30 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -321,14 +321,10 @@ if(WITH_OTLP_HTTP) PRIVATE "$" "$") - if(NOT WITH_CUSTOM_HTTP_CLIENT) - # Links flags of opentelemetry_http_client_curl should be public when - # building internal components - target_link_libraries( - opentelemetry_exporter_otlp_http_client - PRIVATE "$" - "$") - endif() + # Links flags of opentelemetry_http_client should be public when building + # internal components + target_link_libraries(opentelemetry_exporter_otlp_http_client + PRIVATE opentelemetry_http_client) target_include_directories( opentelemetry_exporter_otlp_http_client diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index 9955d8c4cb..8b4eb0f822 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -23,7 +23,7 @@ set_target_version(opentelemetry_exporter_zipkin_trace) target_link_libraries( opentelemetry_exporter_zipkin_trace - PUBLIC opentelemetry_trace opentelemetry_http_client_curl + PUBLIC opentelemetry_trace opentelemetry_http_client nlohmann_json::nlohmann_json) otel_add_component( diff --git a/ext/src/CMakeLists.txt b/ext/src/CMakeLists.txt index b3d45a719d..2c32c64cb8 100644 --- a/ext/src/CMakeLists.txt +++ b/ext/src/CMakeLists.txt @@ -5,6 +5,17 @@ if(WITH_HTTP_CLIENT_CURL) add_subdirectory(http/client/curl) endif() +if(WITH_HTTP_CLIENT_CURL OR WITH_CUSTOM_HTTP_CLIENT) + add_library(opentelemetry_http_client INTERFACE) + if(WITH_HTTP_CLIENT_CURL) + target_link_libraries(opentelemetry_http_client + INTERFACE opentelemetry_http_client_curl) + endif() + # When WITH_CUSTOM_HTTP_CLIENT=ON the target is intentionally left empty. The + # consumer populates it after add_subdirectory: + # target_link_libraries(opentelemetry_http_client INTERFACE my_impl) +endif() + if(DEFINED OPENTELEMETRY_BUILD_DLL) add_subdirectory(dll) endif() diff --git a/ext/test/w3c_tracecontext_http_test_server/CMakeLists.txt b/ext/test/w3c_tracecontext_http_test_server/CMakeLists.txt index 095da7ad80..d441f7471b 100644 --- a/ext/test/w3c_tracecontext_http_test_server/CMakeLists.txt +++ b/ext/test/w3c_tracecontext_http_test_server/CMakeLists.txt @@ -1,9 +1,11 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -add_executable(w3c_tracecontext_http_test_server main.cc) -target_link_libraries( - w3c_tracecontext_http_test_server - PRIVATE ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace - opentelemetry_http_client_curl opentelemetry_exporter_ostream_span - CURL::libcurl nlohmann_json::nlohmann_json) +if(NOT WITH_CUSTOM_HTTP_CLIENT) + add_executable(w3c_tracecontext_http_test_server main.cc) + target_link_libraries( + w3c_tracecontext_http_test_server + PRIVATE ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace + opentelemetry_http_client_curl opentelemetry_exporter_ostream_span + CURL::libcurl nlohmann_json::nlohmann_json) +endif() From 135c213e568bbe8218603e23cd40caca9f7c0d15 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Tue, 12 May 2026 19:57:12 +0000 Subject: [PATCH 04/22] Add example and test --- CMakeLists.txt | 8 ++ examples/CMakeLists.txt | 4 + examples/custom_http_client/CMakeLists.txt | 14 +++ .../custom_http_client/custom_http_client.cc | 92 ++++++++++++++ examples/custom_http_client/main.cc | 32 +++++ exporters/elasticsearch/CMakeLists.txt | 9 +- exporters/otlp/CMakeLists.txt | 23 +++- .../exporters/otlp/otlp_http_exporter.h | 1 + .../test/http_client_factory_nosend_stub.cc | 23 ++++ .../otlp_http_exporter_custom_client_test.cc | 112 ++++++++++++++++++ exporters/zipkin/CMakeLists.txt | 40 ++++--- ext/src/CMakeLists.txt | 5 +- 12 files changed, 339 insertions(+), 24 deletions(-) create mode 100644 examples/custom_http_client/CMakeLists.txt create mode 100644 examples/custom_http_client/custom_http_client.cc create mode 100644 examples/custom_http_client/main.cc create mode 100644 exporters/otlp/test/http_client_factory_nosend_stub.cc create mode 100644 exporters/otlp/test/otlp_http_exporter_custom_client_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index accc44d105..92b5c1644d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,6 +279,14 @@ include(GNUInstallDirs) if(WITH_CUSTOM_HTTP_CLIENT) set(WITH_HTTP_CLIENT_CURL OFF) + if(WITH_ZIPKIN OR WITH_ELASTICSEARCH) + message( + WARNING + "WITH_CUSTOM_HTTP_CLIENT=ON: opentelemetry_http_client INTERFACE is empty. " + "WITH_ZIPKIN and WITH_ELASTICSEARCH require you to populate it with your transport " + "implementation via target_link_libraries(opentelemetry_http_client INTERFACE )." + ) + endif() elseif( WITH_OTLP_HTTP OR WITH_ELASTICSEARCH diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 6052d2f04d..af7bd291ce 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -34,6 +34,10 @@ if(WITH_EXAMPLES_HTTP) add_subdirectory(http) endif() +if(WITH_CUSTOM_HTTP_CLIENT AND WITH_OTLP_HTTP) + add_subdirectory(custom_http_client) +endif() + if(WITH_CONFIGURATION) add_subdirectory(configuration) endif() diff --git a/examples/custom_http_client/CMakeLists.txt b/examples/custom_http_client/CMakeLists.txt new file mode 100644 index 0000000000..3c5a09d266 --- /dev/null +++ b/examples/custom_http_client/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +add_library(custom_http_client_stub STATIC custom_http_client.cc) +target_link_libraries(custom_http_client_stub PUBLIC opentelemetry_ext + opentelemetry_sdk) + +target_link_libraries(opentelemetry_http_client + INTERFACE custom_http_client_stub) + +add_executable(example_custom_http_client main.cc) +target_link_libraries( + example_custom_http_client PRIVATE custom_http_client_stub + opentelemetry-cpp::otlp_http_exporter) diff --git a/examples/custom_http_client/custom_http_client.cc b/examples/custom_http_client/custom_http_client.cc new file mode 100644 index 0000000000..8d8f451565 --- /dev/null +++ b/examples/custom_http_client/custom_http_client.cc @@ -0,0 +1,92 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/sdk/common/thread_instrumentation.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace ext +{ +namespace http +{ +namespace client +{ + +namespace +{ + +class NoopRequest : public Request +{ +public: + void SetMethod(Method) noexcept override {} + void SetUri(nostd::string_view) noexcept override {} + void SetSslOptions(const HttpSslOptions &) noexcept override {} + void SetBody(Body &) noexcept override {} + void AddHeader(nostd::string_view, nostd::string_view) noexcept override {} + void ReplaceHeader(nostd::string_view, nostd::string_view) noexcept override {} + void SetTimeoutMs(std::chrono::milliseconds) noexcept override {} + void SetCompression(const Compression &) noexcept override {} + void EnableLogging(bool) noexcept override {} + void SetRetryPolicy(const RetryPolicy &) noexcept override {} +}; + +class NoopSession : public Session +{ +public: + std::shared_ptr CreateRequest() noexcept override + { + return std::make_shared(); + } + + void SendRequest(std::shared_ptr handler) noexcept override + { + if (!handler) + { + return; + } + NoopResponse response; + handler->OnResponse(response); + handler->OnEvent(SessionState::Response, {}); + } + + bool IsSessionActive() noexcept override { return false; } + bool CancelSession() noexcept override { return true; } + bool FinishSession() noexcept override { return true; } +}; + +class NoopHttpClient : public HttpClient +{ +public: + std::shared_ptr CreateSession(nostd::string_view) noexcept override + { + return std::make_shared(); + } + + bool CancelAllSessions() noexcept override { return true; } + bool FinishAllSessions() noexcept override { return true; } + void SetMaxSessionsPerConnection(std::size_t) noexcept override {} +}; + +} // namespace + +std::shared_ptr HttpClientFactory::Create() +{ + return std::make_shared(); +} + +std::shared_ptr HttpClientFactory::Create( + const std::shared_ptr &) +{ + return std::make_shared(); +} + +std::shared_ptr HttpClientFactory::CreateSync() +{ + return nullptr; +} + +} // namespace client +} // namespace http +} // namespace ext +OPENTELEMETRY_END_NAMESPACE diff --git a/examples/custom_http_client/main.cc b/examples/custom_http_client/main.cc new file mode 100644 index 0000000000..7b50adfce3 --- /dev/null +++ b/examples/custom_http_client/main.cc @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" +#include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider_factory.h" + +namespace trace_sdk = opentelemetry::sdk::trace; +namespace otlp = opentelemetry::exporter::otlp; + +int main() +{ + otlp::OtlpHttpExporterOptions options; + options.url = "http://localhost:4318/v1/traces"; + + auto exporter = otlp::OtlpHttpExporterFactory::Create(options); + auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); + + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor)); + + auto tracer = provider->GetTracer("custom-http-client-example"); + auto span = tracer->StartSpan("custom-span"); + span->SetAttribute("example.key", "value"); + span->End(); + + provider->ForceFlush(); + return 0; +} diff --git a/exporters/elasticsearch/CMakeLists.txt b/exporters/elasticsearch/CMakeLists.txt index cfd4ce01db..556bab5617 100644 --- a/exporters/elasticsearch/CMakeLists.txt +++ b/exporters/elasticsearch/CMakeLists.txt @@ -17,9 +17,16 @@ target_include_directories( target_link_libraries( opentelemetry_exporter_elasticsearch_logs - PUBLIC opentelemetry_trace opentelemetry_logs opentelemetry_http_client + PUBLIC opentelemetry_trace opentelemetry_logs + "$" nlohmann_json::nlohmann_json) +if(WITH_HTTP_CLIENT_CURL) + target_link_libraries( + opentelemetry_exporter_elasticsearch_logs + PUBLIC "$") +endif() + otel_add_component( COMPONENT exporters_elasticsearch diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index fa167b0d30..82cb68040a 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -321,10 +321,9 @@ if(WITH_OTLP_HTTP) PRIVATE "$" "$") - # Links flags of opentelemetry_http_client should be public when building - # internal components - target_link_libraries(opentelemetry_exporter_otlp_http_client - PRIVATE opentelemetry_http_client) + target_link_libraries( + opentelemetry_exporter_otlp_http_client + PRIVATE "$" opentelemetry_common) target_include_directories( opentelemetry_exporter_otlp_http_client @@ -1062,6 +1061,22 @@ if(BUILD_TESTING) TARGET otlp_http_metric_exporter_factory_test TEST_PREFIX exporter.otlp. TEST_LIST otlp_http_metric_exporter_factory_test) + + if(WITH_CUSTOM_HTTP_CLIENT) + add_executable( + otlp_http_exporter_custom_client_test + test/otlp_http_exporter_custom_client_test.cc + # Provides HttpClientFactory::Create() without touching the INTERFACE. + test/http_client_factory_nosend_stub.cc) + target_link_libraries( + otlp_http_exporter_custom_client_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} opentelemetry_exporter_otlp_http + opentelemetry_http_client_nosend) + gtest_add_tests( + TARGET otlp_http_exporter_custom_client_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_exporter_custom_client_test) + endif() endif() if(WITH_OTLP_FILE) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h index 454959dd45..6f2b019ae8 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h @@ -84,6 +84,7 @@ class OPENTELEMETRY_EXPORT OtlpHttpExporter final : public opentelemetry::sdk::t std::unique_ptr http_client_; // For testing friend class OtlpHttpExporterTestPeer; + friend class OtlpHttpExporterCustomClientTestPeer; /** * Create an OtlpHttpExporter using the specified http client. * Only tests can call this constructor directly. diff --git a/exporters/otlp/test/http_client_factory_nosend_stub.cc b/exporters/otlp/test/http_client_factory_nosend_stub.cc new file mode 100644 index 0000000000..2a6e344f02 --- /dev/null +++ b/exporters/otlp/test/http_client_factory_nosend_stub.cc @@ -0,0 +1,23 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" + +namespace http_client = opentelemetry::ext::http::client; + +std::shared_ptr http_client::HttpClientFactory::Create() +{ + return std::make_shared(); +} + +std::shared_ptr http_client::HttpClientFactory::Create( + const std::shared_ptr &) +{ + return std::make_shared(); +} + +std::shared_ptr http_client::HttpClientFactory::CreateSync() +{ + return nullptr; +} diff --git a/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc b/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc new file mode 100644 index 0000000000..0568735da0 --- /dev/null +++ b/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc @@ -0,0 +1,112 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef OPENTELEMETRY_STL_VERSION + +# include + +# include "opentelemetry/exporters/otlp/otlp_http_client.h" +# include "opentelemetry/exporters/otlp/otlp_http_exporter.h" +# include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" +# include "opentelemetry/sdk/trace/batch_span_processor.h" +# include "opentelemetry/sdk/trace/batch_span_processor_options.h" +# include "opentelemetry/sdk/trace/tracer_provider.h" +# include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h" +# include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" + +# include +# include "gmock/gmock.h" + +using namespace testing; + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +namespace http_client = opentelemetry::ext::http::client; + +static OtlpHttpClientOptions MakeOtlpHttpClientOptions() +{ + std::shared_ptr not_instrumented; + OtlpHttpExporterOptions options; + options.console_debug = true; + options.timeout = std::chrono::system_clock::duration::zero(); + options.retry_policy_max_attempts = 0U; + options.retry_policy_initial_backoff = std::chrono::duration::zero(); + options.retry_policy_max_backoff = std::chrono::duration::zero(); + options.retry_policy_backoff_multiplier = 0.0f; + OtlpHttpClientOptions otlp_http_client_options( + options.url, false, /* ssl_insecure_skip_verify */ + "", /* ssl_ca_cert_path */ + "", /* ssl_ca_cert_string */ + "", /* ssl_client_key_path */ + "", /* ssl_client_key_string */ + "", /* ssl_client_cert_path */ + "", /* ssl_client_cert_string */ + "", /* ssl_min_tls */ + "", /* ssl_max_tls */ + "", /* ssl_cipher */ + "", /* ssl_cipher_suite */ + options.content_type, options.json_bytes_mapping, options.compression, options.use_json_name, + options.console_debug, options.timeout, options.http_headers, + options.retry_policy_max_attempts, options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, options.retry_policy_backoff_multiplier, not_instrumented); + otlp_http_client_options.max_concurrent_requests = 0; + return otlp_http_client_options; +} + +class OtlpHttpExporterCustomClientTestPeer : public ::testing::Test +{ +public: + std::unique_ptr GetExporter(std::unique_ptr http_client) + { + return std::unique_ptr(new OtlpHttpExporter(std::move(http_client))); + } + + static std::pair> + GetMockOtlpHttpClient() + { + auto http_client = http_client::HttpClientTestFactory::Create(); + return {new OtlpHttpClient(MakeOtlpHttpClientOptions(), http_client), http_client}; + } +}; + +TEST_F(OtlpHttpExporterCustomClientTestPeer, ExportCallsSendRequest) +{ + auto mock_otlp_client = GetMockOtlpHttpClient(); + auto client = mock_otlp_client.second; + auto exporter = GetExporter(std::unique_ptr{mock_otlp_client.first}); + + sdk::trace::BatchSpanProcessorOptions processor_opts; + processor_opts.max_export_batch_size = 5; + processor_opts.max_queue_size = 5; + processor_opts.schedule_delay_millis = std::chrono::milliseconds(256); + + auto processor = std::unique_ptr( + new sdk::trace::BatchSpanProcessor(std::move(exporter), processor_opts)); + auto provider = nostd::shared_ptr( + new sdk::trace::TracerProvider(std::move(processor))); + + auto tracer = provider->GetTracer("test"); + auto span = tracer->StartSpan("custom-client-span"); + span->End(); + + auto no_send_client = std::static_pointer_cast(client); + EXPECT_CALL(*std::static_pointer_cast(no_send_client->session_), + SendRequest) + .WillRepeatedly( + [](const std::shared_ptr &callback) { + http_client::nosend::Response response; + response.Finish(*callback); + }); + + provider->ForceFlush(); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif // OPENTELEMETRY_STL_VERSION diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index 8b4eb0f822..047de14e0c 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -23,9 +23,15 @@ set_target_version(opentelemetry_exporter_zipkin_trace) target_link_libraries( opentelemetry_exporter_zipkin_trace - PUBLIC opentelemetry_trace opentelemetry_http_client + PUBLIC opentelemetry_trace "$" nlohmann_json::nlohmann_json) +if(WITH_HTTP_CLIENT_CURL) + target_link_libraries( + opentelemetry_exporter_zipkin_trace + PUBLIC "$") +endif() + otel_add_component( COMPONENT exporters_zipkin @@ -62,19 +68,21 @@ if(BUILD_TESTING) TEST_PREFIX exporter. TEST_LIST zipkin_recordable_test) - add_executable(zipkin_exporter_test test/zipkin_exporter_test.cc) - - target_link_libraries( - zipkin_exporter_test - ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - ${GMOCK_LIB} - opentelemetry_exporter_zipkin_trace - opentelemetry_resources - CURL::libcurl) - - gtest_add_tests( - TARGET zipkin_exporter_test - TEST_PREFIX exporter. - TEST_LIST zipkin_exporter_test) + if(NOT WITH_CUSTOM_HTTP_CLIENT) + add_executable(zipkin_exporter_test test/zipkin_exporter_test.cc) + + target_link_libraries( + zipkin_exporter_test + ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ${GMOCK_LIB} + opentelemetry_exporter_zipkin_trace + opentelemetry_resources + CURL::libcurl) + + gtest_add_tests( + TARGET zipkin_exporter_test + TEST_PREFIX exporter. + TEST_LIST zipkin_exporter_test) + endif() endif() # BUILD_TESTING diff --git a/ext/src/CMakeLists.txt b/ext/src/CMakeLists.txt index 2c32c64cb8..f0f2619603 100644 --- a/ext/src/CMakeLists.txt +++ b/ext/src/CMakeLists.txt @@ -11,9 +11,8 @@ if(WITH_HTTP_CLIENT_CURL OR WITH_CUSTOM_HTTP_CLIENT) target_link_libraries(opentelemetry_http_client INTERFACE opentelemetry_http_client_curl) endif() - # When WITH_CUSTOM_HTTP_CLIENT=ON the target is intentionally left empty. The - # consumer populates it after add_subdirectory: - # target_link_libraries(opentelemetry_http_client INTERFACE my_impl) + # When WITH_CUSTOM_HTTP_CLIENT=ON the target is intentionally left empty; the + # consumer populates it with their own transport implementation. endif() if(DEFINED OPENTELEMETRY_BUILD_DLL) From 53debbee8389a499b901ce3c8817a01278d083c4 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Tue, 12 May 2026 20:33:10 +0000 Subject: [PATCH 05/22] Use WITH_HTTP_CLIENT_CURL=OFF --- CMakeLists.txt | 31 +++++-------------- examples/CMakeLists.txt | 2 +- examples/http/CMakeLists.txt | 2 +- exporters/otlp/CMakeLists.txt | 2 +- exporters/zipkin/CMakeLists.txt | 2 +- ext/src/CMakeLists.txt | 9 ++++-- .../CMakeLists.txt | 2 +- 7 files changed, 18 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92b5c1644d..c7aa42c791 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,9 +160,6 @@ option( option(WITH_CURL_LOGGING "Whether to enable select CURL verbosity in OTel logs" OFF) -option(WITH_CUSTOM_HTTP_CLIENT - "Enable a custom HTTP client instead of the default CURL backend" OFF) - option(WITH_ZIPKIN "Whether to include the Zipkin exporter in the SDK" OFF) option(WITH_PROMETHEUS "Whether to include the Prometheus Client in the SDK" @@ -277,26 +274,13 @@ include(GNUInstallDirs) # Do we need HTTP CLIENT CURL ? # -if(WITH_CUSTOM_HTTP_CLIENT) - set(WITH_HTTP_CLIENT_CURL OFF) - if(WITH_ZIPKIN OR WITH_ELASTICSEARCH) - message( - WARNING - "WITH_CUSTOM_HTTP_CLIENT=ON: opentelemetry_http_client INTERFACE is empty. " - "WITH_ZIPKIN and WITH_ELASTICSEARCH require you to populate it with your transport " - "implementation via target_link_libraries(opentelemetry_http_client INTERFACE )." - ) - endif() -elseif( - WITH_OTLP_HTTP - OR WITH_ELASTICSEARCH - OR WITH_ZIPKIN - OR BUILD_W3CTRACECONTEXT_TEST - OR WITH_EXAMPLES_HTTP) - set(WITH_HTTP_CLIENT_CURL ON) -else() - set(WITH_HTTP_CLIENT_CURL OFF) -endif() +include(CMakeDependentOption) +cmake_dependent_option( + WITH_HTTP_CLIENT_CURL + "Use the curl HTTP client backend. Defaults to ON when any HTTP exporter is enabled; set OFF to supply a custom transport." + ON + "WITH_OTLP_HTTP OR WITH_ELASTICSEARCH OR WITH_ZIPKIN OR BUILD_W3CTRACECONTEXT_TEST OR WITH_EXAMPLES_HTTP" + OFF) # # Do we need ZLIB ? @@ -515,7 +499,6 @@ message(STATUS "WITH_OTLP_GRPC: ${WITH_OTLP_GRPC}") message(STATUS "WITH_OTLP_HTTP: ${WITH_OTLP_HTTP}") message(STATUS "WITH_OTLP_FILE: ${WITH_OTLP_FILE}") message(STATUS "WITH_HTTP_CLIENT_CURL: ${WITH_HTTP_CLIENT_CURL}") -message(STATUS "WITH_CUSTOM_HTTP_CLIENT: ${WITH_CUSTOM_HTTP_CLIENT}") message(STATUS "WITH_ZIPKIN: ${WITH_ZIPKIN}") message(STATUS "WITH_PROMETHEUS: ${WITH_PROMETHEUS}") message(STATUS "WITH_ELASTICSEARCH: ${WITH_ELASTICSEARCH}") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index af7bd291ce..4c2f074154 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -34,7 +34,7 @@ if(WITH_EXAMPLES_HTTP) add_subdirectory(http) endif() -if(WITH_CUSTOM_HTTP_CLIENT AND WITH_OTLP_HTTP) +if(NOT WITH_HTTP_CLIENT_CURL AND WITH_OTLP_HTTP) add_subdirectory(custom_http_client) endif() diff --git a/examples/http/CMakeLists.txt b/examples/http/CMakeLists.txt index 218fc7a23e..ffc286354c 100644 --- a/examples/http/CMakeLists.txt +++ b/examples/http/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -if(NOT WITH_CUSTOM_HTTP_CLIENT) +if(WITH_HTTP_CLIENT_CURL) add_executable(http_client client.cc) add_executable(http_server server.cc) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 82cb68040a..8adc194ccb 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -1062,7 +1062,7 @@ if(BUILD_TESTING) TEST_PREFIX exporter.otlp. TEST_LIST otlp_http_metric_exporter_factory_test) - if(WITH_CUSTOM_HTTP_CLIENT) + if(NOT WITH_HTTP_CLIENT_CURL) add_executable( otlp_http_exporter_custom_client_test test/otlp_http_exporter_custom_client_test.cc diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index 047de14e0c..a0bfcb8713 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -68,7 +68,7 @@ if(BUILD_TESTING) TEST_PREFIX exporter. TEST_LIST zipkin_recordable_test) - if(NOT WITH_CUSTOM_HTTP_CLIENT) + if(WITH_HTTP_CLIENT_CURL) add_executable(zipkin_exporter_test test/zipkin_exporter_test.cc) target_link_libraries( diff --git a/ext/src/CMakeLists.txt b/ext/src/CMakeLists.txt index f0f2619603..c306755666 100644 --- a/ext/src/CMakeLists.txt +++ b/ext/src/CMakeLists.txt @@ -5,14 +5,17 @@ if(WITH_HTTP_CLIENT_CURL) add_subdirectory(http/client/curl) endif() -if(WITH_HTTP_CLIENT_CURL OR WITH_CUSTOM_HTTP_CLIENT) +if(WITH_HTTP_CLIENT_CURL + OR WITH_OTLP_HTTP + OR WITH_ELASTICSEARCH + OR WITH_ZIPKIN + OR BUILD_W3CTRACECONTEXT_TEST + OR WITH_EXAMPLES_HTTP) add_library(opentelemetry_http_client INTERFACE) if(WITH_HTTP_CLIENT_CURL) target_link_libraries(opentelemetry_http_client INTERFACE opentelemetry_http_client_curl) endif() - # When WITH_CUSTOM_HTTP_CLIENT=ON the target is intentionally left empty; the - # consumer populates it with their own transport implementation. endif() if(DEFINED OPENTELEMETRY_BUILD_DLL) diff --git a/ext/test/w3c_tracecontext_http_test_server/CMakeLists.txt b/ext/test/w3c_tracecontext_http_test_server/CMakeLists.txt index d441f7471b..064b186037 100644 --- a/ext/test/w3c_tracecontext_http_test_server/CMakeLists.txt +++ b/ext/test/w3c_tracecontext_http_test_server/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -if(NOT WITH_CUSTOM_HTTP_CLIENT) +if(WITH_HTTP_CLIENT_CURL) add_executable(w3c_tracecontext_http_test_server main.cc) target_link_libraries( w3c_tracecontext_http_test_server From 33f0e4d28ec37b9f972113114a2f0fec9a2dd490 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Tue, 12 May 2026 20:44:07 +0000 Subject: [PATCH 06/22] Improve the custom_http_client example --- .../custom_http_client/custom_http_client.cc | 73 ++++++++++++++++--- 1 file changed, 61 insertions(+), 12 deletions(-) diff --git a/examples/custom_http_client/custom_http_client.cc b/examples/custom_http_client/custom_http_client.cc index 8d8f451565..7e009db6ef 100644 --- a/examples/custom_http_client/custom_http_client.cc +++ b/examples/custom_http_client/custom_http_client.cc @@ -1,6 +1,9 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include + #include "opentelemetry/ext/http/client/http_client.h" #include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/sdk/common/thread_instrumentation.h" @@ -16,51 +19,97 @@ namespace client namespace { -class NoopRequest : public Request +class LoggingRequest : public Request { public: - void SetMethod(Method) noexcept override {} - void SetUri(nostd::string_view) noexcept override {} + void SetMethod(Method method) noexcept override + { + switch (method) + { + case Method::Get: + method_ = "GET"; + break; + case Method::Post: + method_ = "POST"; + break; + case Method::Put: + method_ = "PUT"; + break; + default: + method_ = "OTHER"; + break; + } + } + + void SetUri(nostd::string_view uri) noexcept override { uri_ = std::string(uri); } + + void SetBody(Body &body) noexcept override { body_size_ = body.size(); } + void SetSslOptions(const HttpSslOptions &) noexcept override {} - void SetBody(Body &) noexcept override {} void AddHeader(nostd::string_view, nostd::string_view) noexcept override {} void ReplaceHeader(nostd::string_view, nostd::string_view) noexcept override {} void SetTimeoutMs(std::chrono::milliseconds) noexcept override {} void SetCompression(const Compression &) noexcept override {} void EnableLogging(bool) noexcept override {} void SetRetryPolicy(const RetryPolicy &) noexcept override {} + + const std::string &GetMethod() const { return method_; } + const std::string &GetUri() const { return uri_; } + std::size_t GetBodySize() const { return body_size_; } + +private: + std::string method_; + std::string uri_; + std::size_t body_size_ = 0; +}; + +class OkResponse : public NoopResponse +{ +public: + StatusCode GetStatusCode() const noexcept override { return 200; } }; -class NoopSession : public Session +class LoggingSession : public Session { public: std::shared_ptr CreateRequest() noexcept override { - return std::make_shared(); + request_ = std::make_shared(); + return request_; } void SendRequest(std::shared_ptr handler) noexcept override { + if (request_) + { + std::cout << "Custom HTTP client: " << request_->GetMethod() << " " << request_->GetUri() + << " (" << request_->GetBodySize() << " bytes)\n"; + } if (!handler) { return; } - NoopResponse response; + OkResponse response; handler->OnResponse(response); handler->OnEvent(SessionState::Response, {}); + std::cout << "Custom HTTP client: export acknowledged\n"; } bool IsSessionActive() noexcept override { return false; } bool CancelSession() noexcept override { return true; } bool FinishSession() noexcept override { return true; } + +private: + std::shared_ptr request_; }; -class NoopHttpClient : public HttpClient +class LoggingHttpClient : public HttpClient { public: - std::shared_ptr CreateSession(nostd::string_view) noexcept override + std::shared_ptr CreateSession(nostd::string_view url) noexcept override { - return std::make_shared(); + std::cout << "Custom HTTP client: creating session for " << std::string(url) << "\n"; + return std::make_shared(); } bool CancelAllSessions() noexcept override { return true; } @@ -72,13 +121,13 @@ class NoopHttpClient : public HttpClient std::shared_ptr HttpClientFactory::Create() { - return std::make_shared(); + return std::make_shared(); } std::shared_ptr HttpClientFactory::Create( const std::shared_ptr &) { - return std::make_shared(); + return std::make_shared(); } std::shared_ptr HttpClientFactory::CreateSync() From fba51be5ac87ef17d368b171cf8abf3514a9ac21 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Wed, 13 May 2026 21:02:28 +0000 Subject: [PATCH 07/22] Link opentelemetry_exporter_otlp_http_client with CURL --- exporters/otlp/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 8adc194ccb..0678c5e248 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -325,6 +325,12 @@ if(WITH_OTLP_HTTP) opentelemetry_exporter_otlp_http_client PRIVATE "$" opentelemetry_common) + if(WITH_HTTP_CLIENT_CURL) + target_link_libraries( + opentelemetry_exporter_otlp_http_client + PRIVATE "$") + endif() + target_include_directories( opentelemetry_exporter_otlp_http_client PUBLIC "$" From 516c51b0e358dfb977dd6b32f7d69537706d50cc Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Wed, 13 May 2026 21:03:03 +0000 Subject: [PATCH 08/22] Include custom_http_client example only in build-time --- examples/CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 4c2f074154..566eb3a254 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -34,10 +34,12 @@ if(WITH_EXAMPLES_HTTP) add_subdirectory(http) endif() -if(NOT WITH_HTTP_CLIENT_CURL AND WITH_OTLP_HTTP) - add_subdirectory(custom_http_client) -endif() - if(WITH_CONFIGURATION) add_subdirectory(configuration) endif() + +# Build-tree only: depends on the opentelemetry_http_client INTERFACE target which +# is not exported in an installed package. +if(NOT WITH_HTTP_CLIENT_CURL AND WITH_OTLP_HTTP AND TARGET opentelemetry_http_client) + add_subdirectory(custom_http_client) +endif() From 235c5965516939f267c0fba733c9d983cdab5c9f Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Thu, 14 May 2026 17:58:10 +0000 Subject: [PATCH 09/22] Install http_client --- ci/do_ci.sh | 1 + examples/CMakeLists.txt | 4 +--- exporters/elasticsearch/CMakeLists.txt | 9 +-------- exporters/zipkin/CMakeLists.txt | 8 +------- ext/src/CMakeLists.txt | 4 ++++ .../component_tests/ext_http/CMakeLists.txt | 16 ++++++++++++++++ install/test/src/test_ext_http.cc | 13 +++++++++++++ 7 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 install/test/cmake/component_tests/ext_http/CMakeLists.txt create mode 100644 install/test/src/test_ext_http.cc diff --git a/ci/do_ci.sh b/ci/do_ci.sh index f1bb6d78e3..c6b85c988b 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -489,6 +489,7 @@ elif [[ "$1" == "cmake.install.test" ]]; then "sdk" "configuration" "ext_common" + "ext_http" "ext_http_curl" "exporters_in_memory" "exporters_ostream" diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 566eb3a254..604c498913 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -38,8 +38,6 @@ if(WITH_CONFIGURATION) add_subdirectory(configuration) endif() -# Build-tree only: depends on the opentelemetry_http_client INTERFACE target which -# is not exported in an installed package. -if(NOT WITH_HTTP_CLIENT_CURL AND WITH_OTLP_HTTP AND TARGET opentelemetry_http_client) +if(NOT WITH_HTTP_CLIENT_CURL AND WITH_OTLP_HTTP) add_subdirectory(custom_http_client) endif() diff --git a/exporters/elasticsearch/CMakeLists.txt b/exporters/elasticsearch/CMakeLists.txt index 556bab5617..cfd4ce01db 100644 --- a/exporters/elasticsearch/CMakeLists.txt +++ b/exporters/elasticsearch/CMakeLists.txt @@ -17,16 +17,9 @@ target_include_directories( target_link_libraries( opentelemetry_exporter_elasticsearch_logs - PUBLIC opentelemetry_trace opentelemetry_logs - "$" + PUBLIC opentelemetry_trace opentelemetry_logs opentelemetry_http_client nlohmann_json::nlohmann_json) -if(WITH_HTTP_CLIENT_CURL) - target_link_libraries( - opentelemetry_exporter_elasticsearch_logs - PUBLIC "$") -endif() - otel_add_component( COMPONENT exporters_elasticsearch diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index a0bfcb8713..2ba2ee7595 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -23,15 +23,9 @@ set_target_version(opentelemetry_exporter_zipkin_trace) target_link_libraries( opentelemetry_exporter_zipkin_trace - PUBLIC opentelemetry_trace "$" + PUBLIC opentelemetry_trace opentelemetry_http_client nlohmann_json::nlohmann_json) -if(WITH_HTTP_CLIENT_CURL) - target_link_libraries( - opentelemetry_exporter_zipkin_trace - PUBLIC "$") -endif() - otel_add_component( COMPONENT exporters_zipkin diff --git a/ext/src/CMakeLists.txt b/ext/src/CMakeLists.txt index c306755666..37a20fc7de 100644 --- a/ext/src/CMakeLists.txt +++ b/ext/src/CMakeLists.txt @@ -12,10 +12,14 @@ if(WITH_HTTP_CLIENT_CURL OR BUILD_W3CTRACECONTEXT_TEST OR WITH_EXAMPLES_HTTP) add_library(opentelemetry_http_client INTERFACE) + set_target_properties(opentelemetry_http_client PROPERTIES EXPORT_NAME + http_client) + target_link_libraries(opentelemetry_http_client INTERFACE opentelemetry_ext) if(WITH_HTTP_CLIENT_CURL) target_link_libraries(opentelemetry_http_client INTERFACE opentelemetry_http_client_curl) endif() + otel_add_component(COMPONENT ext_http TARGETS opentelemetry_http_client) endif() if(DEFINED OPENTELEMETRY_BUILD_DLL) diff --git a/install/test/cmake/component_tests/ext_http/CMakeLists.txt b/install/test/cmake/component_tests/ext_http/CMakeLists.txt new file mode 100644 index 0000000000..a4997abf3c --- /dev/null +++ b/install/test/cmake/component_tests/ext_http/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.16) +project(opentelemetry-cpp-ext_http-install-test LANGUAGES CXX) + +find_package(opentelemetry-cpp REQUIRED COMPONENTS ext_http) + +find_package(GTest CONFIG REQUIRED) +include(GoogleTest) + +add_executable(ext_http_test ${INSTALL_TEST_SRC_DIR}/test_ext_http.cc) +target_link_libraries(ext_http_test PRIVATE opentelemetry-cpp::http_client + GTest::gtest GTest::gtest_main) + +gtest_discover_tests(ext_http_test) diff --git a/install/test/src/test_ext_http.cc b/install/test/src/test_ext_http.cc new file mode 100644 index 0000000000..edce76bc08 --- /dev/null +++ b/install/test/src/test_ext_http.cc @@ -0,0 +1,13 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include + +TEST(ExtHttpInstall, Headers) +{ + using opentelemetry::ext::http::client::HttpClient; + using opentelemetry::ext::http::client::HttpClientSync; + SUCCEED(); +} From b8eb45ddcd450454129a907f9248ad2ddc2eceeb Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Thu, 14 May 2026 21:40:07 +0000 Subject: [PATCH 10/22] Make HttpClientFactory virtual --- examples/custom_http_client/CMakeLists.txt | 3 - .../custom_http_client/custom_http_client.cc | 14 +++- .../custom_http_client/custom_http_client.h | 31 ++++++++ examples/custom_http_client/main.cc | 9 ++- .../elasticsearch/es_log_record_exporter.h | 17 +++++ .../src/es_log_record_exporter.cc | 14 +++- exporters/otlp/CMakeLists.txt | 9 +-- .../exporters/otlp/otlp_http_client.h | 10 +++ .../exporters/otlp/otlp_http_exporter.h | 17 +++++ .../otlp/otlp_http_exporter_factory.h | 20 +++++ exporters/otlp/src/otlp_http_client.cc | 23 +++--- exporters/otlp/src/otlp_http_exporter.cc | 76 +++++++++++++++++++ .../otlp/src/otlp_http_exporter_factory.cc | 17 +++++ .../test/http_client_factory_nosend_stub.cc | 32 +++++--- .../exporters/zipkin/zipkin_exporter.h | 19 +++++ .../zipkin/zipkin_exporter_factory.h | 20 +++++ exporters/zipkin/src/zipkin_exporter.cc | 31 ++++---- .../zipkin/src/zipkin_exporter_factory.cc | 17 +++++ .../client/curl/http_client_factory_curl.h | 35 +++++++++ .../ext/http/client/http_client_factory.h | 18 ++++- ext/src/CMakeLists.txt | 5 +- .../client/curl/http_client_factory_curl.cc | 16 +++- .../test/cmake/examples_test/CMakeLists.txt | 1 + 23 files changed, 389 insertions(+), 65 deletions(-) create mode 100644 examples/custom_http_client/custom_http_client.h create mode 100644 ext/include/opentelemetry/ext/http/client/curl/http_client_factory_curl.h diff --git a/examples/custom_http_client/CMakeLists.txt b/examples/custom_http_client/CMakeLists.txt index 3c5a09d266..a727198fc4 100644 --- a/examples/custom_http_client/CMakeLists.txt +++ b/examples/custom_http_client/CMakeLists.txt @@ -5,9 +5,6 @@ add_library(custom_http_client_stub STATIC custom_http_client.cc) target_link_libraries(custom_http_client_stub PUBLIC opentelemetry_ext opentelemetry_sdk) -target_link_libraries(opentelemetry_http_client - INTERFACE custom_http_client_stub) - add_executable(example_custom_http_client main.cc) target_link_libraries( example_custom_http_client PRIVATE custom_http_client_stub diff --git a/examples/custom_http_client/custom_http_client.cc b/examples/custom_http_client/custom_http_client.cc index 7e009db6ef..f35edbd732 100644 --- a/examples/custom_http_client/custom_http_client.cc +++ b/examples/custom_http_client/custom_http_client.cc @@ -8,6 +8,8 @@ #include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/sdk/common/thread_instrumentation.h" +#include "custom_http_client.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace ext { @@ -119,22 +121,28 @@ class LoggingHttpClient : public HttpClient } // namespace -std::shared_ptr HttpClientFactory::Create() +std::shared_ptr LoggingHttpClientFactory::Create() { return std::make_shared(); } -std::shared_ptr HttpClientFactory::Create( +std::shared_ptr LoggingHttpClientFactory::Create( const std::shared_ptr &) { return std::make_shared(); } -std::shared_ptr HttpClientFactory::CreateSync() +std::shared_ptr LoggingHttpClientFactory::CreateSync() { return nullptr; } +std::shared_ptr GetDefaultHttpClientFactory() +{ + static auto instance = std::make_shared(); + return instance; +} + } // namespace client } // namespace http } // namespace ext diff --git a/examples/custom_http_client/custom_http_client.h b/examples/custom_http_client/custom_http_client.h new file mode 100644 index 0000000000..bbcb0d488f --- /dev/null +++ b/examples/custom_http_client/custom_http_client.h @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace ext +{ +namespace http +{ +namespace client +{ + +class LoggingHttpClientFactory : public HttpClientFactory +{ +public: + std::shared_ptr CreateSync() override; + std::shared_ptr Create() override; + std::shared_ptr Create( + const std::shared_ptr &thread_instrumentation) override; +}; + +} // namespace client +} // namespace http +} // namespace ext +OPENTELEMETRY_END_NAMESPACE diff --git a/examples/custom_http_client/main.cc b/examples/custom_http_client/main.cc index 7b50adfce3..bb8f8b106a 100644 --- a/examples/custom_http_client/main.cc +++ b/examples/custom_http_client/main.cc @@ -3,20 +3,23 @@ #include +#include "custom_http_client.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" -namespace trace_sdk = opentelemetry::sdk::trace; -namespace otlp = opentelemetry::exporter::otlp; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace otlp = opentelemetry::exporter::otlp; +namespace http_client = opentelemetry::ext::http::client; int main() { otlp::OtlpHttpExporterOptions options; options.url = "http://localhost:4318/v1/traces"; - auto exporter = otlp::OtlpHttpExporterFactory::Create(options); + auto factory = std::make_shared(); + auto exporter = otlp::OtlpHttpExporterFactory::Create(options, factory); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); std::shared_ptr provider = diff --git a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h index bf07bd1bc6..d52751cbe1 100644 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h @@ -9,6 +9,7 @@ #include #include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/common/exporter_utils.h" @@ -90,6 +91,22 @@ class ElasticsearchLogRecordExporter final : public opentelemetry::sdk::logs::Lo */ ElasticsearchLogRecordExporter(const ElasticsearchExporterOptions &options); + /** + * Create an ElasticsearchLogRecordExporter with user specified options and HTTP client factory. + * @param options An object containing the user's configuration options. + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + ElasticsearchLogRecordExporter(const ElasticsearchExporterOptions &options, + std::shared_ptr factory); + + /** + * Create an ElasticsearchLogRecordExporter with user specified options and HTTP client. + * @param options An object containing the user's configuration options. + * @param http_client the HTTP client to be used for exporting + */ + ElasticsearchLogRecordExporter(const ElasticsearchExporterOptions &options, + std::shared_ptr http_client); + /** * Creates a recordable that stores the data in a JSON object * @return a newly initialized Recordable object. diff --git a/exporters/elasticsearch/src/es_log_record_exporter.cc b/exporters/elasticsearch/src/es_log_record_exporter.cc index d617a1ac16..7f256d6074 100644 --- a/exporters/elasticsearch/src/es_log_record_exporter.cc +++ b/exporters/elasticsearch/src/es_log_record_exporter.cc @@ -322,8 +322,20 @@ ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter() ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter( const ElasticsearchExporterOptions &options) + : ElasticsearchLogRecordExporter(options, ext::http::client::GetDefaultHttpClientFactory()) +{} + +ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter( + const ElasticsearchExporterOptions &options, + std::shared_ptr factory) + : ElasticsearchLogRecordExporter(options, factory->Create()) +{} + +ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter( + const ElasticsearchExporterOptions &options, + std::shared_ptr http_client) : options_{options}, - http_client_{ext::http::client::HttpClientFactory::Create()} + http_client_{std::move(http_client)} #ifdef ENABLE_ASYNC_EXPORT , synchronization_data_(new SynchronizationData()) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 0678c5e248..0feb63fcaf 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -323,13 +323,8 @@ if(WITH_OTLP_HTTP) target_link_libraries( opentelemetry_exporter_otlp_http_client - PRIVATE "$" opentelemetry_common) - - if(WITH_HTTP_CLIENT_CURL) - target_link_libraries( - opentelemetry_exporter_otlp_http_client - PRIVATE "$") - endif() + PUBLIC opentelemetry_http_client + PRIVATE opentelemetry_common) target_include_directories( opentelemetry_exporter_otlp_http_client diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h index 15197cf4d6..40b558b588 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h @@ -17,6 +17,7 @@ #include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_http.h" #include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/common/exporter_utils.h" @@ -155,9 +156,18 @@ class OtlpHttpClient public: /** * Create an OtlpHttpClient using the given options. + * Uses the default HTTP client factory (curl when available). */ explicit OtlpHttpClient(OtlpHttpClientOptions &&options); + /** + * Create an OtlpHttpClient using the given options and HTTP client factory. + * @param options the Otlp http client options to be used for exporting + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + OtlpHttpClient(OtlpHttpClientOptions &&options, + std::shared_ptr factory); + /** * Create an OtlpHttpClient using the specified http client. * @param options the Otlp http client options to be used for exporting diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h index 6f2b019ae8..52c7c25932 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h @@ -9,6 +9,7 @@ #include "opentelemetry/exporters/otlp/otlp_http_client.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/common/exporter_utils.h" #include "opentelemetry/sdk/trace/exporter.h" @@ -43,6 +44,22 @@ class OPENTELEMETRY_EXPORT OtlpHttpExporter final : public opentelemetry::sdk::t OtlpHttpExporter(const OtlpHttpExporterOptions &options, const OtlpHttpExporterRuntimeOptions &runtime_options); + /** + * Create an OtlpHttpExporter using the given options and HTTP client factory. + * @param options the exporter options + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + OtlpHttpExporter(const OtlpHttpExporterOptions &options, + std::shared_ptr factory); + + /** + * Create an OtlpHttpExporter using the given options and HTTP client. + * @param options the exporter options + * @param http_client the HTTP client to be used for exporting + */ + OtlpHttpExporter(const OtlpHttpExporterOptions &options, + std::shared_ptr http_client); + /** * Create a span recordable. * @return a newly initialized Recordable object diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h index bf42d26354..987ba3780e 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h @@ -7,6 +7,8 @@ #include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/version.h" @@ -39,6 +41,24 @@ class OPENTELEMETRY_EXPORT OtlpHttpExporterFactory static std::unique_ptr Create( const OtlpHttpExporterOptions &options, const OtlpHttpExporterRuntimeOptions &runtime_options); + + /** + * Create an OtlpHttpExporter using the given options and HTTP client factory. + * @param options the exporter options + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + static std::unique_ptr Create( + const OtlpHttpExporterOptions &options, + std::shared_ptr factory); + + /** + * Create an OtlpHttpExporter using the given options and HTTP client. + * @param options the exporter options + * @param http_client the HTTP client to be used for exporting + */ + static std::unique_ptr Create( + const OtlpHttpExporterOptions &options, + std::shared_ptr http_client); }; } // namespace otlp diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index 77f4df3eed..f82ee66965 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -663,9 +663,19 @@ void ConvertListFieldToJson(nlohmann::json &value, } // namespace OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options) + : OtlpHttpClient(std::move(options), ext::http::client::GetDefaultHttpClientFactory()) +{} + +OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options, + std::shared_ptr factory) + : OtlpHttpClient(std::move(options), factory->Create(options.thread_instrumentation)) +{} + +OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options, + std::shared_ptr http_client) : is_shutdown_(false), options_(std::move(options)), - http_client_(http_client::HttpClientFactory::Create(options_.thread_instrumentation)), + http_client_(std::move(http_client)), start_session_counter_(0), finished_session_counter_(0) { @@ -704,17 +714,6 @@ OtlpHttpClient::~OtlpHttpClient() ; } -OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options, - std::shared_ptr http_client) - : is_shutdown_(false), - options_(std::move(options)), - http_client_(std::move(http_client)), - start_session_counter_(0), - finished_session_counter_(0) -{ - http_client_->SetMaxSessionsPerConnection(options_.max_requests_per_connection); -} - // ----------------------------- HTTP Client methods ------------------------------ opentelemetry::sdk::common::ExportResult OtlpHttpClient::Export( const google::protobuf::Message &message) noexcept diff --git a/exporters/otlp/src/otlp_http_exporter.cc b/exporters/otlp/src/otlp_http_exporter.cc index 499d577185..a6a923bbcb 100644 --- a/exporters/otlp/src/otlp_http_exporter.cc +++ b/exporters/otlp/src/otlp_http_exporter.cc @@ -115,6 +115,82 @@ OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, ))) {} +OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, + std::shared_ptr factory) + : options_(options), + runtime_options_(), + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + std::shared_ptr{nullptr} +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(factory))) +{} + +OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, + std::shared_ptr http_client) + : options_(options), + runtime_options_(), + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + std::shared_ptr{nullptr} +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(http_client))) +{} + OtlpHttpExporter::OtlpHttpExporter(std::unique_ptr http_client) : options_(OtlpHttpExporterOptions()), http_client_(std::move(http_client)) { diff --git a/exporters/otlp/src/otlp_http_exporter_factory.cc b/exporters/otlp/src/otlp_http_exporter_factory.cc index eca3552146..3fdea32b1c 100644 --- a/exporters/otlp/src/otlp_http_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_exporter_factory.cc @@ -5,6 +5,7 @@ #include "opentelemetry/exporters/otlp/otlp_http_exporter.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h" +#include "opentelemetry/ext/http/client/http_client.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -34,6 +35,22 @@ std::unique_ptr OtlpHttpExporterFactory return exporter; } +std::unique_ptr OtlpHttpExporterFactory::Create( + const OtlpHttpExporterOptions &options, + std::shared_ptr factory) +{ + return std::unique_ptr( + new OtlpHttpExporter(options, std::move(factory))); +} + +std::unique_ptr OtlpHttpExporterFactory::Create( + const OtlpHttpExporterOptions &options, + std::shared_ptr http_client) +{ + return std::unique_ptr( + new OtlpHttpExporter(options, std::move(http_client))); +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/test/http_client_factory_nosend_stub.cc b/exporters/otlp/test/http_client_factory_nosend_stub.cc index 2a6e344f02..ee573c020c 100644 --- a/exporters/otlp/test/http_client_factory_nosend_stub.cc +++ b/exporters/otlp/test/http_client_factory_nosend_stub.cc @@ -1,23 +1,35 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include + #include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" namespace http_client = opentelemetry::ext::http::client; -std::shared_ptr http_client::HttpClientFactory::Create() +namespace { - return std::make_shared(); -} - -std::shared_ptr http_client::HttpClientFactory::Create( - const std::shared_ptr &) +class NosendHttpClientFactory : public http_client::HttpClientFactory { - return std::make_shared(); -} +public: + std::shared_ptr Create() override + { + return std::make_shared(); + } + + std::shared_ptr Create( + const std::shared_ptr &) override + { + return std::make_shared(); + } + + std::shared_ptr CreateSync() override { return nullptr; } +}; +} // namespace -std::shared_ptr http_client::HttpClientFactory::CreateSync() +std::shared_ptr http_client::GetDefaultHttpClientFactory() { - return nullptr; + static auto instance = std::make_shared(); + return instance; } diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h index 19e7af9cf6..465b432fd1 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h @@ -11,6 +11,7 @@ #include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" #include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/ext/http/common/url_parser.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/common/exporter_utils.h" @@ -32,14 +33,32 @@ class ZipkinExporter final : public opentelemetry::sdk::trace::SpanExporter public: /** * Create a ZipkinExporter using all default options. + * Uses the default HTTP client factory (curl when available). */ ZipkinExporter(); /** * Create a ZipkinExporter using the given options. + * Uses the default HTTP client factory (curl when available). */ explicit ZipkinExporter(const ZipkinExporterOptions &options); + /** + * Create a ZipkinExporter using the given options and HTTP client factory. + * @param options the exporter options + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + ZipkinExporter(const ZipkinExporterOptions &options, + std::shared_ptr factory); + + /** + * Create a ZipkinExporter using the given options and HTTP client. + * @param options the exporter options + * @param http_client the HTTP client to be used for exporting + */ + ZipkinExporter(const ZipkinExporterOptions &options, + std::shared_ptr http_client); + /** * Create a span recordable. * @return a newly initialized Recordable object diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h index b1564a7977..64826b92c4 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h @@ -6,6 +6,8 @@ #include #include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/version.h" @@ -31,6 +33,24 @@ class ZipkinExporterFactory */ static std::unique_ptr Create( const ZipkinExporterOptions &options); + + /** + * Create a ZipkinExporter using the given options and HTTP client factory. + * @param options the exporter options + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + static std::unique_ptr Create( + const ZipkinExporterOptions &options, + std::shared_ptr factory); + + /** + * Create a ZipkinExporter using the given options and HTTP client. + * @param options the exporter options + * @param http_client the HTTP client to be used for exporting + */ + static std::unique_ptr Create( + const ZipkinExporterOptions &options, + std::shared_ptr http_client); }; } // namespace zipkin diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index f28e9f4d37..abc3157edc 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -36,30 +36,29 @@ namespace zipkin // -------------------------------- Constructors -------------------------------- ZipkinExporter::ZipkinExporter(const ZipkinExporterOptions &options) - : options_(options), - http_client_(ext::http::client::HttpClientFactory::CreateSync()), - url_parser_(options_.endpoint) -{ - InitializeLocalEndpoint(); -} + : ZipkinExporter(options, ext::http::client::GetDefaultHttpClientFactory()) +{} ZipkinExporter::ZipkinExporter() - : options_(ZipkinExporterOptions()), - http_client_(ext::http::client::HttpClientFactory::CreateSync()), - url_parser_(options_.endpoint) + : ZipkinExporter(ZipkinExporterOptions(), ext::http::client::GetDefaultHttpClientFactory()) +{} + +ZipkinExporter::ZipkinExporter(const ZipkinExporterOptions &options, + std::shared_ptr factory) + : ZipkinExporter(options, factory->CreateSync()) +{} + +ZipkinExporter::ZipkinExporter(const ZipkinExporterOptions &options, + std::shared_ptr http_client) + : options_(options), http_client_(std::move(http_client)), url_parser_(options_.endpoint) { InitializeLocalEndpoint(); } ZipkinExporter::ZipkinExporter( std::shared_ptr http_client) - : options_(ZipkinExporterOptions()), - http_client_(std::move(http_client)), - url_parser_(options_.endpoint) -{ - - InitializeLocalEndpoint(); -} + : ZipkinExporter(ZipkinExporterOptions(), std::move(http_client)) +{} // ----------------------------- Exporter methods ------------------------------ diff --git a/exporters/zipkin/src/zipkin_exporter_factory.cc b/exporters/zipkin/src/zipkin_exporter_factory.cc index edacb79842..e2ea38c761 100644 --- a/exporters/zipkin/src/zipkin_exporter_factory.cc +++ b/exporters/zipkin/src/zipkin_exporter_factory.cc @@ -5,6 +5,7 @@ #include "opentelemetry/exporters/zipkin/zipkin_exporter.h" #include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" #include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/version.h" namespace http_client = opentelemetry::ext::http::client; @@ -28,6 +29,22 @@ std::unique_ptr ZipkinExporterFactory:: return exporter; } +std::unique_ptr ZipkinExporterFactory::Create( + const ZipkinExporterOptions &options, + std::shared_ptr factory) +{ + return std::unique_ptr( + new ZipkinExporter(options, std::move(factory))); +} + +std::unique_ptr ZipkinExporterFactory::Create( + const ZipkinExporterOptions &options, + std::shared_ptr http_client) +{ + return std::unique_ptr( + new ZipkinExporter(options, std::move(http_client))); +} + } // namespace zipkin } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/ext/include/opentelemetry/ext/http/client/curl/http_client_factory_curl.h b/ext/include/opentelemetry/ext/http/client/curl/http_client_factory_curl.h new file mode 100644 index 0000000000..03dcabe739 --- /dev/null +++ b/ext/include/opentelemetry/ext/http/client/curl/http_client_factory_curl.h @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace ext +{ +namespace http +{ +namespace client +{ +namespace curl +{ + +class HttpCurlClientFactory : public HttpClientFactory +{ +public: + std::shared_ptr CreateSync() override; + + std::shared_ptr Create() override; + std::shared_ptr Create( + const std::shared_ptr &thread_instrumentation) override; +}; + +} // namespace curl +} // namespace client +} // namespace http +} // namespace ext +OPENTELEMETRY_END_NAMESPACE diff --git a/ext/include/opentelemetry/ext/http/client/http_client_factory.h b/ext/include/opentelemetry/ext/http/client/http_client_factory.h index c1a326b7e6..e33b836a08 100644 --- a/ext/include/opentelemetry/ext/http/client/http_client_factory.h +++ b/ext/include/opentelemetry/ext/http/client/http_client_factory.h @@ -3,6 +3,8 @@ #pragma once +#include + #include "opentelemetry/ext/http/client/http_client.h" #include "opentelemetry/sdk/common/thread_instrumentation.h" #include "opentelemetry/version.h" @@ -17,12 +19,20 @@ namespace client class HttpClientFactory { public: - static std::shared_ptr CreateSync(); + virtual ~HttpClientFactory() = default; + + virtual std::shared_ptr CreateSync() = 0; - static std::shared_ptr Create(); - static std::shared_ptr Create( - const std::shared_ptr &thread_instrumentation); + virtual std::shared_ptr Create() = 0; + virtual std::shared_ptr Create( + const std::shared_ptr &thread_instrumentation) = 0; }; + +// Returns an HttpCurlClientFactory instance when compiled with curl support. +// Not defined otherwise — binaries that link any exporter must provide their +// own definition or use the factory/client constructor overloads exclusively. +std::shared_ptr GetDefaultHttpClientFactory(); + } // namespace client } // namespace http } // namespace ext diff --git a/ext/src/CMakeLists.txt b/ext/src/CMakeLists.txt index 37a20fc7de..d984ce6a61 100644 --- a/ext/src/CMakeLists.txt +++ b/ext/src/CMakeLists.txt @@ -12,13 +12,14 @@ if(WITH_HTTP_CLIENT_CURL OR BUILD_W3CTRACECONTEXT_TEST OR WITH_EXAMPLES_HTTP) add_library(opentelemetry_http_client INTERFACE) - set_target_properties(opentelemetry_http_client PROPERTIES EXPORT_NAME - http_client) target_link_libraries(opentelemetry_http_client INTERFACE opentelemetry_ext) if(WITH_HTTP_CLIENT_CURL) target_link_libraries(opentelemetry_http_client INTERFACE opentelemetry_http_client_curl) endif() + + set_target_properties(opentelemetry_http_client PROPERTIES EXPORT_NAME + http_client) otel_add_component(COMPONENT ext_http TARGETS opentelemetry_http_client) endif() diff --git a/ext/src/http/client/curl/http_client_factory_curl.cc b/ext/src/http/client/curl/http_client_factory_curl.cc index b339c2d93c..5eb5fc7076 100644 --- a/ext/src/http/client/curl/http_client_factory_curl.cc +++ b/ext/src/http/client/curl/http_client_factory_curl.cc @@ -4,24 +4,32 @@ #include #include "opentelemetry/ext/http/client/curl/http_client_curl.h" +#include "opentelemetry/ext/http/client/curl/http_client_factory_curl.h" #include "opentelemetry/ext/http/client/http_client.h" #include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/sdk/common/thread_instrumentation.h" namespace http_client = opentelemetry::ext::http::client; -std::shared_ptr http_client::HttpClientFactory::Create() +std::shared_ptr http_client::curl::HttpCurlClientFactory::Create() { return std::make_shared(); } -std::shared_ptr http_client::HttpClientFactory::Create( - const std::shared_ptr &thread_instrumentation) +std::shared_ptr http_client::curl::HttpCurlClientFactory::Create( + const std::shared_ptr + &thread_instrumentation) { return std::make_shared(thread_instrumentation); } -std::shared_ptr http_client::HttpClientFactory::CreateSync() +std::shared_ptr http_client::curl::HttpCurlClientFactory::CreateSync() { return std::make_shared(); } + +std::shared_ptr http_client::GetDefaultHttpClientFactory() +{ + static auto instance = std::make_shared(); + return instance; +} diff --git a/install/test/cmake/examples_test/CMakeLists.txt b/install/test/cmake/examples_test/CMakeLists.txt index e9c11f5063..798a9124f2 100644 --- a/install/test/cmake/examples_test/CMakeLists.txt +++ b/install/test/cmake/examples_test/CMakeLists.txt @@ -48,6 +48,7 @@ endif() if("ext_http_curl" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED) set(WITH_EXAMPLES_HTTP ON) + set(WITH_HTTP_CLIENT_CURL ON) endif() if("configuration" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED) From b424e8607116e530ae8dc9aece18f49d8bfa78c5 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Fri, 15 May 2026 21:52:46 +0000 Subject: [PATCH 11/22] Fix http_client_factory_curl.h --- .../ext/http/client/curl/http_client_factory_curl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/include/opentelemetry/ext/http/client/curl/http_client_factory_curl.h b/ext/include/opentelemetry/ext/http/client/curl/http_client_factory_curl.h index 03dcabe739..d23caee948 100644 --- a/ext/include/opentelemetry/ext/http/client/curl/http_client_factory_curl.h +++ b/ext/include/opentelemetry/ext/http/client/curl/http_client_factory_curl.h @@ -21,10 +21,10 @@ namespace curl class HttpCurlClientFactory : public HttpClientFactory { public: - std::shared_ptr CreateSync() override; + std::shared_ptr CreateSync() override; - std::shared_ptr Create() override; - std::shared_ptr Create( + std::shared_ptr Create() override; + std::shared_ptr Create( const std::shared_ptr &thread_instrumentation) override; }; From 5695f7da47dee7390d5cecf8d66bfe8f56c0b25e Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Fri, 15 May 2026 21:54:07 +0000 Subject: [PATCH 12/22] Support HttpClientFactory in logs and metrics --- .../otlp/otlp_http_log_record_exporter.h | 17 ++++ .../otlp_http_log_record_exporter_factory.h | 20 +++++ .../otlp/otlp_http_metric_exporter.h | 17 ++++ .../otlp/otlp_http_metric_exporter_factory.h | 20 +++++ .../otlp/src/otlp_http_log_record_exporter.cc | 79 ++++++++++++++++++ .../otlp_http_log_record_exporter_factory.cc | 19 +++++ .../otlp/src/otlp_http_metric_exporter.cc | 83 +++++++++++++++++++ .../src/otlp_http_metric_exporter_factory.cc | 19 +++++ 8 files changed, 274 insertions(+) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h index aba430522e..cbb6eba486 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h @@ -9,6 +9,7 @@ #include "opentelemetry/exporters/otlp/otlp_http_client.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/common/exporter_utils.h" #include "opentelemetry/sdk/logs/exporter.h" @@ -46,6 +47,22 @@ class OtlpHttpLogRecordExporter final : public opentelemetry::sdk::logs::LogReco OtlpHttpLogRecordExporter(const OtlpHttpLogRecordExporterOptions &options, const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options); + /** + * Create an OtlpHttpLogRecordExporter with user specified options and HTTP client factory. + * @param options An object containing the user's configuration options. + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + OtlpHttpLogRecordExporter(const OtlpHttpLogRecordExporterOptions &options, + std::shared_ptr factory); + + /** + * Create an OtlpHttpLogRecordExporter with user specified options and HTTP client. + * @param options An object containing the user's configuration options. + * @param http_client the HTTP client to be used for exporting + */ + OtlpHttpLogRecordExporter(const OtlpHttpLogRecordExporterOptions &options, + std::shared_ptr http_client); + /** * Creates a recordable that stores the data in a JSON object */ diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h index d01eb4259a..d4d3554048 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h @@ -7,6 +7,8 @@ #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/sdk/logs/exporter.h" #include "opentelemetry/version.h" @@ -39,6 +41,24 @@ class OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterFactory static std::unique_ptr Create( const OtlpHttpLogRecordExporterOptions &options, const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options); + + /** + * Create a OtlpHttpLogRecordExporter using the given options and HTTP client factory. + * @param options the exporter options + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + static std::unique_ptr Create( + const OtlpHttpLogRecordExporterOptions &options, + std::shared_ptr factory); + + /** + * Create a OtlpHttpLogRecordExporter using the given options and HTTP client. + * @param options the exporter options + * @param http_client the HTTP client to be used for exporting + */ + static std::unique_ptr Create( + const OtlpHttpLogRecordExporterOptions &options, + std::shared_ptr http_client); }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h index 72774f3606..de7b822605 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h @@ -9,6 +9,7 @@ #include "opentelemetry/exporters/otlp/otlp_http_client.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/sdk/common/exporter_utils.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/instruments.h" @@ -45,6 +46,22 @@ class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::PushMet OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options, const OtlpHttpMetricExporterRuntimeOptions &runtime_options); + /** + * Create an OtlpHttpMetricExporter with user specified options and HTTP client factory. + * @param options An object containing the user's configuration options. + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options, + std::shared_ptr factory); + + /** + * Create an OtlpHttpMetricExporter with user specified options and HTTP client. + * @param options An object containing the user's configuration options. + * @param http_client the HTTP client to be used for exporting + */ + OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options, + std::shared_ptr http_client); + /** * Get the AggregationTemporality for exporter * diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h index cb026cbe1e..7601157914 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h @@ -7,6 +7,8 @@ #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" #include "opentelemetry/version.h" @@ -39,6 +41,24 @@ class OPENTELEMETRY_EXPORT OtlpHttpMetricExporterFactory static std::unique_ptr Create( const OtlpHttpMetricExporterOptions &options, const OtlpHttpMetricExporterRuntimeOptions &runtime_options); + + /** + * Create a OtlpHttpMetricExporter using the given options and HTTP client factory. + * @param options the exporter options + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + static std::unique_ptr Create( + const OtlpHttpMetricExporterOptions &options, + std::shared_ptr factory); + + /** + * Create a OtlpHttpMetricExporter using the given options and HTTP client. + * @param options the exporter options + * @param http_client the HTTP client to be used for exporting + */ + static std::unique_ptr Create( + const OtlpHttpMetricExporterOptions &options, + std::shared_ptr http_client); }; } // namespace otlp diff --git a/exporters/otlp/src/otlp_http_log_record_exporter.cc b/exporters/otlp/src/otlp_http_log_record_exporter.cc index b787ae3a46..6b730b2f37 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter.cc @@ -16,6 +16,7 @@ #include "opentelemetry/exporters/otlp/otlp_log_recordable.h" #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" #include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/exporter_utils.h" @@ -119,6 +120,84 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( ))) {} +OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( + const OtlpHttpLogRecordExporterOptions &options, + std::shared_ptr factory) + : options_(options), + runtime_options_(), + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + std::shared_ptr{nullptr} +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(factory))) +{} + +OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( + const OtlpHttpLogRecordExporterOptions &options, + std::shared_ptr http_client) + : options_(options), + runtime_options_(), + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + std::shared_ptr{nullptr} +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(http_client))) +{} + OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(std::unique_ptr http_client) : options_(OtlpHttpLogRecordExporterOptions()), http_client_(std::move(http_client)) { diff --git a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc index 54e78bf4e9..fb09c31757 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc @@ -5,6 +5,7 @@ #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h" +#include "opentelemetry/ext/http/client/http_client.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -36,6 +37,24 @@ OtlpHttpLogRecordExporterFactory::Create( return exporter; } +std::unique_ptr +OtlpHttpLogRecordExporterFactory::Create( + const OtlpHttpLogRecordExporterOptions &options, + std::shared_ptr factory) +{ + return std::unique_ptr( + new OtlpHttpLogRecordExporter(options, std::move(factory))); +} + +std::unique_ptr +OtlpHttpLogRecordExporterFactory::Create( + const OtlpHttpLogRecordExporterOptions &options, + std::shared_ptr http_client) +{ + return std::unique_ptr( + new OtlpHttpLogRecordExporter(options, std::move(http_client))); +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_metric_exporter.cc b/exporters/otlp/src/otlp_http_metric_exporter.cc index 40b3f04230..b69452736c 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter.cc @@ -16,6 +16,7 @@ #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h" #include "opentelemetry/exporters/otlp/otlp_metric_utils.h" #include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/exporter_utils.h" #include "opentelemetry/sdk/common/global_log_handler.h" @@ -122,6 +123,88 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter( ))) {} +OtlpHttpMetricExporter::OtlpHttpMetricExporter( + const OtlpHttpMetricExporterOptions &options, + std::shared_ptr factory) + : options_(options), + runtime_options_(), + aggregation_temporality_selector_{ + OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + std::shared_ptr{nullptr} +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(factory))) +{} + +OtlpHttpMetricExporter::OtlpHttpMetricExporter( + const OtlpHttpMetricExporterOptions &options, + std::shared_ptr http_client) + : options_(options), + runtime_options_(), + aggregation_temporality_selector_{ + OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + std::shared_ptr{nullptr} +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(http_client))) +{} + OtlpHttpMetricExporter::OtlpHttpMetricExporter(std::unique_ptr http_client) : options_(OtlpHttpMetricExporterOptions()), aggregation_temporality_selector_{ diff --git a/exporters/otlp/src/otlp_http_metric_exporter_factory.cc b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc index 1bd6d8a644..a9f8ace700 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc @@ -5,6 +5,7 @@ #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h" +#include "opentelemetry/ext/http/client/http_client.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -35,6 +36,24 @@ OtlpHttpMetricExporterFactory::Create(const OtlpHttpMetricExporterOptions &optio return exporter; } +std::unique_ptr +OtlpHttpMetricExporterFactory::Create( + const OtlpHttpMetricExporterOptions &options, + std::shared_ptr factory) +{ + return std::unique_ptr( + new OtlpHttpMetricExporter(options, std::move(factory))); +} + +std::unique_ptr +OtlpHttpMetricExporterFactory::Create( + const OtlpHttpMetricExporterOptions &options, + std::shared_ptr http_client) +{ + return std::unique_ptr( + new OtlpHttpMetricExporter(options, std::move(http_client))); +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE From db500303192c4064f76b88d5501ef385851034be Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Fri, 15 May 2026 21:55:18 +0000 Subject: [PATCH 13/22] Remove old HttpClientFactory calls --- examples/http/client.cc | 2 +- ext/test/http/curl_http_test.cc | 12 ++++++------ install/test/src/test_ext_http_curl.cc | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/http/client.cc b/examples/http/client.cc index 5f7a504d81..4736adbadf 100644 --- a/examples/http/client.cc +++ b/examples/http/client.cc @@ -40,7 +40,7 @@ namespace semconv = opentelemetry::semconv; void sendRequest(const std::string &url) { - auto http_client = http_client::HttpClientFactory::CreateSync(); + auto http_client = http_client::GetDefaultHttpClientFactory()->CreateSync(); // start active span StartSpanOptions options; diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index 2e2cf3d412..cd5e4c052d 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -276,7 +276,7 @@ TEST_F(BasicCurlHttpTests, HttpResponse) TEST_F(BasicCurlHttpTests, SendGetRequest) { received_requests_.clear(); - auto session_manager = http_client::HttpClientFactory::Create(); + auto session_manager = http_client::GetDefaultHttpClientFactory()->Create(); EXPECT_TRUE(session_manager != nullptr); auto session = session_manager->CreateSession("http://127.0.0.1:19000"); @@ -293,7 +293,7 @@ TEST_F(BasicCurlHttpTests, SendGetRequest) TEST_F(BasicCurlHttpTests, SendPostRequest) { received_requests_.clear(); - auto session_manager = http_client::HttpClientFactory::Create(); + auto session_manager = http_client::GetDefaultHttpClientFactory()->Create(); EXPECT_TRUE(session_manager != nullptr); auto session = session_manager->CreateSession("http://127.0.0.1:19000"); @@ -319,7 +319,7 @@ TEST_F(BasicCurlHttpTests, SendPostRequest) TEST_F(BasicCurlHttpTests, RequestTimeout) { received_requests_.clear(); - auto session_manager = http_client::HttpClientFactory::Create(); + auto session_manager = http_client::GetDefaultHttpClientFactory()->Create(); EXPECT_TRUE(session_manager != nullptr); auto session = session_manager->CreateSession("192.0.2.0:19000"); // RFC 5737 TEST-NET-1 @@ -655,7 +655,7 @@ TEST_F(BasicCurlHttpTests, FinishInAsyncCallback) TEST_F(BasicCurlHttpTests, ElegantQuitQuick) { - auto http_client = http_client::HttpClientFactory::Create(); + auto http_client = http_client::GetDefaultHttpClientFactory()->Create(); std::static_pointer_cast(http_client)->MaybeSpawnBackgroundThread(); // start background first, then test it could wakeup auto session = http_client->CreateSession("http://127.0.0.1:19000/get/"); @@ -721,7 +721,7 @@ struct GzipEventHandler : public CustomEventHandler TEST_F(BasicCurlHttpTests, GzipCompressibleData) { received_requests_.clear(); - auto session_manager = http_client::HttpClientFactory::Create(); + auto session_manager = http_client::GetDefaultHttpClientFactory()->Create(); EXPECT_TRUE(session_manager != nullptr); auto session = session_manager->CreateSession("http://127.0.0.1:19000"); @@ -755,7 +755,7 @@ TEST_F(BasicCurlHttpTests, GzipCompressibleData) TEST_F(BasicCurlHttpTests, GzipIncompressibleData) { received_requests_.clear(); - auto session_manager = http_client::HttpClientFactory::Create(); + auto session_manager = http_client::GetDefaultHttpClientFactory()->Create(); EXPECT_TRUE(session_manager != nullptr); auto session = session_manager->CreateSession("http://127.0.0.1:19000"); diff --git a/install/test/src/test_ext_http_curl.cc b/install/test/src/test_ext_http_curl.cc index 799ee4732a..e3b2316ddc 100644 --- a/install/test/src/test_ext_http_curl.cc +++ b/install/test/src/test_ext_http_curl.cc @@ -8,6 +8,6 @@ TEST(ExtHttpCurlInstall, HttpClient) { - auto client = opentelemetry::ext::http::client::HttpClientFactory::Create(); + auto client = opentelemetry::ext::http::client::GetDefaultHttpClientFactory()->Create(); ASSERT_TRUE(client != nullptr); } \ No newline at end of file From a790ade9799cefdbc3e61af71fca09e9cbbbf130 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Sat, 16 May 2026 16:49:32 +0000 Subject: [PATCH 14/22] Support options, runtime_options and factory in the Create method --- .../exporters/otlp/otlp_http_exporter.h | 20 +++++ .../otlp/otlp_http_exporter_factory.h | 22 +++++ .../otlp/otlp_http_log_record_exporter.h | 22 +++++ .../otlp_http_log_record_exporter_factory.h | 23 +++++ .../otlp/otlp_http_metric_exporter.h | 21 +++++ .../otlp/otlp_http_metric_exporter_factory.h | 23 +++++ exporters/otlp/src/otlp_http_exporter.cc | 78 +++++++++++++++++ .../otlp/src/otlp_http_exporter_factory.cc | 18 ++++ .../otlp/src/otlp_http_log_record_exporter.cc | 80 ++++++++++++++++++ .../otlp_http_log_record_exporter_factory.cc | 20 +++++ .../otlp/src/otlp_http_metric_exporter.cc | 84 +++++++++++++++++++ .../src/otlp_http_metric_exporter_factory.cc | 20 +++++ 12 files changed, 431 insertions(+) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h index 52c7c25932..e83c5b3504 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h @@ -52,6 +52,16 @@ class OPENTELEMETRY_EXPORT OtlpHttpExporter final : public opentelemetry::sdk::t OtlpHttpExporter(const OtlpHttpExporterOptions &options, std::shared_ptr factory); + /** + * Create an OtlpHttpExporter using the given options, runtime options, and HTTP client factory. + * @param options the exporter options + * @param runtime_options the runtime options (e.g. thread instrumentation) + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + OtlpHttpExporter(const OtlpHttpExporterOptions &options, + const OtlpHttpExporterRuntimeOptions &runtime_options, + std::shared_ptr factory); + /** * Create an OtlpHttpExporter using the given options and HTTP client. * @param options the exporter options @@ -60,6 +70,16 @@ class OPENTELEMETRY_EXPORT OtlpHttpExporter final : public opentelemetry::sdk::t OtlpHttpExporter(const OtlpHttpExporterOptions &options, std::shared_ptr http_client); + /** + * Create an OtlpHttpExporter using the given options, runtime options, and HTTP client. + * @param options the exporter options + * @param runtime_options the runtime options (e.g. thread instrumentation) + * @param http_client the HTTP client to be used for exporting + */ + OtlpHttpExporter(const OtlpHttpExporterOptions &options, + const OtlpHttpExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client); + /** * Create a span recordable. * @return a newly initialized Recordable object diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h index 987ba3780e..fd96ea8f7f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h @@ -51,6 +51,17 @@ class OPENTELEMETRY_EXPORT OtlpHttpExporterFactory const OtlpHttpExporterOptions &options, std::shared_ptr factory); + /** + * Create an OtlpHttpExporter using the given options, runtime options, and HTTP client factory. + * @param options the exporter options + * @param runtime_options the runtime options (e.g. thread instrumentation) + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + static std::unique_ptr Create( + const OtlpHttpExporterOptions &options, + const OtlpHttpExporterRuntimeOptions &runtime_options, + std::shared_ptr factory); + /** * Create an OtlpHttpExporter using the given options and HTTP client. * @param options the exporter options @@ -59,6 +70,17 @@ class OPENTELEMETRY_EXPORT OtlpHttpExporterFactory static std::unique_ptr Create( const OtlpHttpExporterOptions &options, std::shared_ptr http_client); + + /** + * Create an OtlpHttpExporter using the given options, runtime options, and HTTP client. + * @param options the exporter options + * @param runtime_options the runtime options (e.g. thread instrumentation) + * @param http_client the HTTP client to be used for exporting + */ + static std::unique_ptr Create( + const OtlpHttpExporterOptions &options, + const OtlpHttpExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client); }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h index cbb6eba486..80e3a85f2b 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h @@ -55,6 +55,17 @@ class OtlpHttpLogRecordExporter final : public opentelemetry::sdk::logs::LogReco OtlpHttpLogRecordExporter(const OtlpHttpLogRecordExporterOptions &options, std::shared_ptr factory); + /** + * Create an OtlpHttpLogRecordExporter with user specified options, runtime options, and HTTP + * client factory. + * @param options An object containing the user's configuration options. + * @param runtime_options An object containing the user's runtime options. + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + OtlpHttpLogRecordExporter(const OtlpHttpLogRecordExporterOptions &options, + const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, + std::shared_ptr factory); + /** * Create an OtlpHttpLogRecordExporter with user specified options and HTTP client. * @param options An object containing the user's configuration options. @@ -63,6 +74,17 @@ class OtlpHttpLogRecordExporter final : public opentelemetry::sdk::logs::LogReco OtlpHttpLogRecordExporter(const OtlpHttpLogRecordExporterOptions &options, std::shared_ptr http_client); + /** + * Create an OtlpHttpLogRecordExporter with user specified options, runtime options, and HTTP + * client. + * @param options An object containing the user's configuration options. + * @param runtime_options An object containing the user's runtime options. + * @param http_client the HTTP client to be used for exporting + */ + OtlpHttpLogRecordExporter(const OtlpHttpLogRecordExporterOptions &options, + const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client); + /** * Creates a recordable that stores the data in a JSON object */ diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h index d4d3554048..e38ea91872 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h @@ -51,6 +51,18 @@ class OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterFactory const OtlpHttpLogRecordExporterOptions &options, std::shared_ptr factory); + /** + * Create a OtlpHttpLogRecordExporter using the given options, runtime options, and HTTP client + * factory. + * @param options the exporter options + * @param runtime_options the runtime options (e.g. thread instrumentation) + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + static std::unique_ptr Create( + const OtlpHttpLogRecordExporterOptions &options, + const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, + std::shared_ptr factory); + /** * Create a OtlpHttpLogRecordExporter using the given options and HTTP client. * @param options the exporter options @@ -59,6 +71,17 @@ class OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterFactory static std::unique_ptr Create( const OtlpHttpLogRecordExporterOptions &options, std::shared_ptr http_client); + + /** + * Create a OtlpHttpLogRecordExporter using the given options, runtime options, and HTTP client. + * @param options the exporter options + * @param runtime_options the runtime options (e.g. thread instrumentation) + * @param http_client the HTTP client to be used for exporting + */ + static std::unique_ptr Create( + const OtlpHttpLogRecordExporterOptions &options, + const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client); }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h index de7b822605..2f764dc533 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h @@ -54,6 +54,17 @@ class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::PushMet OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options, std::shared_ptr factory); + /** + * Create an OtlpHttpMetricExporter with user specified options, runtime options, and HTTP client + * factory. + * @param options An object containing the user's configuration options. + * @param runtime_options An object containing the user's runtime options. + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options, + const OtlpHttpMetricExporterRuntimeOptions &runtime_options, + std::shared_ptr factory); + /** * Create an OtlpHttpMetricExporter with user specified options and HTTP client. * @param options An object containing the user's configuration options. @@ -62,6 +73,16 @@ class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::PushMet OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options, std::shared_ptr http_client); + /** + * Create an OtlpHttpMetricExporter with user specified options, runtime options, and HTTP client. + * @param options An object containing the user's configuration options. + * @param runtime_options An object containing the user's runtime options. + * @param http_client the HTTP client to be used for exporting + */ + OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options, + const OtlpHttpMetricExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client); + /** * Get the AggregationTemporality for exporter * diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h index 7601157914..544e258a5e 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h @@ -51,6 +51,18 @@ class OPENTELEMETRY_EXPORT OtlpHttpMetricExporterFactory const OtlpHttpMetricExporterOptions &options, std::shared_ptr factory); + /** + * Create a OtlpHttpMetricExporter using the given options, runtime options, and HTTP client + * factory. + * @param options the exporter options + * @param runtime_options the runtime options (e.g. thread instrumentation) + * @param factory the HTTP client factory used to create the underlying HTTP client + */ + static std::unique_ptr Create( + const OtlpHttpMetricExporterOptions &options, + const OtlpHttpMetricExporterRuntimeOptions &runtime_options, + std::shared_ptr factory); + /** * Create a OtlpHttpMetricExporter using the given options and HTTP client. * @param options the exporter options @@ -59,6 +71,17 @@ class OPENTELEMETRY_EXPORT OtlpHttpMetricExporterFactory static std::unique_ptr Create( const OtlpHttpMetricExporterOptions &options, std::shared_ptr http_client); + + /** + * Create a OtlpHttpMetricExporter using the given options, runtime options, and HTTP client. + * @param options the exporter options + * @param runtime_options the runtime options (e.g. thread instrumentation) + * @param http_client the HTTP client to be used for exporting + */ + static std::unique_ptr Create( + const OtlpHttpMetricExporterOptions &options, + const OtlpHttpMetricExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client); }; } // namespace otlp diff --git a/exporters/otlp/src/otlp_http_exporter.cc b/exporters/otlp/src/otlp_http_exporter.cc index a6a923bbcb..45b94b0429 100644 --- a/exporters/otlp/src/otlp_http_exporter.cc +++ b/exporters/otlp/src/otlp_http_exporter.cc @@ -153,6 +153,45 @@ OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, std::move(factory))) {} +OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, + const OtlpHttpExporterRuntimeOptions &runtime_options, + std::shared_ptr factory) + : options_(options), + runtime_options_(runtime_options), + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(factory))) +{} + OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, std::shared_ptr http_client) : options_(options), @@ -191,6 +230,45 @@ OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, std::move(http_client))) {} +OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, + const OtlpHttpExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client) + : options_(options), + runtime_options_(runtime_options), + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(http_client))) +{} + OtlpHttpExporter::OtlpHttpExporter(std::unique_ptr http_client) : options_(OtlpHttpExporterOptions()), http_client_(std::move(http_client)) { diff --git a/exporters/otlp/src/otlp_http_exporter_factory.cc b/exporters/otlp/src/otlp_http_exporter_factory.cc index 3fdea32b1c..6836aff508 100644 --- a/exporters/otlp/src/otlp_http_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_exporter_factory.cc @@ -43,6 +43,15 @@ std::unique_ptr OtlpHttpExporterFactory new OtlpHttpExporter(options, std::move(factory))); } +std::unique_ptr OtlpHttpExporterFactory::Create( + const OtlpHttpExporterOptions &options, + const OtlpHttpExporterRuntimeOptions &runtime_options, + std::shared_ptr factory) +{ + return std::unique_ptr( + new OtlpHttpExporter(options, runtime_options, std::move(factory))); +} + std::unique_ptr OtlpHttpExporterFactory::Create( const OtlpHttpExporterOptions &options, std::shared_ptr http_client) @@ -51,6 +60,15 @@ std::unique_ptr OtlpHttpExporterFactory new OtlpHttpExporter(options, std::move(http_client))); } +std::unique_ptr OtlpHttpExporterFactory::Create( + const OtlpHttpExporterOptions &options, + const OtlpHttpExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client) +{ + return std::unique_ptr( + new OtlpHttpExporter(options, runtime_options, std::move(http_client))); +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_log_record_exporter.cc b/exporters/otlp/src/otlp_http_log_record_exporter.cc index 6b730b2f37..43196afc88 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter.cc @@ -159,6 +159,46 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( std::move(factory))) {} +OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( + const OtlpHttpLogRecordExporterOptions &options, + const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, + std::shared_ptr factory) + : options_(options), + runtime_options_(runtime_options), + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(factory))) +{} + OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( const OtlpHttpLogRecordExporterOptions &options, std::shared_ptr http_client) @@ -198,6 +238,46 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( std::move(http_client))) {} +OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( + const OtlpHttpLogRecordExporterOptions &options, + const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client) + : options_(options), + runtime_options_(runtime_options), + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(http_client))) +{} + OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(std::unique_ptr http_client) : options_(OtlpHttpLogRecordExporterOptions()), http_client_(std::move(http_client)) { diff --git a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc index fb09c31757..cc14facdbf 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc @@ -46,6 +46,16 @@ OtlpHttpLogRecordExporterFactory::Create( new OtlpHttpLogRecordExporter(options, std::move(factory))); } +std::unique_ptr +OtlpHttpLogRecordExporterFactory::Create( + const OtlpHttpLogRecordExporterOptions &options, + const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, + std::shared_ptr factory) +{ + return std::unique_ptr( + new OtlpHttpLogRecordExporter(options, runtime_options, std::move(factory))); +} + std::unique_ptr OtlpHttpLogRecordExporterFactory::Create( const OtlpHttpLogRecordExporterOptions &options, @@ -55,6 +65,16 @@ OtlpHttpLogRecordExporterFactory::Create( new OtlpHttpLogRecordExporter(options, std::move(http_client))); } +std::unique_ptr +OtlpHttpLogRecordExporterFactory::Create( + const OtlpHttpLogRecordExporterOptions &options, + const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client) +{ + return std::unique_ptr( + new OtlpHttpLogRecordExporter(options, runtime_options, std::move(http_client))); +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_metric_exporter.cc b/exporters/otlp/src/otlp_http_metric_exporter.cc index b69452736c..ca856e1f53 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter.cc @@ -164,6 +164,48 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter( std::move(factory))) {} +OtlpHttpMetricExporter::OtlpHttpMetricExporter( + const OtlpHttpMetricExporterOptions &options, + const OtlpHttpMetricExporterRuntimeOptions &runtime_options, + std::shared_ptr factory) + : options_(options), + runtime_options_(runtime_options), + aggregation_temporality_selector_{ + OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(factory))) +{} + OtlpHttpMetricExporter::OtlpHttpMetricExporter( const OtlpHttpMetricExporterOptions &options, std::shared_ptr http_client) @@ -205,6 +247,48 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter( std::move(http_client))) {} +OtlpHttpMetricExporter::OtlpHttpMetricExporter( + const OtlpHttpMetricExporterOptions &options, + const OtlpHttpMetricExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client) + : options_(options), + runtime_options_(runtime_options), + aggregation_temporality_selector_{ + OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, + http_client_(new OtlpHttpClient( + OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation +#ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +#endif + ), + std::move(http_client))) +{} + OtlpHttpMetricExporter::OtlpHttpMetricExporter(std::unique_ptr http_client) : options_(OtlpHttpMetricExporterOptions()), aggregation_temporality_selector_{ diff --git a/exporters/otlp/src/otlp_http_metric_exporter_factory.cc b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc index a9f8ace700..46d20b73f1 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc @@ -45,6 +45,16 @@ OtlpHttpMetricExporterFactory::Create( new OtlpHttpMetricExporter(options, std::move(factory))); } +std::unique_ptr +OtlpHttpMetricExporterFactory::Create( + const OtlpHttpMetricExporterOptions &options, + const OtlpHttpMetricExporterRuntimeOptions &runtime_options, + std::shared_ptr factory) +{ + return std::unique_ptr( + new OtlpHttpMetricExporter(options, runtime_options, std::move(factory))); +} + std::unique_ptr OtlpHttpMetricExporterFactory::Create( const OtlpHttpMetricExporterOptions &options, @@ -54,6 +64,16 @@ OtlpHttpMetricExporterFactory::Create( new OtlpHttpMetricExporter(options, std::move(http_client))); } +std::unique_ptr +OtlpHttpMetricExporterFactory::Create( + const OtlpHttpMetricExporterOptions &options, + const OtlpHttpMetricExporterRuntimeOptions &runtime_options, + std::shared_ptr http_client) +{ + return std::unique_ptr( + new OtlpHttpMetricExporter(options, runtime_options, std::move(http_client))); +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE From 864d7069fff4ea8d465e486fa41fca98c555c291 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Sat, 16 May 2026 16:54:57 +0000 Subject: [PATCH 15/22] Add unit tests --- exporters/otlp/CMakeLists.txt | 30 ++++- exporters/otlp/src/otlp_http_exporter.cc | 118 +++++++++--------- .../otlp/src/otlp_http_log_record_exporter.cc | 118 +++++++++--------- .../otlp/src/otlp_http_metric_exporter.cc | 118 +++++++++--------- .../otlp_http_exporter_custom_client_test.cc | 37 ++++++ ..._log_record_exporter_custom_client_test.cc | 60 +++++++++ ...http_metric_exporter_custom_client_test.cc | 60 +++++++++ 7 files changed, 360 insertions(+), 181 deletions(-) create mode 100644 exporters/otlp/test/otlp_http_log_record_exporter_custom_client_test.cc create mode 100644 exporters/otlp/test/otlp_http_metric_exporter_custom_client_test.cc diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 0feb63fcaf..07f9a48149 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -1067,7 +1067,6 @@ if(BUILD_TESTING) add_executable( otlp_http_exporter_custom_client_test test/otlp_http_exporter_custom_client_test.cc - # Provides HttpClientFactory::Create() without touching the INTERFACE. test/http_client_factory_nosend_stub.cc) target_link_libraries( otlp_http_exporter_custom_client_test ${GTEST_BOTH_LIBRARIES} @@ -1077,6 +1076,35 @@ if(BUILD_TESTING) TARGET otlp_http_exporter_custom_client_test TEST_PREFIX exporter.otlp. TEST_LIST otlp_http_exporter_custom_client_test) + + add_executable( + otlp_http_metric_exporter_custom_client_test + test/otlp_http_metric_exporter_custom_client_test.cc + test/http_client_factory_nosend_stub.cc) + target_link_libraries( + otlp_http_metric_exporter_custom_client_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_otlp_http_metric + opentelemetry_metrics opentelemetry_http_client_nosend) + gtest_add_tests( + TARGET otlp_http_metric_exporter_custom_client_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_metric_exporter_custom_client_test) + + add_executable( + otlp_http_log_record_exporter_custom_client_test + test/otlp_http_log_record_exporter_custom_client_test.cc + test/http_client_factory_nosend_stub.cc) + target_link_libraries( + otlp_http_log_record_exporter_custom_client_test + ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + opentelemetry_exporter_otlp_http_log + opentelemetry_logs + opentelemetry_http_client_nosend) + gtest_add_tests( + TARGET otlp_http_log_record_exporter_custom_client_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_log_record_exporter_custom_client_test) endif() endif() diff --git a/exporters/otlp/src/otlp_http_exporter.cc b/exporters/otlp/src/otlp_http_exporter.cc index 45b94b0429..b1b342878b 100644 --- a/exporters/otlp/src/otlp_http_exporter.cc +++ b/exporters/otlp/src/otlp_http_exporter.cc @@ -158,38 +158,37 @@ OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, std::shared_ptr factory) : options_(options), runtime_options_(runtime_options), - http_client_(new OtlpHttpClient( - OtlpHttpClientOptions(options.url, - options.ssl_insecure_skip_verify, - options.ssl_ca_cert_path, - options.ssl_ca_cert_string, - options.ssl_client_key_path, - options.ssl_client_key_string, - options.ssl_client_cert_path, - options.ssl_client_cert_string, - options.ssl_min_tls, - options.ssl_max_tls, - options.ssl_cipher, - options.ssl_cipher_suite, - options.content_type, - options.json_bytes_mapping, - options.compression, - options.use_json_name, - options.console_debug, - options.timeout, - options.http_headers, - options.retry_policy_max_attempts, - options.retry_policy_initial_backoff, - options.retry_policy_max_backoff, - options.retry_policy_backoff_multiplier, - runtime_options.thread_instrumentation + http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation #ifdef ENABLE_ASYNC_EXPORT - , - options.max_concurrent_requests, - options.max_requests_per_connection + , + options.max_concurrent_requests, + options.max_requests_per_connection #endif - ), - std::move(factory))) + ), + std::move(factory))) {} OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, @@ -235,38 +234,37 @@ OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, std::shared_ptr http_client) : options_(options), runtime_options_(runtime_options), - http_client_(new OtlpHttpClient( - OtlpHttpClientOptions(options.url, - options.ssl_insecure_skip_verify, - options.ssl_ca_cert_path, - options.ssl_ca_cert_string, - options.ssl_client_key_path, - options.ssl_client_key_string, - options.ssl_client_cert_path, - options.ssl_client_cert_string, - options.ssl_min_tls, - options.ssl_max_tls, - options.ssl_cipher, - options.ssl_cipher_suite, - options.content_type, - options.json_bytes_mapping, - options.compression, - options.use_json_name, - options.console_debug, - options.timeout, - options.http_headers, - options.retry_policy_max_attempts, - options.retry_policy_initial_backoff, - options.retry_policy_max_backoff, - options.retry_policy_backoff_multiplier, - runtime_options.thread_instrumentation + http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation #ifdef ENABLE_ASYNC_EXPORT - , - options.max_concurrent_requests, - options.max_requests_per_connection + , + options.max_concurrent_requests, + options.max_requests_per_connection #endif - ), - std::move(http_client))) + ), + std::move(http_client))) {} OtlpHttpExporter::OtlpHttpExporter(std::unique_ptr http_client) diff --git a/exporters/otlp/src/otlp_http_log_record_exporter.cc b/exporters/otlp/src/otlp_http_log_record_exporter.cc index 43196afc88..cf7d1768c5 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter.cc @@ -165,38 +165,37 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( std::shared_ptr factory) : options_(options), runtime_options_(runtime_options), - http_client_(new OtlpHttpClient( - OtlpHttpClientOptions(options.url, - options.ssl_insecure_skip_verify, - options.ssl_ca_cert_path, - options.ssl_ca_cert_string, - options.ssl_client_key_path, - options.ssl_client_key_string, - options.ssl_client_cert_path, - options.ssl_client_cert_string, - options.ssl_min_tls, - options.ssl_max_tls, - options.ssl_cipher, - options.ssl_cipher_suite, - options.content_type, - options.json_bytes_mapping, - options.compression, - options.use_json_name, - options.console_debug, - options.timeout, - options.http_headers, - options.retry_policy_max_attempts, - options.retry_policy_initial_backoff, - options.retry_policy_max_backoff, - options.retry_policy_backoff_multiplier, - runtime_options.thread_instrumentation + http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation #ifdef ENABLE_ASYNC_EXPORT - , - options.max_concurrent_requests, - options.max_requests_per_connection + , + options.max_concurrent_requests, + options.max_requests_per_connection #endif - ), - std::move(factory))) + ), + std::move(factory))) {} OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( @@ -244,38 +243,37 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( std::shared_ptr http_client) : options_(options), runtime_options_(runtime_options), - http_client_(new OtlpHttpClient( - OtlpHttpClientOptions(options.url, - options.ssl_insecure_skip_verify, - options.ssl_ca_cert_path, - options.ssl_ca_cert_string, - options.ssl_client_key_path, - options.ssl_client_key_string, - options.ssl_client_cert_path, - options.ssl_client_cert_string, - options.ssl_min_tls, - options.ssl_max_tls, - options.ssl_cipher, - options.ssl_cipher_suite, - options.content_type, - options.json_bytes_mapping, - options.compression, - options.use_json_name, - options.console_debug, - options.timeout, - options.http_headers, - options.retry_policy_max_attempts, - options.retry_policy_initial_backoff, - options.retry_policy_max_backoff, - options.retry_policy_backoff_multiplier, - runtime_options.thread_instrumentation + http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation #ifdef ENABLE_ASYNC_EXPORT - , - options.max_concurrent_requests, - options.max_requests_per_connection + , + options.max_concurrent_requests, + options.max_requests_per_connection #endif - ), - std::move(http_client))) + ), + std::move(http_client))) {} OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(std::unique_ptr http_client) diff --git a/exporters/otlp/src/otlp_http_metric_exporter.cc b/exporters/otlp/src/otlp_http_metric_exporter.cc index ca856e1f53..6ed72ca6bf 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter.cc @@ -172,38 +172,37 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter( runtime_options_(runtime_options), aggregation_temporality_selector_{ OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, - http_client_(new OtlpHttpClient( - OtlpHttpClientOptions(options.url, - options.ssl_insecure_skip_verify, - options.ssl_ca_cert_path, - options.ssl_ca_cert_string, - options.ssl_client_key_path, - options.ssl_client_key_string, - options.ssl_client_cert_path, - options.ssl_client_cert_string, - options.ssl_min_tls, - options.ssl_max_tls, - options.ssl_cipher, - options.ssl_cipher_suite, - options.content_type, - options.json_bytes_mapping, - options.compression, - options.use_json_name, - options.console_debug, - options.timeout, - options.http_headers, - options.retry_policy_max_attempts, - options.retry_policy_initial_backoff, - options.retry_policy_max_backoff, - options.retry_policy_backoff_multiplier, - runtime_options.thread_instrumentation + http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation #ifdef ENABLE_ASYNC_EXPORT - , - options.max_concurrent_requests, - options.max_requests_per_connection + , + options.max_concurrent_requests, + options.max_requests_per_connection #endif - ), - std::move(factory))) + ), + std::move(factory))) {} OtlpHttpMetricExporter::OtlpHttpMetricExporter( @@ -255,38 +254,37 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter( runtime_options_(runtime_options), aggregation_temporality_selector_{ OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, - http_client_(new OtlpHttpClient( - OtlpHttpClientOptions(options.url, - options.ssl_insecure_skip_verify, - options.ssl_ca_cert_path, - options.ssl_ca_cert_string, - options.ssl_client_key_path, - options.ssl_client_key_string, - options.ssl_client_cert_path, - options.ssl_client_cert_string, - options.ssl_min_tls, - options.ssl_max_tls, - options.ssl_cipher, - options.ssl_cipher_suite, - options.content_type, - options.json_bytes_mapping, - options.compression, - options.use_json_name, - options.console_debug, - options.timeout, - options.http_headers, - options.retry_policy_max_attempts, - options.retry_policy_initial_backoff, - options.retry_policy_max_backoff, - options.retry_policy_backoff_multiplier, - runtime_options.thread_instrumentation + http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url, + options.ssl_insecure_skip_verify, + options.ssl_ca_cert_path, + options.ssl_ca_cert_string, + options.ssl_client_key_path, + options.ssl_client_key_string, + options.ssl_client_cert_path, + options.ssl_client_cert_string, + options.ssl_min_tls, + options.ssl_max_tls, + options.ssl_cipher, + options.ssl_cipher_suite, + options.content_type, + options.json_bytes_mapping, + options.compression, + options.use_json_name, + options.console_debug, + options.timeout, + options.http_headers, + options.retry_policy_max_attempts, + options.retry_policy_initial_backoff, + options.retry_policy_max_backoff, + options.retry_policy_backoff_multiplier, + runtime_options.thread_instrumentation #ifdef ENABLE_ASYNC_EXPORT - , - options.max_concurrent_requests, - options.max_requests_per_connection + , + options.max_concurrent_requests, + options.max_requests_per_connection #endif - ), - std::move(http_client))) + ), + std::move(http_client))) {} OtlpHttpMetricExporter::OtlpHttpMetricExporter(std::unique_ptr http_client) diff --git a/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc b/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc index 0568735da0..41336e2b88 100644 --- a/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc @@ -7,7 +7,10 @@ # include "opentelemetry/exporters/otlp/otlp_http_client.h" # include "opentelemetry/exporters/otlp/otlp_http_exporter.h" +# include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" # include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" +# include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h" +# include "opentelemetry/ext/http/client/http_client_factory.h" # include "opentelemetry/sdk/trace/batch_span_processor.h" # include "opentelemetry/sdk/trace/batch_span_processor_options.h" # include "opentelemetry/sdk/trace/tracer_provider.h" @@ -73,6 +76,40 @@ class OtlpHttpExporterCustomClientTestPeer : public ::testing::Test } }; +TEST_F(OtlpHttpExporterCustomClientTestPeer, FactoryInjectionCreatesExporter) +{ + OtlpHttpExporterOptions opts; + auto factory = http_client::GetDefaultHttpClientFactory(); + auto exporter = OtlpHttpExporterFactory::Create(opts, std::move(factory)); + ASSERT_NE(exporter, nullptr); +} + +TEST_F(OtlpHttpExporterCustomClientTestPeer, HttpClientInjectionCreatesExporter) +{ + OtlpHttpExporterOptions opts; + auto client = http_client::HttpClientTestFactory::Create(); + auto exporter = OtlpHttpExporterFactory::Create(opts, std::move(client)); + ASSERT_NE(exporter, nullptr); +} + +TEST_F(OtlpHttpExporterCustomClientTestPeer, RuntimeOptionsWithFactoryCreatesExporter) +{ + OtlpHttpExporterOptions opts; + OtlpHttpExporterRuntimeOptions runtime_opts; + auto factory = http_client::GetDefaultHttpClientFactory(); + auto exporter = OtlpHttpExporterFactory::Create(opts, runtime_opts, std::move(factory)); + ASSERT_NE(exporter, nullptr); +} + +TEST_F(OtlpHttpExporterCustomClientTestPeer, RuntimeOptionsWithHttpClientCreatesExporter) +{ + OtlpHttpExporterOptions opts; + OtlpHttpExporterRuntimeOptions runtime_opts; + auto client = http_client::HttpClientTestFactory::Create(); + auto exporter = OtlpHttpExporterFactory::Create(opts, runtime_opts, std::move(client)); + ASSERT_NE(exporter, nullptr); +} + TEST_F(OtlpHttpExporterCustomClientTestPeer, ExportCallsSendRequest) { auto mock_otlp_client = GetMockOtlpHttpClient(); diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_custom_client_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_custom_client_test.cc new file mode 100644 index 0000000000..b56cad5c3b --- /dev/null +++ b/exporters/otlp/test/otlp_http_log_record_exporter_custom_client_test.cc @@ -0,0 +1,60 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef OPENTELEMETRY_STL_VERSION + +# include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h" +# include "opentelemetry/ext/http/client/http_client_factory.h" +# include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h" + +# include + +namespace http_client = opentelemetry::ext::http::client; + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +TEST(OtlpHttpLogRecordExporterCustomClientTest, FactoryInjectionCreatesExporter) +{ + OtlpHttpLogRecordExporterOptions opts; + auto factory = http_client::GetDefaultHttpClientFactory(); + auto exporter = OtlpHttpLogRecordExporterFactory::Create(opts, std::move(factory)); + ASSERT_NE(exporter, nullptr); +} + +TEST(OtlpHttpLogRecordExporterCustomClientTest, HttpClientInjectionCreatesExporter) +{ + OtlpHttpLogRecordExporterOptions opts; + auto client = http_client::HttpClientTestFactory::Create(); + auto exporter = OtlpHttpLogRecordExporterFactory::Create(opts, std::move(client)); + ASSERT_NE(exporter, nullptr); +} + +TEST(OtlpHttpLogRecordExporterCustomClientTest, RuntimeOptionsWithFactoryCreatesExporter) +{ + OtlpHttpLogRecordExporterOptions opts; + OtlpHttpLogRecordExporterRuntimeOptions runtime_opts; + auto factory = http_client::GetDefaultHttpClientFactory(); + auto exporter = OtlpHttpLogRecordExporterFactory::Create(opts, runtime_opts, std::move(factory)); + ASSERT_NE(exporter, nullptr); +} + +TEST(OtlpHttpLogRecordExporterCustomClientTest, RuntimeOptionsWithHttpClientCreatesExporter) +{ + OtlpHttpLogRecordExporterOptions opts; + OtlpHttpLogRecordExporterRuntimeOptions runtime_opts; + auto client = http_client::HttpClientTestFactory::Create(); + auto exporter = OtlpHttpLogRecordExporterFactory::Create(opts, runtime_opts, std::move(client)); + ASSERT_NE(exporter, nullptr); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif // OPENTELEMETRY_STL_VERSION diff --git a/exporters/otlp/test/otlp_http_metric_exporter_custom_client_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_custom_client_test.cc new file mode 100644 index 0000000000..abb498a75d --- /dev/null +++ b/exporters/otlp/test/otlp_http_metric_exporter_custom_client_test.cc @@ -0,0 +1,60 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef OPENTELEMETRY_STL_VERSION + +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h" +# include "opentelemetry/ext/http/client/http_client_factory.h" +# include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h" + +# include + +namespace http_client = opentelemetry::ext::http::client; + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +TEST(OtlpHttpMetricExporterCustomClientTest, FactoryInjectionCreatesExporter) +{ + OtlpHttpMetricExporterOptions opts; + auto factory = http_client::GetDefaultHttpClientFactory(); + auto exporter = OtlpHttpMetricExporterFactory::Create(opts, std::move(factory)); + ASSERT_NE(exporter, nullptr); +} + +TEST(OtlpHttpMetricExporterCustomClientTest, HttpClientInjectionCreatesExporter) +{ + OtlpHttpMetricExporterOptions opts; + auto client = http_client::HttpClientTestFactory::Create(); + auto exporter = OtlpHttpMetricExporterFactory::Create(opts, std::move(client)); + ASSERT_NE(exporter, nullptr); +} + +TEST(OtlpHttpMetricExporterCustomClientTest, RuntimeOptionsWithFactoryCreatesExporter) +{ + OtlpHttpMetricExporterOptions opts; + OtlpHttpMetricExporterRuntimeOptions runtime_opts; + auto factory = http_client::GetDefaultHttpClientFactory(); + auto exporter = OtlpHttpMetricExporterFactory::Create(opts, runtime_opts, std::move(factory)); + ASSERT_NE(exporter, nullptr); +} + +TEST(OtlpHttpMetricExporterCustomClientTest, RuntimeOptionsWithHttpClientCreatesExporter) +{ + OtlpHttpMetricExporterOptions opts; + OtlpHttpMetricExporterRuntimeOptions runtime_opts; + auto client = http_client::HttpClientTestFactory::Create(); + auto exporter = OtlpHttpMetricExporterFactory::Create(opts, runtime_opts, std::move(client)); + ASSERT_NE(exporter, nullptr); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif // OPENTELEMETRY_STL_VERSION From 316a8ba35a80ac11b46108241d7091945a20e814 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Sat, 16 May 2026 22:16:35 +0000 Subject: [PATCH 16/22] Fix warnings --- .../exporters/elasticsearch/es_log_record_exporter.h | 2 +- exporters/elasticsearch/src/es_log_record_exporter.cc | 2 +- .../include/opentelemetry/exporters/otlp/otlp_http_client.h | 2 +- exporters/otlp/src/otlp_http_client.cc | 2 +- .../opentelemetry/exporters/zipkin/zipkin_exporter.h | 2 +- exporters/zipkin/src/zipkin_exporter.cc | 2 +- .../opentelemetry/ext/http/client/http_client_factory.h | 6 ++++++ 7 files changed, 12 insertions(+), 6 deletions(-) diff --git a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h index d52751cbe1..80de4455e5 100644 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h @@ -97,7 +97,7 @@ class ElasticsearchLogRecordExporter final : public opentelemetry::sdk::logs::Lo * @param factory the HTTP client factory used to create the underlying HTTP client */ ElasticsearchLogRecordExporter(const ElasticsearchExporterOptions &options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create an ElasticsearchLogRecordExporter with user specified options and HTTP client. diff --git a/exporters/elasticsearch/src/es_log_record_exporter.cc b/exporters/elasticsearch/src/es_log_record_exporter.cc index 7f256d6074..7a74d79480 100644 --- a/exporters/elasticsearch/src/es_log_record_exporter.cc +++ b/exporters/elasticsearch/src/es_log_record_exporter.cc @@ -327,7 +327,7 @@ ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter( ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter( const ElasticsearchExporterOptions &options, - std::shared_ptr factory) + const std::shared_ptr &factory) : ElasticsearchLogRecordExporter(options, factory->Create()) {} diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h index 40b558b588..e273c5da57 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h @@ -166,7 +166,7 @@ class OtlpHttpClient * @param factory the HTTP client factory used to create the underlying HTTP client */ OtlpHttpClient(OtlpHttpClientOptions &&options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create an OtlpHttpClient using the specified http client. diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index f82ee66965..4a3452e44d 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -667,7 +667,7 @@ OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options) {} OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options, - std::shared_ptr factory) + const std::shared_ptr &factory) : OtlpHttpClient(std::move(options), factory->Create(options.thread_instrumentation)) {} diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h index 465b432fd1..16e862f208 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h @@ -49,7 +49,7 @@ class ZipkinExporter final : public opentelemetry::sdk::trace::SpanExporter * @param factory the HTTP client factory used to create the underlying HTTP client */ ZipkinExporter(const ZipkinExporterOptions &options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create a ZipkinExporter using the given options and HTTP client. diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index abc3157edc..15766e7170 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -44,7 +44,7 @@ ZipkinExporter::ZipkinExporter() {} ZipkinExporter::ZipkinExporter(const ZipkinExporterOptions &options, - std::shared_ptr factory) + const std::shared_ptr &factory) : ZipkinExporter(options, factory->CreateSync()) {} diff --git a/ext/include/opentelemetry/ext/http/client/http_client_factory.h b/ext/include/opentelemetry/ext/http/client/http_client_factory.h index e33b836a08..4ea37e7bac 100644 --- a/ext/include/opentelemetry/ext/http/client/http_client_factory.h +++ b/ext/include/opentelemetry/ext/http/client/http_client_factory.h @@ -19,6 +19,12 @@ namespace client class HttpClientFactory { public: + HttpClientFactory() = default; + HttpClientFactory(const HttpClientFactory &) = delete; + HttpClientFactory(HttpClientFactory &&) = delete; + HttpClientFactory &operator=(const HttpClientFactory &) = delete; + HttpClientFactory &operator=(HttpClientFactory &&) = delete; + virtual ~HttpClientFactory() = default; virtual std::shared_ptr CreateSync() = 0; From e30851355e2e4081e1b564978d89020171eb75c3 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Sat, 16 May 2026 22:53:23 +0000 Subject: [PATCH 17/22] Increase test coverage --- .../test/es_log_record_exporter_test.cc | 8 ++ exporters/otlp/CMakeLists.txt | 78 +++++++++---------- .../test/http_client_factory_nosend_stub.cc | 35 --------- .../otlp_http_exporter_custom_client_test.cc | 7 +- ..._log_record_exporter_custom_client_test.cc | 8 +- ...http_metric_exporter_custom_client_test.cc | 8 +- exporters/zipkin/CMakeLists.txt | 1 + exporters/zipkin/test/zipkin_exporter_test.cc | 20 +++++ .../nosend/http_client_factory_nosend.h | 48 ++++++++++++ 9 files changed, 129 insertions(+), 84 deletions(-) delete mode 100644 exporters/otlp/test/http_client_factory_nosend_stub.cc create mode 100644 test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_factory_nosend.h diff --git a/exporters/elasticsearch/test/es_log_record_exporter_test.cc b/exporters/elasticsearch/test/es_log_record_exporter_test.cc index c0ee47299e..79d0cc61f5 100644 --- a/exporters/elasticsearch/test/es_log_record_exporter_test.cc +++ b/exporters/elasticsearch/test/es_log_record_exporter_test.cc @@ -25,6 +25,14 @@ namespace logs_api = opentelemetry::logs; namespace nostd = opentelemetry::nostd; namespace logs_exporter = opentelemetry::exporter::logs; +TEST(ElasticsearchLogsExporterTests, CustomClientConstructionSucceeds) +{ + logs_exporter::ElasticsearchExporterOptions opts; + auto exporter = std::unique_ptr( + new logs_exporter::ElasticsearchLogRecordExporter(opts)); + ASSERT_NE(exporter, nullptr); +} + // Attempt to write a log to an invalid host/port, test that the Export() returns failure TEST(DISABLED_ElasticsearchLogsExporterTests, InvalidEndpoint) { diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 07f9a48149..b863645ea1 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -1063,49 +1063,41 @@ if(BUILD_TESTING) TEST_PREFIX exporter.otlp. TEST_LIST otlp_http_metric_exporter_factory_test) - if(NOT WITH_HTTP_CLIENT_CURL) - add_executable( - otlp_http_exporter_custom_client_test - test/otlp_http_exporter_custom_client_test.cc - test/http_client_factory_nosend_stub.cc) - target_link_libraries( - otlp_http_exporter_custom_client_test ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} opentelemetry_exporter_otlp_http - opentelemetry_http_client_nosend) - gtest_add_tests( - TARGET otlp_http_exporter_custom_client_test - TEST_PREFIX exporter.otlp. - TEST_LIST otlp_http_exporter_custom_client_test) - - add_executable( - otlp_http_metric_exporter_custom_client_test - test/otlp_http_metric_exporter_custom_client_test.cc - test/http_client_factory_nosend_stub.cc) - target_link_libraries( - otlp_http_metric_exporter_custom_client_test ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_otlp_http_metric - opentelemetry_metrics opentelemetry_http_client_nosend) - gtest_add_tests( - TARGET otlp_http_metric_exporter_custom_client_test - TEST_PREFIX exporter.otlp. - TEST_LIST otlp_http_metric_exporter_custom_client_test) - - add_executable( - otlp_http_log_record_exporter_custom_client_test - test/otlp_http_log_record_exporter_custom_client_test.cc - test/http_client_factory_nosend_stub.cc) - target_link_libraries( - otlp_http_log_record_exporter_custom_client_test - ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - opentelemetry_exporter_otlp_http_log - opentelemetry_logs - opentelemetry_http_client_nosend) - gtest_add_tests( - TARGET otlp_http_log_record_exporter_custom_client_test - TEST_PREFIX exporter.otlp. - TEST_LIST otlp_http_log_record_exporter_custom_client_test) - endif() + add_executable(otlp_http_exporter_custom_client_test + test/otlp_http_exporter_custom_client_test.cc) + target_link_libraries( + otlp_http_exporter_custom_client_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} opentelemetry_exporter_otlp_http + opentelemetry_http_client_nosend) + gtest_add_tests( + TARGET otlp_http_exporter_custom_client_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_exporter_custom_client_test) + + add_executable(otlp_http_metric_exporter_custom_client_test + test/otlp_http_metric_exporter_custom_client_test.cc) + target_link_libraries( + otlp_http_metric_exporter_custom_client_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_otlp_http_metric + opentelemetry_metrics opentelemetry_http_client_nosend) + gtest_add_tests( + TARGET otlp_http_metric_exporter_custom_client_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_metric_exporter_custom_client_test) + + add_executable(otlp_http_log_record_exporter_custom_client_test + test/otlp_http_log_record_exporter_custom_client_test.cc) + target_link_libraries( + otlp_http_log_record_exporter_custom_client_test + ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + opentelemetry_exporter_otlp_http_log + opentelemetry_logs + opentelemetry_http_client_nosend) + gtest_add_tests( + TARGET otlp_http_log_record_exporter_custom_client_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_log_record_exporter_custom_client_test) endif() if(WITH_OTLP_FILE) diff --git a/exporters/otlp/test/http_client_factory_nosend_stub.cc b/exporters/otlp/test/http_client_factory_nosend_stub.cc deleted file mode 100644 index ee573c020c..0000000000 --- a/exporters/otlp/test/http_client_factory_nosend_stub.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#include - -#include "opentelemetry/ext/http/client/http_client_factory.h" -#include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" - -namespace http_client = opentelemetry::ext::http::client; - -namespace -{ -class NosendHttpClientFactory : public http_client::HttpClientFactory -{ -public: - std::shared_ptr Create() override - { - return std::make_shared(); - } - - std::shared_ptr Create( - const std::shared_ptr &) override - { - return std::make_shared(); - } - - std::shared_ptr CreateSync() override { return nullptr; } -}; -} // namespace - -std::shared_ptr http_client::GetDefaultHttpClientFactory() -{ - static auto instance = std::make_shared(); - return instance; -} diff --git a/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc b/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc index 41336e2b88..e90088be7b 100644 --- a/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc @@ -15,6 +15,7 @@ # include "opentelemetry/sdk/trace/batch_span_processor_options.h" # include "opentelemetry/sdk/trace/tracer_provider.h" # include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h" +# include "opentelemetry/test_common/ext/http/client/nosend/http_client_factory_nosend.h" # include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" # include @@ -29,6 +30,8 @@ namespace otlp { namespace http_client = opentelemetry::ext::http::client; +using NosendHttpClientFactory = + opentelemetry::test_common::ext::http::client::nosend::HttpClientFactoryNosend; static OtlpHttpClientOptions MakeOtlpHttpClientOptions() { @@ -79,7 +82,7 @@ class OtlpHttpExporterCustomClientTestPeer : public ::testing::Test TEST_F(OtlpHttpExporterCustomClientTestPeer, FactoryInjectionCreatesExporter) { OtlpHttpExporterOptions opts; - auto factory = http_client::GetDefaultHttpClientFactory(); + auto factory = std::make_shared(); auto exporter = OtlpHttpExporterFactory::Create(opts, std::move(factory)); ASSERT_NE(exporter, nullptr); } @@ -96,7 +99,7 @@ TEST_F(OtlpHttpExporterCustomClientTestPeer, RuntimeOptionsWithFactoryCreatesExp { OtlpHttpExporterOptions opts; OtlpHttpExporterRuntimeOptions runtime_opts; - auto factory = http_client::GetDefaultHttpClientFactory(); + auto factory = std::make_shared(); auto exporter = OtlpHttpExporterFactory::Create(opts, runtime_opts, std::move(factory)); ASSERT_NE(exporter, nullptr); } diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_custom_client_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_custom_client_test.cc index b56cad5c3b..82645ab3e1 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_custom_client_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_custom_client_test.cc @@ -8,6 +8,7 @@ # include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h" # include "opentelemetry/ext/http/client/http_client_factory.h" # include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h" +# include "opentelemetry/test_common/ext/http/client/nosend/http_client_factory_nosend.h" # include @@ -19,10 +20,13 @@ namespace exporter namespace otlp { +using NosendHttpClientFactory = + opentelemetry::test_common::ext::http::client::nosend::HttpClientFactoryNosend; + TEST(OtlpHttpLogRecordExporterCustomClientTest, FactoryInjectionCreatesExporter) { OtlpHttpLogRecordExporterOptions opts; - auto factory = http_client::GetDefaultHttpClientFactory(); + auto factory = std::make_shared(); auto exporter = OtlpHttpLogRecordExporterFactory::Create(opts, std::move(factory)); ASSERT_NE(exporter, nullptr); } @@ -39,7 +43,7 @@ TEST(OtlpHttpLogRecordExporterCustomClientTest, RuntimeOptionsWithFactoryCreates { OtlpHttpLogRecordExporterOptions opts; OtlpHttpLogRecordExporterRuntimeOptions runtime_opts; - auto factory = http_client::GetDefaultHttpClientFactory(); + auto factory = std::make_shared(); auto exporter = OtlpHttpLogRecordExporterFactory::Create(opts, runtime_opts, std::move(factory)); ASSERT_NE(exporter, nullptr); } diff --git a/exporters/otlp/test/otlp_http_metric_exporter_custom_client_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_custom_client_test.cc index abb498a75d..58cbfe28e8 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_custom_client_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_custom_client_test.cc @@ -8,6 +8,7 @@ # include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h" # include "opentelemetry/ext/http/client/http_client_factory.h" # include "opentelemetry/test_common/ext/http/client/http_client_test_factory.h" +# include "opentelemetry/test_common/ext/http/client/nosend/http_client_factory_nosend.h" # include @@ -19,10 +20,13 @@ namespace exporter namespace otlp { +using NosendHttpClientFactory = + opentelemetry::test_common::ext::http::client::nosend::HttpClientFactoryNosend; + TEST(OtlpHttpMetricExporterCustomClientTest, FactoryInjectionCreatesExporter) { OtlpHttpMetricExporterOptions opts; - auto factory = http_client::GetDefaultHttpClientFactory(); + auto factory = std::make_shared(); auto exporter = OtlpHttpMetricExporterFactory::Create(opts, std::move(factory)); ASSERT_NE(exporter, nullptr); } @@ -39,7 +43,7 @@ TEST(OtlpHttpMetricExporterCustomClientTest, RuntimeOptionsWithFactoryCreatesExp { OtlpHttpMetricExporterOptions opts; OtlpHttpMetricExporterRuntimeOptions runtime_opts; - auto factory = http_client::GetDefaultHttpClientFactory(); + auto factory = std::make_shared(); auto exporter = OtlpHttpMetricExporterFactory::Create(opts, runtime_opts, std::move(factory)); ASSERT_NE(exporter, nullptr); } diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index 2ba2ee7595..b90b1177ce 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -72,6 +72,7 @@ if(BUILD_TESTING) ${GMOCK_LIB} opentelemetry_exporter_zipkin_trace opentelemetry_resources + opentelemetry_http_client_nosend CURL::libcurl) gtest_add_tests( diff --git a/exporters/zipkin/test/zipkin_exporter_test.cc b/exporters/zipkin/test/zipkin_exporter_test.cc index 36a78edf9c..6964695629 100644 --- a/exporters/zipkin/test/zipkin_exporter_test.cc +++ b/exporters/zipkin/test/zipkin_exporter_test.cc @@ -4,11 +4,13 @@ #ifndef OPENTELEMETRY_STL_VERSION # include "opentelemetry/exporters/zipkin/zipkin_exporter.h" +# include "opentelemetry/exporters/zipkin/zipkin_exporter_factory.h" # include "opentelemetry/ext/http/client/curl/http_client_curl.h" # include "opentelemetry/ext/http/server/http_server.h" # include "opentelemetry/sdk/trace/batch_span_processor.h" # include "opentelemetry/sdk/trace/batch_span_processor_options.h" # include "opentelemetry/sdk/trace/tracer_provider.h" +# include "opentelemetry/test_common/ext/http/client/nosend/http_client_factory_nosend.h" # include "opentelemetry/trace/provider.h" # include @@ -224,6 +226,24 @@ TEST_F(ZipkinExporterTestPeer, ConfigFromEnv) # endif // NO_GETENV +TEST_F(ZipkinExporterTestPeer, FactoryInjectionCreatesExporter) +{ + ZipkinExporterOptions opts; + auto factory = std::make_shared< + opentelemetry::test_common::ext::http::client::nosend::HttpClientFactoryNosend>(); + auto exporter = ZipkinExporterFactory::Create(opts, std::move(factory)); + ASSERT_NE(exporter, nullptr); +} + +TEST_F(ZipkinExporterTestPeer, HttpClientSyncInjectionCreatesExporter) +{ + ZipkinExporterOptions opts; + auto client = std::shared_ptr( + new MockHttpClient); + auto exporter = ZipkinExporterFactory::Create(opts, std::move(client)); + ASSERT_NE(exporter, nullptr); +} + } // namespace zipkin } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_factory_nosend.h b/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_factory_nosend.h new file mode 100644 index 0000000000..7a71b24db5 --- /dev/null +++ b/test_common/include/opentelemetry/test_common/ext/http/client/nosend/http_client_factory_nosend.h @@ -0,0 +1,48 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/test_common/ext/http/client/nosend/http_client_nosend.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace test_common +{ +namespace ext +{ +namespace http +{ +namespace client +{ +namespace nosend +{ + +class HttpClientFactoryNosend : public opentelemetry::ext::http::client::HttpClientFactory +{ +public: + std::shared_ptr Create() override + { + return std::make_shared(); + } + + std::shared_ptr Create( + const std::shared_ptr &) override + { + return std::make_shared(); + } + + std::shared_ptr CreateSync() override + { + return nullptr; + } +}; + +} // namespace nosend +} // namespace client +} // namespace http +} // namespace ext +} // namespace test_common +OPENTELEMETRY_END_NAMESPACE From 2dd13e4e24d465c7029233691ac29e7a8934a243 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Sat, 16 May 2026 23:10:35 +0000 Subject: [PATCH 18/22] Fix formatting --- .../exporters/elasticsearch/es_log_record_exporter.h | 5 +++-- exporters/otlp/CMakeLists.txt | 9 +++------ .../opentelemetry/exporters/zipkin/zipkin_exporter.h | 5 +++-- exporters/zipkin/test/zipkin_exporter_test.cc | 6 +++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h index 80de4455e5..3d51639f24 100644 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h @@ -96,8 +96,9 @@ class ElasticsearchLogRecordExporter final : public opentelemetry::sdk::logs::Lo * @param options An object containing the user's configuration options. * @param factory the HTTP client factory used to create the underlying HTTP client */ - ElasticsearchLogRecordExporter(const ElasticsearchExporterOptions &options, - const std::shared_ptr &factory); + ElasticsearchLogRecordExporter( + const ElasticsearchExporterOptions &options, + const std::shared_ptr &factory); /** * Create an ElasticsearchLogRecordExporter with user specified options and HTTP client. diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index b863645ea1..1d2852dc73 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -1088,12 +1088,9 @@ if(BUILD_TESTING) add_executable(otlp_http_log_record_exporter_custom_client_test test/otlp_http_log_record_exporter_custom_client_test.cc) target_link_libraries( - otlp_http_log_record_exporter_custom_client_test - ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - opentelemetry_exporter_otlp_http_log - opentelemetry_logs - opentelemetry_http_client_nosend) + otlp_http_log_record_exporter_custom_client_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_otlp_http_log + opentelemetry_logs opentelemetry_http_client_nosend) gtest_add_tests( TARGET otlp_http_log_record_exporter_custom_client_test TEST_PREFIX exporter.otlp. diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h index 16e862f208..cb4d8f099b 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h @@ -48,8 +48,9 @@ class ZipkinExporter final : public opentelemetry::sdk::trace::SpanExporter * @param options the exporter options * @param factory the HTTP client factory used to create the underlying HTTP client */ - ZipkinExporter(const ZipkinExporterOptions &options, - const std::shared_ptr &factory); + ZipkinExporter( + const ZipkinExporterOptions &options, + const std::shared_ptr &factory); /** * Create a ZipkinExporter using the given options and HTTP client. diff --git a/exporters/zipkin/test/zipkin_exporter_test.cc b/exporters/zipkin/test/zipkin_exporter_test.cc index 6964695629..086357c07f 100644 --- a/exporters/zipkin/test/zipkin_exporter_test.cc +++ b/exporters/zipkin/test/zipkin_exporter_test.cc @@ -229,7 +229,7 @@ TEST_F(ZipkinExporterTestPeer, ConfigFromEnv) TEST_F(ZipkinExporterTestPeer, FactoryInjectionCreatesExporter) { ZipkinExporterOptions opts; - auto factory = std::make_shared< + auto factory = std::make_shared< opentelemetry::test_common::ext::http::client::nosend::HttpClientFactoryNosend>(); auto exporter = ZipkinExporterFactory::Create(opts, std::move(factory)); ASSERT_NE(exporter, nullptr); @@ -238,8 +238,8 @@ TEST_F(ZipkinExporterTestPeer, FactoryInjectionCreatesExporter) TEST_F(ZipkinExporterTestPeer, HttpClientSyncInjectionCreatesExporter) { ZipkinExporterOptions opts; - auto client = std::shared_ptr( - new MockHttpClient); + auto client = + std::shared_ptr(new MockHttpClient); auto exporter = ZipkinExporterFactory::Create(opts, std::move(client)); ASSERT_NE(exporter, nullptr); } From 9c3dd331e47f9034236f9f42e05acd94f1f2bdba Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Sun, 17 May 2026 06:01:37 +0000 Subject: [PATCH 19/22] Fix Bazel --- exporters/zipkin/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/exporters/zipkin/BUILD b/exporters/zipkin/BUILD index bfa91014d3..b79294c955 100644 --- a/exporters/zipkin/BUILD +++ b/exporters/zipkin/BUILD @@ -68,6 +68,7 @@ cc_test( deps = [ ":zipkin_exporter", ":zipkin_recordable", + "//test_common/src/http/client/nosend:http_client_nosend", "@com_google_googletest//:gtest_main", ], ) From 2c64733941f7af29590b04582c48d8e735921ab6 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Sun, 17 May 2026 06:15:39 +0000 Subject: [PATCH 20/22] Fix IWYU --- exporters/otlp/src/otlp_http_exporter.cc | 1 + exporters/otlp/src/otlp_http_exporter_factory.cc | 4 +++- exporters/otlp/src/otlp_http_log_record_exporter_factory.cc | 4 +++- exporters/otlp/src/otlp_http_metric_exporter_factory.cc | 4 +++- exporters/zipkin/src/zipkin_exporter_factory.cc | 4 +++- ext/src/http/client/curl/http_client_factory_curl.cc | 2 -- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/exporters/otlp/src/otlp_http_exporter.cc b/exporters/otlp/src/otlp_http_exporter.cc index b1b342878b..5559c7fbbf 100644 --- a/exporters/otlp/src/otlp_http_exporter.cc +++ b/exporters/otlp/src/otlp_http_exporter.cc @@ -16,6 +16,7 @@ #include "opentelemetry/exporters/otlp/otlp_recordable.h" #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" #include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/exporter_utils.h" diff --git a/exporters/otlp/src/otlp_http_exporter_factory.cc b/exporters/otlp/src/otlp_http_exporter_factory.cc index 6836aff508..36971a1fcb 100644 --- a/exporters/otlp/src/otlp_http_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_exporter_factory.cc @@ -1,8 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" +#include + #include "opentelemetry/exporters/otlp/otlp_http_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h" #include "opentelemetry/ext/http/client/http_client.h" diff --git a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc index cc14facdbf..d9dfbc78bf 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc @@ -1,8 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h" +#include + #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h" #include "opentelemetry/ext/http/client/http_client.h" diff --git a/exporters/otlp/src/otlp_http_metric_exporter_factory.cc b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc index 46d20b73f1..ac79552b41 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc @@ -1,8 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h" +#include + #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h" #include "opentelemetry/ext/http/client/http_client.h" diff --git a/exporters/zipkin/src/zipkin_exporter_factory.cc b/exporters/zipkin/src/zipkin_exporter_factory.cc index e2ea38c761..51bb01c4c0 100644 --- a/exporters/zipkin/src/zipkin_exporter_factory.cc +++ b/exporters/zipkin/src/zipkin_exporter_factory.cc @@ -1,8 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/zipkin/zipkin_exporter_factory.h" +#include + #include "opentelemetry/exporters/zipkin/zipkin_exporter.h" +#include "opentelemetry/exporters/zipkin/zipkin_exporter_factory.h" #include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" #include "opentelemetry/ext/http/client/http_client.h" #include "opentelemetry/ext/http/client/http_client_factory.h" diff --git a/ext/src/http/client/curl/http_client_factory_curl.cc b/ext/src/http/client/curl/http_client_factory_curl.cc index 5eb5fc7076..b0c5f131b4 100644 --- a/ext/src/http/client/curl/http_client_factory_curl.cc +++ b/ext/src/http/client/curl/http_client_factory_curl.cc @@ -5,9 +5,7 @@ #include "opentelemetry/ext/http/client/curl/http_client_curl.h" #include "opentelemetry/ext/http/client/curl/http_client_factory_curl.h" -#include "opentelemetry/ext/http/client/http_client.h" #include "opentelemetry/ext/http/client/http_client_factory.h" -#include "opentelemetry/sdk/common/thread_instrumentation.h" namespace http_client = opentelemetry::ext::http::client; From 6ca4b379cd1df736aba1fa39a487f2d3cbc75073 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Sun, 17 May 2026 06:56:04 +0000 Subject: [PATCH 21/22] Fix clang-tidy --- .../exporters/otlp/otlp_http_exporter.h | 4 ++-- .../exporters/otlp/otlp_http_exporter_factory.h | 4 ++-- .../otlp/otlp_http_log_record_exporter.h | 4 ++-- .../otlp/otlp_http_log_record_exporter_factory.h | 4 ++-- .../exporters/otlp/otlp_http_metric_exporter.h | 4 ++-- .../otlp/otlp_http_metric_exporter_factory.h | 4 ++-- exporters/otlp/src/otlp_http_exporter.cc | 16 +++++++++------- exporters/otlp/src/otlp_http_exporter_factory.cc | 8 ++++---- .../otlp/src/otlp_http_log_record_exporter.cc | 8 ++++---- .../src/otlp_http_log_record_exporter_factory.cc | 8 ++++---- exporters/otlp/src/otlp_http_metric_exporter.cc | 8 ++++---- .../src/otlp_http_metric_exporter_factory.cc | 8 ++++---- .../exporters/zipkin/zipkin_exporter_factory.h | 2 +- exporters/zipkin/src/zipkin_exporter_factory.cc | 6 ++---- 14 files changed, 44 insertions(+), 44 deletions(-) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h index e83c5b3504..ad1639a04b 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h @@ -50,7 +50,7 @@ class OPENTELEMETRY_EXPORT OtlpHttpExporter final : public opentelemetry::sdk::t * @param factory the HTTP client factory used to create the underlying HTTP client */ OtlpHttpExporter(const OtlpHttpExporterOptions &options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create an OtlpHttpExporter using the given options, runtime options, and HTTP client factory. @@ -60,7 +60,7 @@ class OPENTELEMETRY_EXPORT OtlpHttpExporter final : public opentelemetry::sdk::t */ OtlpHttpExporter(const OtlpHttpExporterOptions &options, const OtlpHttpExporterRuntimeOptions &runtime_options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create an OtlpHttpExporter using the given options and HTTP client. diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h index fd96ea8f7f..4484db127d 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h @@ -49,7 +49,7 @@ class OPENTELEMETRY_EXPORT OtlpHttpExporterFactory */ static std::unique_ptr Create( const OtlpHttpExporterOptions &options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create an OtlpHttpExporter using the given options, runtime options, and HTTP client factory. @@ -60,7 +60,7 @@ class OPENTELEMETRY_EXPORT OtlpHttpExporterFactory static std::unique_ptr Create( const OtlpHttpExporterOptions &options, const OtlpHttpExporterRuntimeOptions &runtime_options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create an OtlpHttpExporter using the given options and HTTP client. diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h index 80e3a85f2b..4259c28998 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h @@ -53,7 +53,7 @@ class OtlpHttpLogRecordExporter final : public opentelemetry::sdk::logs::LogReco * @param factory the HTTP client factory used to create the underlying HTTP client */ OtlpHttpLogRecordExporter(const OtlpHttpLogRecordExporterOptions &options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create an OtlpHttpLogRecordExporter with user specified options, runtime options, and HTTP @@ -64,7 +64,7 @@ class OtlpHttpLogRecordExporter final : public opentelemetry::sdk::logs::LogReco */ OtlpHttpLogRecordExporter(const OtlpHttpLogRecordExporterOptions &options, const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create an OtlpHttpLogRecordExporter with user specified options and HTTP client. diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h index e38ea91872..3669d923b5 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h @@ -49,7 +49,7 @@ class OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterFactory */ static std::unique_ptr Create( const OtlpHttpLogRecordExporterOptions &options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create a OtlpHttpLogRecordExporter using the given options, runtime options, and HTTP client @@ -61,7 +61,7 @@ class OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterFactory static std::unique_ptr Create( const OtlpHttpLogRecordExporterOptions &options, const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create a OtlpHttpLogRecordExporter using the given options and HTTP client. diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h index 2f764dc533..d8a25f95d8 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h @@ -52,7 +52,7 @@ class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::PushMet * @param factory the HTTP client factory used to create the underlying HTTP client */ OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create an OtlpHttpMetricExporter with user specified options, runtime options, and HTTP client @@ -63,7 +63,7 @@ class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::PushMet */ OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options, const OtlpHttpMetricExporterRuntimeOptions &runtime_options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create an OtlpHttpMetricExporter with user specified options and HTTP client. diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h index 544e258a5e..d60dfb2b7f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h @@ -49,7 +49,7 @@ class OPENTELEMETRY_EXPORT OtlpHttpMetricExporterFactory */ static std::unique_ptr Create( const OtlpHttpMetricExporterOptions &options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create a OtlpHttpMetricExporter using the given options, runtime options, and HTTP client @@ -61,7 +61,7 @@ class OPENTELEMETRY_EXPORT OtlpHttpMetricExporterFactory static std::unique_ptr Create( const OtlpHttpMetricExporterOptions &options, const OtlpHttpMetricExporterRuntimeOptions &runtime_options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create a OtlpHttpMetricExporter using the given options and HTTP client. diff --git a/exporters/otlp/src/otlp_http_exporter.cc b/exporters/otlp/src/otlp_http_exporter.cc index 5559c7fbbf..50bf12f868 100644 --- a/exporters/otlp/src/otlp_http_exporter.cc +++ b/exporters/otlp/src/otlp_http_exporter.cc @@ -116,8 +116,9 @@ OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, ))) {} -OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, - std::shared_ptr factory) +OtlpHttpExporter::OtlpHttpExporter( + const OtlpHttpExporterOptions &options, + const std::shared_ptr &factory) : options_(options), runtime_options_(), http_client_(new OtlpHttpClient( @@ -151,12 +152,13 @@ OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, options.max_requests_per_connection #endif ), - std::move(factory))) + factory)) {} -OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, - const OtlpHttpExporterRuntimeOptions &runtime_options, - std::shared_ptr factory) +OtlpHttpExporter::OtlpHttpExporter( + const OtlpHttpExporterOptions &options, + const OtlpHttpExporterRuntimeOptions &runtime_options, + const std::shared_ptr &factory) : options_(options), runtime_options_(runtime_options), http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url, @@ -189,7 +191,7 @@ OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, options.max_requests_per_connection #endif ), - std::move(factory))) + factory)) {} OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options, diff --git a/exporters/otlp/src/otlp_http_exporter_factory.cc b/exporters/otlp/src/otlp_http_exporter_factory.cc index 36971a1fcb..4aa8d9e52b 100644 --- a/exporters/otlp/src/otlp_http_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_exporter_factory.cc @@ -39,19 +39,19 @@ std::unique_ptr OtlpHttpExporterFactory std::unique_ptr OtlpHttpExporterFactory::Create( const OtlpHttpExporterOptions &options, - std::shared_ptr factory) + const std::shared_ptr &factory) { return std::unique_ptr( - new OtlpHttpExporter(options, std::move(factory))); + new OtlpHttpExporter(options, factory)); } std::unique_ptr OtlpHttpExporterFactory::Create( const OtlpHttpExporterOptions &options, const OtlpHttpExporterRuntimeOptions &runtime_options, - std::shared_ptr factory) + const std::shared_ptr &factory) { return std::unique_ptr( - new OtlpHttpExporter(options, runtime_options, std::move(factory))); + new OtlpHttpExporter(options, runtime_options, factory)); } std::unique_ptr OtlpHttpExporterFactory::Create( diff --git a/exporters/otlp/src/otlp_http_log_record_exporter.cc b/exporters/otlp/src/otlp_http_log_record_exporter.cc index cf7d1768c5..e062d35146 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter.cc @@ -122,7 +122,7 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( const OtlpHttpLogRecordExporterOptions &options, - std::shared_ptr factory) + const std::shared_ptr &factory) : options_(options), runtime_options_(), http_client_(new OtlpHttpClient( @@ -156,13 +156,13 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( options.max_requests_per_connection #endif ), - std::move(factory))) + factory)) {} OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( const OtlpHttpLogRecordExporterOptions &options, const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, - std::shared_ptr factory) + const std::shared_ptr &factory) : options_(options), runtime_options_(runtime_options), http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url, @@ -195,7 +195,7 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( options.max_requests_per_connection #endif ), - std::move(factory))) + factory)) {} OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter( diff --git a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc index d9dfbc78bf..7b22231ad6 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc @@ -42,20 +42,20 @@ OtlpHttpLogRecordExporterFactory::Create( std::unique_ptr OtlpHttpLogRecordExporterFactory::Create( const OtlpHttpLogRecordExporterOptions &options, - std::shared_ptr factory) + const std::shared_ptr &factory) { return std::unique_ptr( - new OtlpHttpLogRecordExporter(options, std::move(factory))); + new OtlpHttpLogRecordExporter(options, factory)); } std::unique_ptr OtlpHttpLogRecordExporterFactory::Create( const OtlpHttpLogRecordExporterOptions &options, const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options, - std::shared_ptr factory) + const std::shared_ptr &factory) { return std::unique_ptr( - new OtlpHttpLogRecordExporter(options, runtime_options, std::move(factory))); + new OtlpHttpLogRecordExporter(options, runtime_options, factory)); } std::unique_ptr diff --git a/exporters/otlp/src/otlp_http_metric_exporter.cc b/exporters/otlp/src/otlp_http_metric_exporter.cc index 6ed72ca6bf..37e2a0d9c3 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter.cc @@ -125,7 +125,7 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter( OtlpHttpMetricExporter::OtlpHttpMetricExporter( const OtlpHttpMetricExporterOptions &options, - std::shared_ptr factory) + const std::shared_ptr &factory) : options_(options), runtime_options_(), aggregation_temporality_selector_{ @@ -161,13 +161,13 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter( options.max_requests_per_connection #endif ), - std::move(factory))) + factory)) {} OtlpHttpMetricExporter::OtlpHttpMetricExporter( const OtlpHttpMetricExporterOptions &options, const OtlpHttpMetricExporterRuntimeOptions &runtime_options, - std::shared_ptr factory) + const std::shared_ptr &factory) : options_(options), runtime_options_(runtime_options), aggregation_temporality_selector_{ @@ -202,7 +202,7 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter( options.max_requests_per_connection #endif ), - std::move(factory))) + factory)) {} OtlpHttpMetricExporter::OtlpHttpMetricExporter( diff --git a/exporters/otlp/src/otlp_http_metric_exporter_factory.cc b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc index ac79552b41..f819b4f9c2 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc @@ -41,20 +41,20 @@ OtlpHttpMetricExporterFactory::Create(const OtlpHttpMetricExporterOptions &optio std::unique_ptr OtlpHttpMetricExporterFactory::Create( const OtlpHttpMetricExporterOptions &options, - std::shared_ptr factory) + const std::shared_ptr &factory) { return std::unique_ptr( - new OtlpHttpMetricExporter(options, std::move(factory))); + new OtlpHttpMetricExporter(options, factory)); } std::unique_ptr OtlpHttpMetricExporterFactory::Create( const OtlpHttpMetricExporterOptions &options, const OtlpHttpMetricExporterRuntimeOptions &runtime_options, - std::shared_ptr factory) + const std::shared_ptr &factory) { return std::unique_ptr( - new OtlpHttpMetricExporter(options, runtime_options, std::move(factory))); + new OtlpHttpMetricExporter(options, runtime_options, factory)); } std::unique_ptr diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h index 64826b92c4..91e7ae4efc 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h @@ -41,7 +41,7 @@ class ZipkinExporterFactory */ static std::unique_ptr Create( const ZipkinExporterOptions &options, - std::shared_ptr factory); + const std::shared_ptr &factory); /** * Create a ZipkinExporter using the given options and HTTP client. diff --git a/exporters/zipkin/src/zipkin_exporter_factory.cc b/exporters/zipkin/src/zipkin_exporter_factory.cc index 51bb01c4c0..d793831cd5 100644 --- a/exporters/zipkin/src/zipkin_exporter_factory.cc +++ b/exporters/zipkin/src/zipkin_exporter_factory.cc @@ -10,8 +10,6 @@ #include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/version.h" -namespace http_client = opentelemetry::ext::http::client; - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -33,10 +31,10 @@ std::unique_ptr ZipkinExporterFactory:: std::unique_ptr ZipkinExporterFactory::Create( const ZipkinExporterOptions &options, - std::shared_ptr factory) + const std::shared_ptr &factory) { return std::unique_ptr( - new ZipkinExporter(options, std::move(factory))); + new ZipkinExporter(options, factory)); } std::unique_ptr ZipkinExporterFactory::Create( From ad89717a4f56a60b1879178a33f99f101f417f63 Mon Sep 17 00:00:00 2001 From: Lukasz Towarek Date: Thu, 21 May 2026 22:07:40 +0000 Subject: [PATCH 22/22] Fix IWYU --- exporters/otlp/src/otlp_http_exporter_factory.cc | 4 ++++ exporters/otlp/src/otlp_http_log_record_exporter_factory.cc | 4 ++++ exporters/otlp/src/otlp_http_metric_exporter_factory.cc | 4 ++++ exporters/zipkin/src/zipkin_exporter_factory.cc | 2 ++ 4 files changed, 14 insertions(+) diff --git a/exporters/otlp/src/otlp_http_exporter_factory.cc b/exporters/otlp/src/otlp_http_exporter_factory.cc index 4aa8d9e52b..b9b6605d77 100644 --- a/exporters/otlp/src/otlp_http_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_exporter_factory.cc @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #include #include "opentelemetry/exporters/otlp/otlp_http_exporter.h" @@ -8,6 +9,9 @@ #include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h" #include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc index 7b22231ad6..956c04dd2d 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter_factory.cc @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #include #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" @@ -8,6 +9,9 @@ #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h" #include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/otlp/src/otlp_http_metric_exporter_factory.cc b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc index f819b4f9c2..7ff0b6b0b7 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter_factory.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #include #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter.h" @@ -8,6 +9,9 @@ #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h" #include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/zipkin/src/zipkin_exporter_factory.cc b/exporters/zipkin/src/zipkin_exporter_factory.cc index d793831cd5..6c3f1f4f88 100644 --- a/exporters/zipkin/src/zipkin_exporter_factory.cc +++ b/exporters/zipkin/src/zipkin_exporter_factory.cc @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #include #include "opentelemetry/exporters/zipkin/zipkin_exporter.h" @@ -8,6 +9,7 @@ #include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" #include "opentelemetry/ext/http/client/http_client.h" #include "opentelemetry/ext/http/client/http_client_factory.h" +#include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE