From 3f2111656fbc2feda3b1ba932fdcc09b3cb86eec Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sun, 14 Jun 2026 22:35:12 +0200 Subject: [PATCH 1/3] [TEST] Code cleanup in exporter tests --- .../otlp/test/otlp_grpc_exporter_test.cc | 114 +++++++++-------- .../test/otlp_grpc_metric_exporter_test.cc | 68 ++++------ .../otlp_http_exporter_custom_client_test.cc | 48 ++++--- .../otlp/test/otlp_http_exporter_test.cc | 120 +++++++++++------- ..._log_record_exporter_custom_client_test.cc | 21 +-- .../otlp_http_log_record_exporter_test.cc | 105 ++++++++------- ...http_metric_exporter_custom_client_test.cc | 21 +-- .../exporters/zipkin/zipkin_exporter.h | 3 - exporters/zipkin/test/zipkin_exporter_test.cc | 71 +++++++---- 9 files changed, 313 insertions(+), 258 deletions(-) diff --git a/exporters/otlp/test/otlp_grpc_exporter_test.cc b/exporters/otlp/test/otlp_grpc_exporter_test.cc index 3ac174b691..364c59681b 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_test.cc @@ -1,49 +1,54 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef OPENTELEMETRY_STL_VERSION -// Unfortunately as of 04/27/2021 the fix is NOT in the vcpkg snapshot of Google Test. -// Remove above `#ifdef` once the GMock fix for C++20 is in the mainline. -// -// Please refer to this GitHub issue for additional details: -// https://github.com/google/googletest/issues/2914 -// https://github.com/google/googletest/commit/61f010d703b32de9bfb20ab90ece38ab2f25977f -// -// If we compile using Visual Studio 2019 with `c++latest` (C++20) without the GMock fix, -// then the compilation here fails in `gmock-actions.h` from: -// .\tools\vcpkg\installed\x64-windows\include\gmock\gmock-actions.h(819): -// error C2653: 'result_of': is not a class or namespace name -// -// That is because `std::result_of` has been removed in C++20. - -# include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - -// Problematic code that pulls in Gmock and breaks with vs2019/c++latest : +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gmock/gmock.h" + +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/simple_processor.h" +#include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/sdk/trace/tracer_provider_factory.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" +#include "opentelemetry/version.h" + +// clang-format off +# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep # include "opentelemetry/proto/collector/trace/v1/trace_service_mock.grpc.pb.h" - # include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h" +# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/sdk/trace/simple_processor.h" -# include "opentelemetry/sdk/trace/simple_processor_factory.h" -# include "opentelemetry/sdk/trace/tracer_provider.h" -# include "opentelemetry/sdk/trace/tracer_provider_factory.h" -# include "opentelemetry/trace/provider.h" -# include "opentelemetry/trace/tracer_provider.h" - -# include -# include -# include - -# if defined(_MSC_VER) -# include "opentelemetry/sdk/common/env_variables.h" +#if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; -# endif +#endif using namespace testing; @@ -59,14 +64,14 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe { public: // Some old toolchains can only use gRPC 1.33 and it's experimental. -# if defined(GRPC_CPP_VERSION_MAJOR) && \ - (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 +#if defined(GRPC_CPP_VERSION_MAJOR) && \ + (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 using async_interface_base = proto::collector::trace::v1::TraceService::StubInterface::async_interface; -# else +#else using async_interface_base = proto::collector::trace::v1::TraceService::StubInterface::experimental_async_interface; -# endif +#endif OtlpMockTraceServiceStub() : async_interface_(this) {} @@ -86,23 +91,23 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe } // Some old toolchains can only use gRPC 1.33 and it's experimental. -# if defined(GRPC_CPP_VERSION_MAJOR) && \ - (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \ - defined(GRPC_CALLBACK_API_NONEXPERIMENTAL) +#if defined(GRPC_CPP_VERSION_MAJOR) && \ + (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \ + defined(GRPC_CALLBACK_API_NONEXPERIMENTAL) void Export( ::grpc::ClientContext * /*context*/, const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest * /*request*/, ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceResponse * /*response*/, ::grpc::ClientUnaryReactor * /*reactor*/) override {} -# else +#else void Export( ::grpc::ClientContext * /*context*/, const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest * /*request*/, ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceResponse * /*response*/, ::grpc::experimental::ClientUnaryReactor * /*reactor*/) {} -# endif +#endif private: OtlpMockTraceServiceStub *stub_; @@ -188,12 +193,12 @@ TEST_F(OtlpGrpcExporterTestPeer, ExportUnitTest) .WillOnce(Return(grpc::Status::CANCELLED)); result = exporter->Export(batch_2); exporter->ForceFlush(); -# if defined(ENABLE_ASYNC_EXPORT) +#if defined(ENABLE_ASYNC_EXPORT) EXPECT_EQ(sdk::common::ExportResult::kSuccess, result); EXPECT_FALSE(mock_stub->GetLastAsyncStatus().ok()); -# else +#else EXPECT_EQ(sdk::common::ExportResult::kFailure, result); -# endif +#endif } // Create spans, let processor call Export() @@ -242,7 +247,7 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigSslCredentialsTest) EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); } -# ifndef NO_GETENV +#ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpGrpcExporterTestPeer, ConfigFromEnv) { @@ -402,9 +407,9 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigRetryGenericValuesFromEnv) unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_MAX_BACKOFF"); unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_BACKOFF_MULTIPLIER"); } -# endif // NO_GETENV +#endif // NO_GETENV -# ifdef ENABLE_OTLP_RETRY_PREVIEW +#ifdef ENABLE_OTLP_RETRY_PREVIEW struct TestTraceService : public opentelemetry::proto::collector::trace::v1::TraceService::Service { TestTraceService(const std::vector &status_codes) : status_codes_(status_codes) @@ -558,9 +563,8 @@ TEST_P(OtlpGrpcExporterRetryIntegrationTests, StatusCodes) ASSERT_EQ(expected_attempts, service.request_count_); } -# endif // ENABLE_OTLP_RETRY_PREVIEW +#endif // ENABLE_OTLP_RETRY_PREVIEW } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc b/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc index 098c2c85c0..b670846c01 100644 --- a/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc @@ -1,45 +1,34 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef OPENTELEMETRY_STL_VERSION -// Unfortunately as of 04/27/2021 the fix is NOT in the vcpkg snapshot of Google Test. -// Remove above `#ifdef` once the GMock fix for C++20 is in the mainline. -// -// Please refer to this GitHub issue for additional details: -// https://github.com/google/googletest/issues/2914 -// https://github.com/google/googletest/commit/61f010d703b32de9bfb20ab90ece38ab2f25977f -// -// If we compile using Visual Studio 2019 with `c++latest` (C++20) without the GMock fix, -// then the compilation here fails in `gmock-actions.h` from: -// .\tools\vcpkg\installed\x64-windows\include\gmock\gmock-actions.h(819): -// error C2653: 'result_of': is not a class or namespace name -// -// That is because `std::result_of` has been removed in C++20. - -# include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - -// Problematic code that pulls in Gmock and breaks with vs2019/c++latest : -# include "opentelemetry/proto/collector/metrics/v1/metrics_service_mock.grpc.pb.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -# include "opentelemetry/exporters/otlp/otlp_grpc_client.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" - -# include "opentelemetry/sdk/trace/simple_processor.h" -# include "opentelemetry/sdk/trace/tracer_provider.h" -# include "opentelemetry/trace/provider.h" - -# include -# include - -# if defined(_MSC_VER) -# include "opentelemetry/sdk/common/env_variables.h" +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/exporters/otlp/otlp_grpc_client.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" + +// clang-format off +# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +# include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h" +# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on + +#if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; -# endif +#endif using namespace testing; @@ -109,7 +98,7 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigSslCredentialsTest) EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); } -# ifndef NO_GETENV +#ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigFromEnv) { @@ -269,7 +258,7 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigRetryGenericValuesFromEnv) unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_MAX_BACKOFF"); unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_BACKOFF_MULTIPLIER"); } -# endif // NO_GETENV +#endif // NO_GETENV TEST_F(OtlpGrpcMetricExporterTestPeer, CheckGetAggregationTemporality) { @@ -303,4 +292,3 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, CheckGetAggregationTemporality) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif /* OPENTELEMETRY_STL_VERSION */ 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 e90088be7b..1b5edabf55 100644 --- a/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_custom_client_test.cc @@ -1,25 +1,33 @@ // 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_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" -# 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 -# include "gmock/gmock.h" +#include +#include +#include +#include +#include "gmock/gmock.h" + +#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.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/thread_instrumentation.h" +#include "opentelemetry/sdk/trace/batch_span_processor.h" +#include "opentelemetry/sdk/trace/batch_span_processor_options.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/version.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" using namespace testing; @@ -148,5 +156,3 @@ TEST_F(OtlpHttpExporterCustomClientTestPeer, ExportCallsSendRequest) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif // OPENTELEMETRY_STL_VERSION diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index 3cbfa9d16c..2c08afccf3 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -1,44 +1,67 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef OPENTELEMETRY_STL_VERSION - -# include -# include - -# include "opentelemetry/exporters/otlp/otlp_http_exporter.h" -# include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - -# include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -# include "opentelemetry/ext/http/client/http_client_factory.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/simple_processor.h" -# include "opentelemetry/sdk/trace/simple_processor_factory.h" -# include "opentelemetry/sdk/trace/tracer_provider.h" -# include "opentelemetry/sdk/trace/tracer_provider_factory.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 "opentelemetry/trace/provider.h" -# include "opentelemetry/trace/tracer_provider.h" - -# include -# include -# include "gmock/gmock.h" - -# include "nlohmann/json.hpp" - -# if defined(_MSC_VER) -# include "opentelemetry/sdk/common/env_variables.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gmock/gmock.h" +#include "nlohmann/json.hpp" + +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#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/ext/http/client/http_client.h" +#include "opentelemetry/ext/http/server/http_server.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/proto/trace/v1/trace.pb.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/thread_instrumentation.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/batch_span_processor.h" +#include "opentelemetry/sdk/trace/batch_span_processor_options.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/sdk/trace/tracer_provider_factory.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 "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_startoptions.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/version.h" + +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +// IWYU pragma: no_include +#include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on + +#if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; -# endif +#endif using namespace testing; OPENTELEMETRY_BEGIN_NAMESPACE @@ -227,7 +250,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test EXPECT_GE(received_trace_id_counter, 1); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT void ExportJsonIntegrationTestAsync() { auto mock_otlp_client = @@ -342,7 +365,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test // Exporting can be retried EXPECT_GE(received_trace_id_counter, 1); } -# endif +#endif void ExportBinaryIntegrationTest() { @@ -440,7 +463,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test EXPECT_GE(received_trace_id_counter, 1); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT void ExportBinaryIntegrationTestAsync() { auto mock_otlp_client = @@ -540,7 +563,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test // Exporting can be retried EXPECT_GE(received_trace_id_counter, 1); } -# endif +#endif }; TEST(OtlpHttpExporterTest, Shutdown) @@ -560,13 +583,13 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTestSync) ExportJsonIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTestAsync) { ExportJsonIntegrationTestAsync(); google::protobuf::ShutdownProtobufLibrary(); } -# endif +#endif // Create spans, let processor call Export() TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTestSync) @@ -574,12 +597,12 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTestSync) ExportBinaryIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTestAsync) { ExportBinaryIntegrationTestAsync(); } -# endif +#endif // Test exporter configuration options TEST_F(OtlpHttpExporterTestPeer, ConfigTest) @@ -614,7 +637,7 @@ TEST(OtlpHttpExporterTest, ConfigDefaultProtocolTest) EXPECT_EQ(opts.content_type, HttpRequestContentType::kBinary); } -# ifndef NO_GETENV +#ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpHttpExporterTestPeer, ConfigFromEnv) { @@ -751,9 +774,9 @@ TEST_F(OtlpHttpExporterTestPeer, ConfigRetryGenericValuesFromEnv) unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_MAX_BACKOFF"); unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_BACKOFF_MULTIPLIER"); } -# endif // NO_GETENV +#endif // NO_GETENV -# ifdef ENABLE_OTLP_RETRY_PREVIEW +#ifdef ENABLE_OTLP_RETRY_PREVIEW using StatusCodeVector = std::vector; class OtlpHttpExporterRetryIntegrationTests @@ -856,9 +879,8 @@ TEST_P(OtlpHttpExporterRetryIntegrationTests, StatusCodes) ASSERT_EQ(expected_attempts, request_count); } -# endif // ENABLE_OTLP_RETRY_PREVIEW +#endif // ENABLE_OTLP_RETRY_PREVIEW } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif /* OPENTELEMETRY_STL_VERSION */ 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 82645ab3e1..be61fc92b1 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 @@ -1,16 +1,19 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef OPENTELEMETRY_STL_VERSION +#include +#include +#include +#include -# 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 "opentelemetry/test_common/ext/http/client/nosend/http_client_factory_nosend.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/sdk/logs/exporter.h" +#include "opentelemetry/version.h" -# include +#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" namespace http_client = opentelemetry::ext::http::client; @@ -60,5 +63,3 @@ TEST(OtlpHttpLogRecordExporterCustomClientTest, RuntimeOptionsWithHttpClientCrea } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif // OPENTELEMETRY_STL_VERSION diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc index 3fca7a06ea..ca19af024f 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -1,41 +1,59 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef OPENTELEMETRY_STL_VERSION - -# include -# include - -# include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - -# include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -# include "opentelemetry/common/key_value_iterable_view.h" -# include "opentelemetry/ext/http/client/http_client_factory.h" -# include "opentelemetry/ext/http/server/http_server.h" -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/sdk/logs/batch_log_record_processor.h" -# include "opentelemetry/sdk/logs/exporter.h" -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/resource/resource.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 -# include "gmock/gmock.h" - -# include "nlohmann/json.hpp" - -# if defined(_MSC_VER) -# include "opentelemetry/sdk/common/env_variables.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "gmock/gmock.h" +#include "nlohmann/json.hpp" + +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#include "opentelemetry/exporters/otlp/otlp_http_client.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/proto/common/v1/common.pb.h" +#include "opentelemetry/proto/logs/v1/logs.pb.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/thread_instrumentation.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/recordable.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 "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/version.h" + +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +// IWYU pragma: no_include +// IWYU pragma: no_include +#include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on + +#if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; -# endif +#endif using namespace testing; @@ -244,7 +262,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test EXPECT_GE(received_record_counter, 1); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT void ExportJsonIntegrationTestAsync() { auto mock_otlp_client = OtlpHttpLogRecordExporterTestPeer::GetMockOtlpHttpClient( @@ -390,7 +408,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test // Exporting can be retried EXPECT_GE(received_record_counter, 1); } -# endif +#endif void ExportBinaryIntegrationTest() { @@ -518,7 +536,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test EXPECT_GE(received_record_counter, 1); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT void ExportBinaryIntegrationTestAsync() { auto mock_otlp_client = OtlpHttpLogRecordExporterTestPeer::GetMockOtlpHttpClient( @@ -648,7 +666,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test // Exporting can be retried EXPECT_GE(received_record_counter, 1); } -# endif +#endif }; TEST(OtlpHttpLogRecordExporterTest, Shutdown) @@ -669,13 +687,13 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportJsonIntegrationTestSync) ExportJsonIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportJsonIntegrationTestAsync) { ExportJsonIntegrationTestAsync(); google::protobuf::ShutdownProtobufLibrary(); } -# endif +#endif // Create log records, let processor call Export() TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestSync) @@ -683,12 +701,12 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestSync) ExportBinaryIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestAsync) { ExportBinaryIntegrationTestAsync(); } -# endif +#endif // Test exporter configuration options TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigTest) @@ -723,7 +741,7 @@ TEST(OtlpHttpLogRecordExporterTest, ConfigDefaultProtocolTest) EXPECT_EQ(opts.content_type, HttpRequestContentType::kBinary); } -# ifndef NO_GETENV +#ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigFromEnv) { @@ -867,9 +885,8 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigRetryGenericValuesFromEnv) unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_MAX_BACKOFF"); unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_BACKOFF_MULTIPLIER"); } -# endif // NO_GETENV +#endif // NO_GETENV } // 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 index 58cbfe28e8..96f3c59c75 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 @@ -1,16 +1,19 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef OPENTELEMETRY_STL_VERSION +#include +#include +#include +#include -# 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 "opentelemetry/test_common/ext/http/client/nosend/http_client_factory_nosend.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/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" -# include +#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" namespace http_client = opentelemetry::ext::http::client; @@ -60,5 +63,3 @@ TEST(OtlpHttpMetricExporterCustomClientTest, RuntimeOptionsWithHttpClientCreates } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE - -#endif // OPENTELEMETRY_STL_VERSION diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h index cb4d8f099b..8fdd99bff4 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h @@ -13,10 +13,7 @@ #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" #include "opentelemetry/sdk/trace/exporter.h" -#include "opentelemetry/sdk/trace/recordable.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/exporters/zipkin/test/zipkin_exporter_test.cc b/exporters/zipkin/test/zipkin_exporter_test.cc index 086357c07f..3d5718ac38 100644 --- a/exporters/zipkin/test/zipkin_exporter_test.cc +++ b/exporters/zipkin/test/zipkin_exporter_test.cc @@ -1,31 +1,51 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#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 -# include "gmock/gmock.h" - -# include "nlohmann/json.hpp" - -# include -# include - -# if defined(_MSC_VER) -# include "opentelemetry/sdk/common/env_variables.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "gmock/gmock.h" +#include "nlohmann/json.hpp" + +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/context/context.h" +#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/curl/http_client_curl.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/batch_span_processor.h" +#include "opentelemetry/sdk/trace/batch_span_processor_options.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_startoptions.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" +#include "opentelemetry/version.h" + +#include "opentelemetry/test_common/ext/http/client/nosend/http_client_factory_nosend.h" + +#if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; -# endif +#endif namespace sdk_common = opentelemetry::sdk::common; using namespace testing; @@ -211,7 +231,7 @@ TEST_F(ZipkinExporterTestPeer, ConfigTest) EXPECT_EQ(GetOptions(exporter).endpoint, "http://localhost:45455/v1/traces"); } -# ifndef NO_GETENV +#ifndef NO_GETENV // Test exporter configuration options from env TEST_F(ZipkinExporterTestPeer, ConfigFromEnv) { @@ -224,7 +244,7 @@ TEST_F(ZipkinExporterTestPeer, ConfigFromEnv) unsetenv("OTEL_EXPORTER_ZIPKIN_ENDPOINT"); } -# endif // NO_GETENV +#endif // NO_GETENV TEST_F(ZipkinExporterTestPeer, FactoryInjectionCreatesExporter) { @@ -247,4 +267,3 @@ TEST_F(ZipkinExporterTestPeer, HttpClientSyncInjectionCreatesExporter) } // namespace zipkin } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif /* OPENTELEMETRY_STL_VERSION */ From 84d567d9c5b400dab72520c177c37c2f5988a49e Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 10 Jul 2026 00:56:51 +0200 Subject: [PATCH 2/3] Test cleanup, in progress --- .../exporters/otlp/otlp_grpc_exporter.h | 24 ++-- .../otlp/otlp_grpc_metric_exporter.h | 26 ++-- .../otlp/src/otlp_grpc_exporter_factory.cc | 1 + .../otlp/test/otlp_grpc_exporter_test.cc | 122 ++++++++--------- .../test/otlp_grpc_metric_exporter_test.cc | 119 ++++++++-------- .../otlp/test/otlp_http_exporter_test.cc | 127 ++++++++++-------- .../otlp_http_log_record_exporter_test.cc | 119 +++++++++------- 7 files changed, 275 insertions(+), 263 deletions(-) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h index f698b8fb5d..8c2b6d791a 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h @@ -6,21 +6,16 @@ #include #include -// clang-format off -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" -// clang-format on - -#include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h" - -// clang-format off -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" -// clang-format on - +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" -#include "opentelemetry/exporters/otlp/otlp_environment.h" -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -28,9 +23,8 @@ namespace exporter namespace otlp { -class OtlpGrpcClientReferenceGuard; - -class OtlpGrpcClient; +class OtlpGrpcClientReferenceGuard; // IWYU pragma: keep +class OtlpGrpcClient; // IWYU pragma: keep /** * The OTLP exporter exports span data in OpenTelemetry Protocol (OTLP) format. diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h index 4272bf2126..c49ab713b9 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h @@ -3,22 +3,22 @@ #pragma once -// clang-format off -#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" -// clang-format on - -#include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h" - -// clang-format off -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" -// clang-format on +#include +#include -#include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" -#include +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on + +// IWYU pragma: no_include "opentelemetry/exporters/otlp/otlp_grpc_client.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -26,8 +26,8 @@ namespace exporter namespace otlp { -class OtlpGrpcClientReferenceGuard; -class OtlpGrpcClient; +class OtlpGrpcClientReferenceGuard; // IWYU pragma: keep +class OtlpGrpcClient; // IWYU pragma: keep /** * The OTLP exporter exports metrics data in OpenTelemetry Protocol (OTLP) format in gRPC. diff --git a/exporters/otlp/src/otlp_grpc_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_exporter_factory.cc index 3615e099c9..6ef5c21404 100644 --- a/exporters/otlp/src/otlp_grpc_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_exporter_factory.cc @@ -8,6 +8,7 @@ #include +#include "opentelemetry/exporters/otlp/otlp_grpc_client.h" #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" #include "opentelemetry/sdk/trace/exporter.h" diff --git a/exporters/otlp/test/otlp_grpc_exporter_test.cc b/exporters/otlp/test/otlp_grpc_exporter_test.cc index 7525fc2109..e53ffc31ee 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_test.cc @@ -1,54 +1,51 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef OPENTELEMETRY_STL_VERSION -// Unfortunately as of 04/27/2021 the fix is NOT in the vcpkg snapshot of Google Test. -// Remove above `#ifdef` once the GMock fix for C++20 is in the mainline. -// -// Please refer to this GitHub issue for additional details: -// https://github.com/google/googletest/issues/2914 -// https://github.com/google/googletest/commit/61f010d703b32de9bfb20ab90ece38ab2f25977f -// -// If we compile using Visual Studio 2019 with `c++latest` (C++20) without the GMock fix, -// then the compilation here fails in `gmock-actions.h` from: -// .\tools\vcpkg\installed\x64-windows\include\gmock\gmock-actions.h(819): -// error C2653: 'result_of': is not a class or namespace name -// -// That is because `std::result_of` has been removed in C++20. - -# include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - -// Problematic code that pulls in Gmock and breaks with vs2019/c++latest : -# include "opentelemetry/proto/collector/trace/v1/trace_service_mock.grpc.pb.h" - -# include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/sdk/common/global_log_handler.h" -# include "opentelemetry/sdk/trace/simple_processor.h" -# include "opentelemetry/sdk/trace/simple_processor_factory.h" -# include "opentelemetry/sdk/trace/tracer_provider.h" -# include "opentelemetry/sdk/trace/tracer_provider_factory.h" -# include "opentelemetry/test_common/sdk/common/scoped_test_log_handler.h" -# include "opentelemetry/trace/provider.h" -# include "opentelemetry/trace/tracer_provider.h" - -# include -# include -# include -# include -# include -# include - -# if defined(_MSC_VER) -# include "opentelemetry/sdk/common/env_variables.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gmock/gmock.h" + +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/simple_processor.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/test_common/sdk/common/scoped_test_log_handler.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" +#include "opentelemetry/version.h" + +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/collector/trace/v1/trace_service_mock.grpc.pb.h" +#include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on + +// IWYU pragma: no_include +// IWYU pragma: no_include + +#if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; -# endif +#endif using namespace testing; @@ -64,14 +61,14 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe { public: // Some old toolchains can only use gRPC 1.33 and it's experimental. -# if defined(GRPC_CPP_VERSION_MAJOR) && \ - (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 +#if defined(GRPC_CPP_VERSION_MAJOR) && \ + (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 using async_interface_base = proto::collector::trace::v1::TraceService::StubInterface::async_interface; -# else +#else using async_interface_base = proto::collector::trace::v1::TraceService::StubInterface::experimental_async_interface; -# endif +#endif OtlpMockTraceServiceStub() : async_interface_(this) {} @@ -91,23 +88,23 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe } // Some old toolchains can only use gRPC 1.33 and it's experimental. -# if defined(GRPC_CPP_VERSION_MAJOR) && \ - (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \ - defined(GRPC_CALLBACK_API_NONEXPERIMENTAL) +#if defined(GRPC_CPP_VERSION_MAJOR) && \ + (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \ + defined(GRPC_CALLBACK_API_NONEXPERIMENTAL) void Export( ::grpc::ClientContext * /*context*/, const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest * /*request*/, ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceResponse * /*response*/, ::grpc::ClientUnaryReactor * /*reactor*/) override {} -# else +#else void Export( ::grpc::ClientContext * /*context*/, const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest * /*request*/, ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceResponse * /*response*/, ::grpc::experimental::ClientUnaryReactor * /*reactor*/) {} -# endif +#endif private: OtlpMockTraceServiceStub *stub_; @@ -195,12 +192,12 @@ TEST_F(OtlpGrpcExporterTestPeer, ExportUnitTest) .WillOnce(Return(grpc::Status::CANCELLED)); result = exporter->Export(batch_2); exporter->ForceFlush(); -# if defined(ENABLE_ASYNC_EXPORT) +#if defined(ENABLE_ASYNC_EXPORT) EXPECT_EQ(sdk::common::ExportResult::kSuccess, result); EXPECT_FALSE(mock_stub->GetLastAsyncStatus().ok()); -# else +#else EXPECT_EQ(sdk::common::ExportResult::kFailure, result); -# endif +#endif } // Exporter logs the rejection on partial_success. @@ -290,7 +287,7 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigSslCredentialsTest) EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); } -# ifndef NO_GETENV +#ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpGrpcExporterTestPeer, ConfigFromEnv) { @@ -450,9 +447,9 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigRetryGenericValuesFromEnv) unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_MAX_BACKOFF"); unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_BACKOFF_MULTIPLIER"); } -# endif // NO_GETENV +#endif // NO_GETENV -# ifdef ENABLE_OTLP_RETRY_PREVIEW +#ifdef ENABLE_OTLP_RETRY_PREVIEW struct TestTraceService : public opentelemetry::proto::collector::trace::v1::TraceService::Service { TestTraceService(const std::vector &status_codes) : status_codes_(status_codes) @@ -606,9 +603,8 @@ TEST_P(OtlpGrpcExporterRetryIntegrationTests, StatusCodes) ASSERT_EQ(expected_attempts, service.request_count_); } -# endif // ENABLE_OTLP_RETRY_PREVIEW +#endif // ENABLE_OTLP_RETRY_PREVIEW } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc b/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc index e752a24b7e..401ab13230 100644 --- a/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc @@ -1,59 +1,53 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef OPENTELEMETRY_STL_VERSION -// Unfortunately as of 04/27/2021 the fix is NOT in the vcpkg snapshot of Google Test. -// Remove above `#ifdef` once the GMock fix for C++20 is in the mainline. -// -// Please refer to this GitHub issue for additional details: -// https://github.com/google/googletest/issues/2914 -// https://github.com/google/googletest/commit/61f010d703b32de9bfb20ab90ece38ab2f25977f -// -// If we compile using Visual Studio 2019 with `c++latest` (C++20) without the GMock fix, -// then the compilation here fails in `gmock-actions.h` from: -// .\tools\vcpkg\installed\x64-windows\include\gmock\gmock-actions.h(819): -// error C2653: 'result_of': is not a class or namespace name -// -// That is because `std::result_of` has been removed in C++20. - -# include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - -// Problematic code that pulls in Gmock and breaks with vs2019/c++latest : -# include "opentelemetry/proto/collector/metrics/v1/metrics_service_mock.grpc.pb.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -# include "opentelemetry/exporters/otlp/otlp_grpc_client.h" -# include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" - -# include "opentelemetry/common/timestamp.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/sdk/common/global_log_handler.h" -# include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" -# include "opentelemetry/sdk/metrics/data/metric_data.h" -# include "opentelemetry/sdk/metrics/data/point_data.h" -# include "opentelemetry/sdk/metrics/export/metric_producer.h" -# include "opentelemetry/sdk/metrics/instruments.h" -# include "opentelemetry/sdk/resource/resource.h" -# include "opentelemetry/sdk/trace/simple_processor.h" -# include "opentelemetry/sdk/trace/tracer_provider.h" -# include "opentelemetry/test_common/sdk/common/scoped_test_log_handler.h" -# include "opentelemetry/trace/provider.h" - -# include -# include -# include -# include -# include -# include - -# if defined(_MSC_VER) -# include "opentelemetry/sdk/common/env_variables.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gmock/gmock.h" + +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/metrics/data/metric_data.h" +#include "opentelemetry/sdk/metrics/data/point_data.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/test_common/sdk/common/scoped_test_log_handler.h" +#include "opentelemetry/version.h" + +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/collector/metrics/v1/metrics_service_mock.grpc.pb.h" +#include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h" +#include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on + +// IWYU pragma: no_include +// IWYU pragma: no_include + +#if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; -# endif +#endif using namespace testing; @@ -69,14 +63,14 @@ class OtlpMockMetricsServiceStub : public proto::collector::metrics::v1::MockMet { public: // Some old toolchains can only use gRPC 1.33 and it's experimental. -# if defined(GRPC_CPP_VERSION_MAJOR) && \ - (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 +#if defined(GRPC_CPP_VERSION_MAJOR) && \ + (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 using async_interface_base = proto::collector::metrics::v1::MetricsService::StubInterface::async_interface; -# else +#else using async_interface_base = proto::collector::metrics::v1::MetricsService::StubInterface::experimental_async_interface; -# endif +#endif OtlpMockMetricsServiceStub() : async_interface_(this) {} @@ -96,9 +90,9 @@ class OtlpMockMetricsServiceStub : public proto::collector::metrics::v1::MockMet } // Some old toolchains can only use gRPC 1.33 and it's experimental. -# if defined(GRPC_CPP_VERSION_MAJOR) && \ - (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \ - defined(GRPC_CALLBACK_API_NONEXPERIMENTAL) +#if defined(GRPC_CPP_VERSION_MAJOR) && \ + (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \ + defined(GRPC_CALLBACK_API_NONEXPERIMENTAL) void Export( ::grpc::ClientContext * /*context*/, const ::opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest @@ -106,7 +100,7 @@ class OtlpMockMetricsServiceStub : public proto::collector::metrics::v1::MockMet ::opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceResponse * /*response*/, ::grpc::ClientUnaryReactor * /*reactor*/) override {} -# else +#else void Export( ::grpc::ClientContext * /*context*/, const ::opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest @@ -114,7 +108,7 @@ class OtlpMockMetricsServiceStub : public proto::collector::metrics::v1::MockMet ::opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceResponse * /*response*/, ::grpc::experimental::ClientUnaryReactor * /*reactor*/) {} -# endif +#endif private: OtlpMockMetricsServiceStub *stub_; @@ -193,7 +187,7 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigSslCredentialsTest) EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); } -# ifndef NO_GETENV +#ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigFromEnv) { @@ -361,7 +355,7 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigRetryGenericValuesFromEnv) unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_MAX_BACKOFF"); unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_BACKOFF_MULTIPLIER"); } -# endif // NO_GETENV +#endif // NO_GETENV TEST_F(OtlpGrpcMetricExporterTestPeer, CheckGetAggregationTemporality) { @@ -450,4 +444,3 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, ExportPartialSuccess) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index b7a346c866..a6532cbbed 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -1,50 +1,64 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef OPENTELEMETRY_STL_VERSION - -# include -# include - -# include "opentelemetry/exporters/otlp/otlp_http_exporter.h" -# include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - -# include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -# include "opentelemetry/ext/http/client/http_client_factory.h" -# include "opentelemetry/ext/http/server/http_server.h" -# include "opentelemetry/sdk/common/global_log_handler.h" -# include "opentelemetry/sdk/trace/batch_span_processor.h" -# include "opentelemetry/sdk/trace/batch_span_processor_options.h" -# include "opentelemetry/sdk/trace/simple_processor.h" -# include "opentelemetry/sdk/trace/simple_processor_factory.h" -# include "opentelemetry/sdk/trace/tracer_provider.h" -# include "opentelemetry/sdk/trace/tracer_provider_factory.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 "opentelemetry/test_common/sdk/common/scoped_test_log_handler.h" -# include "opentelemetry/trace/provider.h" -# include "opentelemetry/trace/tracer_provider.h" - -# include -# include -# include - -# include -# include -# include "gmock/gmock.h" - -# include "nlohmann/json.hpp" - -# if defined(_MSC_VER) -# include "opentelemetry/sdk/common/env_variables.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gmock/gmock.h" +#include "nlohmann/json.hpp" + +#include "opentelemetry/common/timestamp.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#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/ext/http/client/http_client.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/common/thread_instrumentation.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/batch_span_processor.h" +#include "opentelemetry/sdk/trace/batch_span_processor_options.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.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 "opentelemetry/test_common/sdk/common/scoped_test_log_handler.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_startoptions.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/version.h" + +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/trace/v1/trace.pb.h" +#include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on + +// IWYU pragma: no_include + +#if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; -# endif +#endif using namespace testing; OPENTELEMETRY_BEGIN_NAMESPACE @@ -247,7 +261,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test EXPECT_GE(received_trace_id_counter, 1); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT void ExportJsonIntegrationTestAsync() { auto mock_otlp_client = @@ -362,7 +376,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test // Exporting can be retried EXPECT_GE(received_trace_id_counter, 1); } -# endif +#endif void ExportBinaryIntegrationTest() { @@ -460,7 +474,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test EXPECT_GE(received_trace_id_counter, 1); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT void ExportBinaryIntegrationTestAsync() { auto mock_otlp_client = @@ -560,7 +574,7 @@ class OtlpHttpExporterTestPeer : public ::testing::Test // Exporting can be retried EXPECT_GE(received_trace_id_counter, 1); } -# endif +#endif }; TEST(OtlpHttpExporterTest, Shutdown) @@ -581,13 +595,13 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTestSync) ExportJsonIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTestAsync) { ExportJsonIntegrationTestAsync(); static ProtobufGlobalSymbolGuard global_symbol_guard; } -# endif +#endif // Create spans, let processor call Export() TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTestSync) @@ -595,12 +609,12 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTestSync) ExportBinaryIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTestAsync) { ExportBinaryIntegrationTestAsync(); } -# endif +#endif // Test exporter configuration options TEST_F(OtlpHttpExporterTestPeer, ConfigTest) @@ -635,7 +649,7 @@ TEST(OtlpHttpExporterTest, ConfigDefaultProtocolTest) EXPECT_EQ(opts.content_type, HttpRequestContentType::kBinary); } -# ifndef NO_GETENV +#ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpHttpExporterTestPeer, ConfigFromEnv) { @@ -772,9 +786,9 @@ TEST_F(OtlpHttpExporterTestPeer, ConfigRetryGenericValuesFromEnv) unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_MAX_BACKOFF"); unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_BACKOFF_MULTIPLIER"); } -# endif // NO_GETENV +#endif // NO_GETENV -# ifdef ENABLE_OTLP_RETRY_PREVIEW +#ifdef ENABLE_OTLP_RETRY_PREVIEW using StatusCodeVector = std::vector; class OtlpHttpExporterRetryIntegrationTests @@ -877,7 +891,7 @@ TEST_P(OtlpHttpExporterRetryIntegrationTests, StatusCodes) ASSERT_EQ(expected_attempts, request_count); } -# endif // ENABLE_OTLP_RETRY_PREVIEW +#endif // ENABLE_OTLP_RETRY_PREVIEW using opentelemetry::test_common::ScopedTestLogHandler; @@ -964,7 +978,7 @@ TEST_F(OtlpHttpExporterTestPeer, ExportPartialSuccessJson) } // A malformed response body on a 2xx should return as kFailure for sync exports. -# ifndef ENABLE_ASYNC_EXPORT +#ifndef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpExporterTestPeer, ExportParseFailureReturnsFailure) { std::string serialized = "{some bad JSON"; @@ -990,9 +1004,8 @@ TEST_F(OtlpHttpExporterTestPeer, ExportParseFailureReturnsFailure) nostd::span> batch(&recordable, 1); EXPECT_EQ(sdk::common::ExportResult::kFailure, exporter->Export(batch)); } -# endif +#endif } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc index 918d21b515..f30e8906d1 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -1,47 +1,63 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef OPENTELEMETRY_STL_VERSION - -# include -# include -# include -# include -# include - -# include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - -# include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" - -# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - -# include "opentelemetry/common/key_value_iterable_view.h" -# include "opentelemetry/ext/http/client/http_client_factory.h" -# include "opentelemetry/ext/http/server/http_server.h" -# include "opentelemetry/logs/provider.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/sdk/common/global_log_handler.h" -# include "opentelemetry/sdk/logs/batch_log_record_processor.h" -# include "opentelemetry/sdk/logs/exporter.h" -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/resource/resource.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 "opentelemetry/test_common/sdk/common/scoped_test_log_handler.h" - -# include -# include -# include "gmock/gmock.h" - -# include "nlohmann/json.hpp" - -# if defined(_MSC_VER) -# include "opentelemetry/sdk/common/env_variables.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gmock/gmock.h" +#include "nlohmann/json.hpp" + +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#include "opentelemetry/exporters/otlp/otlp_http_client.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" +#include "opentelemetry/ext/http/client/http_client.h" +#include "opentelemetry/logs/logger.h" +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/proto/common/v1/common.pb.h" +#include "opentelemetry/proto/logs/v1/logs.pb.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/common/thread_instrumentation.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/recordable.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 "opentelemetry/test_common/sdk/common/scoped_test_log_handler.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_flags.h" +#include "opentelemetry/trace/trace_id.h" +#include "opentelemetry/version.h" + +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep +#include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep +// clang-format on + +// IWYU pragma: no_include +// IWYU pragma: no_include + +#if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; -# endif +#endif using namespace testing; @@ -265,7 +281,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test EXPECT_GE(received_record_counter, 1); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT void ExportJsonIntegrationTestAsync() { auto mock_otlp_client = OtlpHttpLogRecordExporterTestPeer::GetMockOtlpHttpClient( @@ -411,7 +427,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test // Exporting can be retried EXPECT_GE(received_record_counter, 1); } -# endif +#endif void ExportBinaryIntegrationTest() { @@ -539,7 +555,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test EXPECT_GE(received_record_counter, 1); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT void ExportBinaryIntegrationTestAsync() { auto mock_otlp_client = OtlpHttpLogRecordExporterTestPeer::GetMockOtlpHttpClient( @@ -669,7 +685,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test // Exporting can be retried EXPECT_GE(received_record_counter, 1); } -# endif +#endif }; TEST(OtlpHttpLogRecordExporterTest, Shutdown) @@ -690,13 +706,13 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportJsonIntegrationTestSync) ExportJsonIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportJsonIntegrationTestAsync) { ExportJsonIntegrationTestAsync(); static ProtobufGlobalSymbolGuard global_symbol_guard; } -# endif +#endif // Create log records, let processor call Export() TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestSync) @@ -704,12 +720,12 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestSync) ExportBinaryIntegrationTest(); } -# ifdef ENABLE_ASYNC_EXPORT +#ifdef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportBinaryIntegrationTestAsync) { ExportBinaryIntegrationTestAsync(); } -# endif +#endif // Test exporter configuration options TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigTest) @@ -747,7 +763,7 @@ TEST(OtlpHttpLogRecordExporterTest, ConfigDefaultProtocolTest) EXPECT_EQ(opts.content_type, HttpRequestContentType::kBinary); } -# ifndef NO_GETENV +#ifndef NO_GETENV // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigFromEnv) { @@ -896,7 +912,7 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ConfigRetryGenericValuesFromEnv) unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_MAX_BACKOFF"); unsetenv("OTEL_CPP_EXPORTER_OTLP_RETRY_BACKOFF_MULTIPLIER"); } -# endif // NO_GETENV +#endif // NO_GETENV // Exporter logs the rejection on partial_success. TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportPartialSuccess) @@ -979,7 +995,7 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportPartialSuccessJson) } // A malformed response body on a 2xx should return as kFailure for sync exports. -# ifndef ENABLE_ASYNC_EXPORT +#ifndef ENABLE_ASYNC_EXPORT TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportParseFailureReturnsFailure) { std::string serialized = "{some bad JSON"; @@ -1004,9 +1020,8 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, ExportParseFailureReturnsFailure) nostd::span> batch(&recordable, 1); EXPECT_EQ(opentelemetry::sdk::common::ExportResult::kFailure, exporter->Export(batch)); } -# endif +#endif } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif /* OPENTELEMETRY_STL_VERSION */ From bbc306d1ab9f24ba33d6e007f58024ae89e63e5d Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 10 Jul 2026 02:31:05 +0200 Subject: [PATCH 3/3] Cleanup --- exporters/otlp/test/otlp_grpc_exporter_test.cc | 14 ++++++++++++++ exporters/otlp/test/otlp_http_exporter_test.cc | 12 ++++++++++++ .../test/otlp_http_log_record_exporter_test.cc | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/exporters/otlp/test/otlp_grpc_exporter_test.cc b/exporters/otlp/test/otlp_grpc_exporter_test.cc index e53ffc31ee..9fa3bda9e5 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_test.cc @@ -41,6 +41,20 @@ // IWYU pragma: no_include // IWYU pragma: no_include +#ifdef ENABLE_OTLP_RETRY_PREVIEW +# include +# include +# include +# include +# include + +// IWYU pragma: no_include + +# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" +# include "opentelemetry/sdk/trace/simple_processor_factory.h" +# include "opentelemetry/sdk/trace/tracer_provider_factory.h" +#endif + #if defined(_MSC_VER) # include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index a6532cbbed..82c8e156fe 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -54,6 +54,18 @@ // IWYU pragma: no_include +#ifdef ENABLE_OTLP_RETRY_PREVIEW +# include +# include +# include +# include + +# include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" +# include "opentelemetry/ext/http/server/http_server.h" +# include "opentelemetry/sdk/trace/simple_processor_factory.h" +# include "opentelemetry/sdk/trace/tracer_provider_factory.h" +#endif + #if defined(_MSC_VER) # include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv; diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc index f30e8906d1..dafaadb1e1 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -53,6 +53,10 @@ // IWYU pragma: no_include // IWYU pragma: no_include +#ifdef ENABLE_ASYNC_EXPORT +# include +#endif + #if defined(_MSC_VER) # include "opentelemetry/sdk/common/env_variables.h" using opentelemetry::sdk::common::setenv;