Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 59 additions & 55 deletions exporters/otlp/test/otlp_grpc_exporter_test.cc
Original file line number Diff line number Diff line change
@@ -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 <grpc/support/port_platform.h>
#include <grpcpp/grpcpp.h>
#include <grpcpp/security/server_credentials.h>
#include <grpcpp/support/status.h>
#include <gtest/gtest.h>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <future>
#include <map>
#include <string>
#include <thread>
#include <tuple>
#include <utility>
#include <variant>
#include <vector>
#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 <grpcpp/grpcpp.h>
# include <gtest/gtest.h>
# include <future>

# 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;

Expand All @@ -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) {}

Expand All @@ -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_;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<grpc::StatusCode> &status_codes) : status_codes_(status_codes)
Expand Down Expand Up @@ -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 */
68 changes: 28 additions & 40 deletions exporters/otlp/test/otlp_grpc_metric_exporter_test.cc
Original file line number Diff line number Diff line change
@@ -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 <grpcpp/grpcpp.h>
# include <gtest/gtest.h>

# if defined(_MSC_VER)
# include "opentelemetry/sdk/common/env_variables.h"
#include <gtest/gtest.h>
#include <stdlib.h>
#include <chrono>
#include <map>
#include <memory>
#include <string>
#include <utility>

#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;

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -303,4 +292,3 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, CheckGetAggregationTemporality)
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
#endif /* OPENTELEMETRY_STL_VERSION */
48 changes: 27 additions & 21 deletions exporters/otlp/test/otlp_http_exporter_custom_client_test.cc
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#ifndef OPENTELEMETRY_STL_VERSION

# include <chrono>

# 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 <gtest/gtest.h>
# include "gmock/gmock.h"
#include <gtest/gtest.h>
#include <chrono>
#include <string>
#include <utility>
#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;

Expand Down Expand Up @@ -148,5 +156,3 @@ TEST_F(OtlpHttpExporterCustomClientTestPeer, ExportCallsSendRequest)
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE

#endif // OPENTELEMETRY_STL_VERSION
Loading
Loading