11// Copyright The OpenTelemetry Authors
22// SPDX-License-Identifier: Apache-2.0
33
4- #ifndef OPENTELEMETRY_STL_VERSION
5- // Unfortunately as of 04/27/2021 the fix is NOT in the vcpkg snapshot of Google Test.
6- // Remove above `#ifdef` once the GMock fix for C++20 is in the mainline.
7- //
8- // Please refer to this GitHub issue for additional details:
9- // https://github.com/google/googletest/issues/2914
10- // https://github.com/google/googletest/commit/61f010d703b32de9bfb20ab90ece38ab2f25977f
11- //
12- // If we compile using Visual Studio 2019 with `c++latest` (C++20) without the GMock fix,
13- // then the compilation here fails in `gmock-actions.h` from:
14- // .\tools\vcpkg\installed\x64-windows\include\gmock\gmock-actions.h(819):
15- // error C2653: 'result_of': is not a class or namespace name
16- //
17- // That is because `std::result_of` has been removed in C++20.
18-
19- # include " opentelemetry/exporters/otlp/otlp_grpc_exporter.h"
20- # include " opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h"
21- # include " opentelemetry/exporters/otlp/protobuf_include_prefix.h"
22-
23- // Problematic code that pulls in Gmock and breaks with vs2019/c++latest :
24- # include " opentelemetry/proto/collector/trace/v1/trace_service_mock.grpc.pb.h"
25-
26- # include " opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h"
4+ #include < grpcpp/grpcpp.h>
5+ #include < gtest/gtest.h>
6+ #include < algorithm>
7+ #include < chrono>
8+ #include < cstddef>
9+ #include < cstdlib>
10+ #include < functional>
11+ #include < map>
12+ #include < mutex>
13+ #include < string>
14+ #include < thread>
15+ #include < utility>
16+ #include < vector>
17+ #include " gmock/gmock.h"
18+
19+ #include " opentelemetry/exporters/otlp/otlp_grpc_exporter.h"
20+ #include " opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h"
21+ #include " opentelemetry/nostd/shared_ptr.h"
22+ #include " opentelemetry/nostd/span.h"
23+ #include " opentelemetry/sdk/common/exporter_utils.h"
24+ #include " opentelemetry/sdk/common/global_log_handler.h"
25+ #include " opentelemetry/sdk/trace/exporter.h"
26+ #include " opentelemetry/sdk/trace/processor.h"
27+ #include " opentelemetry/sdk/trace/recordable.h"
28+ #include " opentelemetry/sdk/trace/simple_processor.h"
29+ #include " opentelemetry/sdk/trace/tracer_provider.h"
30+ #include " opentelemetry/test_common/sdk/common/scoped_test_log_handler.h"
31+ #include " opentelemetry/trace/span.h"
32+ #include " opentelemetry/trace/tracer.h"
33+ #include " opentelemetry/trace/tracer_provider.h"
34+ #include " opentelemetry/version.h"
35+
36+ // clang-format off
37+ #include " opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep
38+ #include " opentelemetry/proto/collector/trace/v1/trace_service.pb.h"
39+ #include " opentelemetry/proto/collector/trace/v1/trace_service_mock.grpc.pb.h"
40+ #include " opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h"
41+ #include " opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep
42+ // clang-format on
43+
44+ // IWYU pragma: no_include <grpc/support/port_platform.h>
45+ // IWYU pragma: no_include <grpcpp/support/status.h>
46+
47+ #ifdef ENABLE_OTLP_RETRY_PREVIEW
48+ # include < future>
49+ # include < tuple>
50+ # include < variant>
2751
28- # include " opentelemetry/exporters/otlp/protobuf_include_suffix.h "
52+ // IWYU pragma: no_include <grpcpp/security/server_credentials.h>
2953
30- # include " opentelemetry/nostd/shared_ptr.h"
31- # include " opentelemetry/sdk/common/global_log_handler.h"
32- # include " opentelemetry/sdk/trace/simple_processor.h"
54+ # include " opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h"
3355# include " opentelemetry/sdk/trace/simple_processor_factory.h"
34- # include " opentelemetry/sdk/trace/tracer_provider.h"
3556# include " opentelemetry/sdk/trace/tracer_provider_factory.h"
36- # include " opentelemetry/test_common/sdk/common/scoped_test_log_handler.h"
37- # include " opentelemetry/trace/provider.h"
38- # include " opentelemetry/trace/tracer_provider.h"
39-
40- # include < grpcpp/grpcpp.h>
41- # include < gtest/gtest.h>
42- # include < algorithm>
43- # include < chrono>
44- # include < cstddef>
45- # include < functional>
46- # include < future>
47- # include < memory>
48- # include < mutex>
49- # include < thread>
50- # include < utility>
51- # include < vector>
52-
53- # if defined(_MSC_VER)
54- # include " opentelemetry/sdk/common/env_variables.h"
57+ #endif
58+
59+ #if defined(_MSC_VER)
60+ # include " opentelemetry/sdk/common/env_variables.h"
5561using opentelemetry::sdk::common::setenv;
5662using opentelemetry::sdk::common::unsetenv;
57- # endif
63+ #endif
5864
59- # if defined(GRPC_CPP_VERSION_MAJOR) && \
60- (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR ) >= 1039 || \
61- defined (GRPC_CALLBACK_API_NONEXPERIMENTAL )
62- # define OTELCPP_GRPC_ASYNC_API_IS_STABLE
63- # endif
65+ #if defined(GRPC_CPP_VERSION_MAJOR) && \
66+ (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR ) >= 1039 || \
67+ defined (GRPC_CALLBACK_API_NONEXPERIMENTAL )
68+ # define OTELCPP_GRPC_ASYNC_API_IS_STABLE
69+ #endif
6470
6571using namespace testing ;
6672
@@ -76,13 +82,13 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe
7682{
7783public:
7884// Some old toolchains can only use gRPC 1.33 and it's experimental.
79- # if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
85+ #if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
8086 using async_interface_base =
8187 proto::collector::trace::v1::TraceService::StubInterface::async_interface;
82- # else
88+ #else
8389 using async_interface_base =
8490 proto::collector::trace::v1::TraceService::StubInterface::experimental_async_interface;
85- # endif
91+ #endif
8692
8793 OtlpMockTraceServiceStub () : async_interface_(this ) {}
8894
@@ -109,31 +115,31 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe
109115 }
110116
111117// Some old toolchains can only use gRPC 1.33 and it's experimental.
112- # if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
118+ #if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
113119 void Export (
114120 ::grpc::ClientContext * /* context*/ ,
115121 const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest * /* request*/ ,
116122 ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceResponse * /* response*/ ,
117123 ::grpc::ClientUnaryReactor * /* reactor*/ ) override
118124 {}
119- # else
125+ #else
120126 void Export (
121127 ::grpc::ClientContext * /* context*/ ,
122128 const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest * /* request*/ ,
123129 ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceResponse * /* response*/ ,
124130 ::grpc::experimental::ClientUnaryReactor * /* reactor*/ )
125131 {}
126- # endif
132+ #endif
127133
128134 private:
129135 OtlpMockTraceServiceStub *stub_;
130136 };
131137
132- # if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
138+ #if defined(OTELCPP_GRPC_ASYNC_API_IS_STABLE)
133139 async_interface_base *async () override { return &async_interface_; }
134- # else
140+ #else
135141 async_interface_base *experimental_async () override { return &async_interface_; }
136- # endif
142+ #endif
137143
138144 ::grpc::Status GetLastAsyncStatus () const noexcept { return last_async_status_; }
139145
@@ -271,12 +277,12 @@ TEST_F(OtlpGrpcExporterTestPeer, ExportUnitTest)
271277 .WillOnce (Return (grpc::Status::CANCELLED ));
272278 result = exporter->Export (batch_2);
273279 exporter->ForceFlush ();
274- # if defined(ENABLE_ASYNC_EXPORT)
280+ #if defined(ENABLE_ASYNC_EXPORT)
275281 EXPECT_EQ (sdk::common::ExportResult::kSuccess , result);
276282 EXPECT_FALSE (mock_stub->GetLastAsyncStatus ().ok ());
277- # else
283+ #else
278284 EXPECT_EQ (sdk::common::ExportResult::kFailure , result);
279- # endif
285+ #endif
280286}
281287
282288// Exporter logs the rejection on partial_success.
@@ -330,9 +336,9 @@ class OtlpGrpcExporterFlushTestPeer : public OtlpGrpcExporterTestPeer
330336protected:
331337 void SetUp () override
332338 {
333- # if !defined(ENABLE_ASYNC_EXPORT)
339+ #if !defined(ENABLE_ASYNC_EXPORT)
334340 GTEST_SKIP () << " ForceFlush has no in-flight requests to wait for without async export" ;
335- # endif
341+ #endif
336342 }
337343};
338344
@@ -452,7 +458,7 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigSslCredentialsTest)
452458 EXPECT_EQ (GetOptions (exporter).use_ssl_credentials , true );
453459}
454460
455- # ifndef NO_GETENV
461+ #ifndef NO_GETENV
456462// Test exporter configuration options with use_ssl_credentials
457463TEST_F (OtlpGrpcExporterTestPeer, ConfigFromEnv)
458464{
@@ -612,9 +618,9 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigRetryGenericValuesFromEnv)
612618 unsetenv (" OTEL_CPP_EXPORTER_OTLP_RETRY_MAX_BACKOFF" );
613619 unsetenv (" OTEL_CPP_EXPORTER_OTLP_RETRY_BACKOFF_MULTIPLIER" );
614620}
615- # endif // NO_GETENV
621+ #endif // NO_GETENV
616622
617- # ifdef ENABLE_OTLP_RETRY_PREVIEW
623+ #ifdef ENABLE_OTLP_RETRY_PREVIEW
618624namespace
619625{
620626struct TestTraceService : public opentelemetry ::proto::collector::trace::v1::TraceService::Service
@@ -774,9 +780,8 @@ TEST_P(OtlpGrpcExporterRetryIntegrationTests, StatusCodes)
774780
775781 ASSERT_EQ (expected_attempts, service.request_count_ );
776782}
777- # endif // ENABLE_OTLP_RETRY_PREVIEW
783+ #endif // ENABLE_OTLP_RETRY_PREVIEW
778784
779785} // namespace otlp
780786} // namespace exporter
781787OPENTELEMETRY_END_NAMESPACE
782- #endif /* OPENTELEMETRY_STL_VERSION */
0 commit comments