From 4367e62cc0156fb2d2b1f14634838fdb5700f9e4 Mon Sep 17 00:00:00 2001 From: owent Date: Wed, 30 Oct 2024 23:26:52 +0800 Subject: [PATCH] Change unique_ptr and shared_ptr from `nostd::` to `std::`. Change the include order --- CMakeLists.txt | 12 +++--------- api/CMakeLists.txt | 2 +- cmake/opentelemetry-cpp-config.cmake.in | 9 ++++++++- cmake/opentelemetry-proto.cmake | 16 ++++++++++++---- .../exporters/otlp/otlp_grpc_client_factory.h | 4 ++-- .../exporters/otlp/otlp_grpc_exporter.h | 12 ++++++------ .../exporters/otlp/otlp_grpc_exporter_factory.h | 2 +- .../otlp/otlp_grpc_log_record_exporter.h | 12 ++++++------ .../otlp/otlp_grpc_log_record_exporter_factory.h | 2 +- .../exporters/otlp/otlp_grpc_metric_exporter.h | 12 ++++++------ .../otlp/otlp_grpc_metric_exporter_factory.h | 2 +- exporters/otlp/src/otlp_grpc_client_factory.cc | 9 ++++----- exporters/otlp/src/otlp_grpc_exporter.cc | 16 ++++++++-------- exporters/otlp/src/otlp_grpc_exporter_factory.cc | 4 ++-- .../otlp/src/otlp_grpc_log_record_exporter.cc | 16 ++++++++-------- .../src/otlp_grpc_log_record_exporter_factory.cc | 4 ++-- exporters/otlp/src/otlp_grpc_metric_exporter.cc | 16 ++++++++-------- .../src/otlp_grpc_metric_exporter_factory.cc | 4 ++-- .../otlp/test/otlp_grpc_exporter_factory_test.cc | 2 +- ...otlp_grpc_log_record_exporter_factory_test.cc | 2 +- .../test/otlp_grpc_log_record_exporter_test.cc | 6 +++--- .../otlp_grpc_metric_exporter_factory_test.cc | 2 +- 22 files changed, 87 insertions(+), 79 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index add762344a..fe2477cf54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -369,7 +369,7 @@ if(WITH_PROMETHEUS) endif() endif() -if(WITH_ABSEIL OR WITH_OTLP_GRPC) +if(WITH_ABSEIL) if(NOT TARGET absl::strings) find_package(absl CONFIG REQUIRED) endif() @@ -379,14 +379,8 @@ if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP OR WITH_OTLP_FILE) find_package(Protobuf) - if(Protobuf_VERSION AND Protobuf_VERSION VERSION_GREATER_EQUAL "3.22.0") - if(NOT WITH_ABSEIL AND NOT WITH_OTLP_GRPC) - message( - FATAL_ERROR - "Protobuf 3.22 or upper require abseil-cpp(Recommended version: 20230125 or upper)" - ) - endif() - endif() + # Protobuf 3.22 or upper require abseil-cpp, we can find it in + # opentelemetry-cpp-config.cmake if(WITH_OTLP_GRPC) find_package(gRPC) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 6a3b047f97..78e97ad029 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -35,7 +35,7 @@ if(WITH_NO_DEPRECATED_CODE) INTERFACE OPENTELEMETRY_NO_DEPRECATED_CODE) endif() -if(WITH_ABSEIL OR WITH_OTLP_GRPC) +if(WITH_ABSEIL) target_compile_definitions(opentelemetry_api INTERFACE HAVE_ABSEIL) target_link_libraries( opentelemetry_api INTERFACE absl::bad_variant_access absl::any absl::base diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index 36215c8af7..028b3cd68e 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -7,7 +7,6 @@ # # Find the native opentelemetry-cpp includes and library. # -# # Result Variables # ^^^^^^^^^^^^^^^^ # @@ -72,6 +71,14 @@ set(OPENTELEMETRY_VERSION find_package(Threads) +if(@WITH_ABSEIL@ OR @WITH_OTLP_GRPC@) + find_package(absl CONFIG) +elseif(OR @WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@) + if("@Protobuf_VERSION@" VERSION_GREATER_EQUAL "3.22.0") + find_package(absl CONFIG) + endif() +endif() + set_and_check(OPENTELEMETRY_CPP_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") set_and_check(OPENTELEMETRY_CPP_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_LIBDIR@") diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 78e0b746ff..beb60c4283 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -331,10 +331,20 @@ set_target_version(opentelemetry_proto) set_target_properties(opentelemetry_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "") -if(WITH_ABSEIL OR WITH_OTLP_GRPC) +if(TARGET absl::bad_variant_access) target_link_libraries(opentelemetry_proto PUBLIC absl::bad_variant_access) endif() +if(NOT Protobuf_INCLUDE_DIRS AND TARGET protobuf::libprotobuf) + get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf + INTERFACE_INCLUDE_DIRECTORIES) +endif() +if(Protobuf_INCLUDE_DIRS) + target_include_directories( + opentelemetry_proto BEFORE + PUBLIC "$") endif() endif() @@ -385,8 +395,6 @@ endif() if(TARGET protobuf::libprotobuf) target_link_libraries(opentelemetry_proto PUBLIC protobuf::libprotobuf) else() # cmake 3.8 or lower - target_include_directories(opentelemetry_proto - PUBLIC ${Protobuf_INCLUDE_DIRS}) target_link_libraries(opentelemetry_proto PUBLIC ${Protobuf_LIBRARIES}) endif() diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_factory.h index a59c478937..ded0eadd8e 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_factory.h @@ -26,9 +26,9 @@ class OPENTELEMETRY_EXPORT OtlpGrpcClientFactory /** * Create an OtlpGrpcClient using all default options. */ - static nostd::shared_ptr Create(const OtlpGrpcClientOptions &options); + static std::shared_ptr Create(const OtlpGrpcClientOptions &options); - static nostd::shared_ptr CreateReferenceGuard(); + static std::shared_ptr CreateReferenceGuard(); }; } // namespace otlp 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 58d27580b2..1022b0dc8f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h @@ -50,7 +50,7 @@ class OtlpGrpcExporter final : public opentelemetry::sdk::trace::SpanExporter * @param client the gRPC client to use */ OtlpGrpcExporter(const OtlpGrpcExporterOptions &options, - nostd::shared_ptr client); + const std::shared_ptr &client); /** * Create an OtlpGrpcExporter using the given options. @@ -94,21 +94,21 @@ class OtlpGrpcExporter final : public opentelemetry::sdk::trace::SpanExporter * * @return return binded gRPC client */ - const nostd::shared_ptr &GetClient() const noexcept; + const std::shared_ptr &GetClient() const noexcept; private: // The configuration options associated with this exporter. const OtlpGrpcExporterOptions options_; - nostd::shared_ptr client_; - nostd::shared_ptr client_reference_guard_; + std::shared_ptr client_; + std::shared_ptr client_reference_guard_; // For testing friend class OtlpGrpcExporterTestPeer; friend class OtlpGrpcLogRecordExporterTestPeer; // Store service stub internally. Useful for testing. - nostd::shared_ptr trace_service_stub_; + std::shared_ptr trace_service_stub_; /** * Create an OtlpGrpcExporter using the specified service stub. @@ -124,7 +124,7 @@ class OtlpGrpcExporter final : public opentelemetry::sdk::trace::SpanExporter * @param client the gRPC client to use */ OtlpGrpcExporter(std::unique_ptr stub, - nostd::shared_ptr client); + const std::shared_ptr &client); std::atomic is_shutdown_{false}; bool isShutdown() const noexcept; diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h index 3bf81adfa6..24d19d5ced 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h @@ -39,7 +39,7 @@ class OPENTELEMETRY_EXPORT OtlpGrpcExporterFactory */ static std::unique_ptr Create( const OtlpGrpcExporterOptions &options, - nostd::shared_ptr client); + const std::shared_ptr &client); }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h index 68b100a9fc..da278ccd28 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h @@ -48,7 +48,7 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo * @param client the gRPC client to use */ OtlpGrpcLogRecordExporter(const OtlpGrpcLogRecordExporterOptions &options, - nostd::shared_ptr client); + const std::shared_ptr &client); /** * Create an OtlpGrpcLogRecordExporter with user specified options. @@ -93,20 +93,20 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo * * @return return binded gRPC client */ - const nostd::shared_ptr &GetClient() const noexcept; + const std::shared_ptr &GetClient() const noexcept; private: // Configuration options for the exporter const OtlpGrpcLogRecordExporterOptions options_; - nostd::shared_ptr client_; - nostd::shared_ptr client_reference_guard_; + std::shared_ptr client_; + std::shared_ptr client_reference_guard_; // For testing friend class OtlpGrpcLogRecordExporterTestPeer; // Store service stub internally. Useful for testing. - nostd::shared_ptr log_service_stub_; + std::shared_ptr log_service_stub_; /** * Create an OtlpGrpcLogRecordExporter using the specified service stub. @@ -124,7 +124,7 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo */ OtlpGrpcLogRecordExporter( std::unique_ptr stub, - nostd::shared_ptr client); + const std::shared_ptr &client); std::atomic is_shutdown_{false}; bool isShutdown() const noexcept; diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h index 486bab7bdb..e69a20b452 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h @@ -37,7 +37,7 @@ class OPENTELEMETRY_EXPORT OtlpGrpcLogRecordExporterFactory */ static std::unique_ptr Create( const OtlpGrpcLogRecordExporterOptions &options, - nostd::shared_ptr client); + const std::shared_ptr &client); }; } // namespace otlp 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 121ac933d4..d3d857b3f0 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 @@ -47,7 +47,7 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp * @param client the gRPC client to use */ OtlpGrpcMetricExporter(const OtlpGrpcMetricExporterOptions &options, - nostd::shared_ptr client); + const std::shared_ptr &client); /** * Create an OtlpGrpcMetricExporter using the given options. @@ -78,14 +78,14 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp * * @return return binded gRPC client */ - const nostd::shared_ptr &GetClient() const noexcept; + const std::shared_ptr &GetClient() const noexcept; private: // The configuration options associated with this exporter. const OtlpGrpcMetricExporterOptions options_; - nostd::shared_ptr client_; - nostd::shared_ptr client_reference_guard_; + std::shared_ptr client_; + std::shared_ptr client_reference_guard_; // Aggregation Temporality selector const sdk::metrics::AggregationTemporalitySelector aggregation_temporality_selector_; @@ -94,7 +94,7 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp friend class OtlpGrpcMetricExporterTestPeer; // Store service stub internally. Useful for testing. - nostd::shared_ptr + std::shared_ptr metrics_service_stub_; /** @@ -113,7 +113,7 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp */ OtlpGrpcMetricExporter( std::unique_ptr stub, - nostd::shared_ptr client); + const std::shared_ptr &client); std::atomic is_shutdown_{false}; bool isShutdown() const noexcept; diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h index db38f937fc..5d405609b0 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h @@ -39,7 +39,7 @@ class OPENTELEMETRY_EXPORT OtlpGrpcMetricExporterFactory */ static std::unique_ptr Create( const OtlpGrpcMetricExporterOptions &options, - nostd::shared_ptr client); + const std::shared_ptr &client); }; } // namespace otlp diff --git a/exporters/otlp/src/otlp_grpc_client_factory.cc b/exporters/otlp/src/otlp_grpc_client_factory.cc index 0529021e3f..310593a77a 100644 --- a/exporters/otlp/src/otlp_grpc_client_factory.cc +++ b/exporters/otlp/src/otlp_grpc_client_factory.cc @@ -12,15 +12,14 @@ namespace exporter namespace otlp { -nostd::shared_ptr OtlpGrpcClientFactory::Create( - const OtlpGrpcClientOptions &options) +std::shared_ptr OtlpGrpcClientFactory::Create(const OtlpGrpcClientOptions &options) { - return nostd::shared_ptr(new OtlpGrpcClient(options)); + return std::make_shared(options); } -nostd::shared_ptr OtlpGrpcClientFactory::CreateReferenceGuard() +std::shared_ptr OtlpGrpcClientFactory::CreateReferenceGuard() { - return nostd::shared_ptr(new OtlpGrpcClientReferenceGuard()); + return std::make_shared(); } } // namespace otlp diff --git a/exporters/otlp/src/otlp_grpc_exporter.cc b/exporters/otlp/src/otlp_grpc_exporter.cc index ad598a6a3e..e4012c2ebf 100644 --- a/exporters/otlp/src/otlp_grpc_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_exporter.cc @@ -43,9 +43,9 @@ OtlpGrpcExporter::OtlpGrpcExporter( } OtlpGrpcExporter::OtlpGrpcExporter(const OtlpGrpcExporterOptions &options, - nostd::shared_ptr client) + const std::shared_ptr &client) : options_(options), - client_(std::move(client)), + client_(client), client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()) { client_->AddReference(*client_reference_guard_, options_); @@ -55,9 +55,9 @@ OtlpGrpcExporter::OtlpGrpcExporter(const OtlpGrpcExporterOptions &options, OtlpGrpcExporter::OtlpGrpcExporter( std::unique_ptr stub, - nostd::shared_ptr client) + const std::shared_ptr &client) : options_(OtlpGrpcExporterOptions()), - client_(std::move(client)), + client_(client), client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()), trace_service_stub_(std::move(stub)) { @@ -82,7 +82,7 @@ std::unique_ptr OtlpGrpcExporter::MakeRecordable() noexc sdk::common::ExportResult OtlpGrpcExporter::Export( const nostd::span> &spans) noexcept { - nostd::shared_ptr client = client_; + std::shared_ptr client = client_; if (isShutdown() || !client) { OTEL_INTERNAL_LOG_ERROR("[OTLP gRPC] Exporting " << spans.size() @@ -170,7 +170,7 @@ bool OtlpGrpcExporter::ForceFlush( OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept { // Maybe already shutdown, we need to keep thread-safety here. - nostd::shared_ptr client = client_; + std::shared_ptr client = client_; if (!client) { return true; @@ -183,7 +183,7 @@ bool OtlpGrpcExporter::Shutdown( { is_shutdown_ = true; // Maybe already shutdown, we need to keep thread-safety here. - nostd::shared_ptr client; + std::shared_ptr client; client.swap(client_); if (!client) { @@ -197,7 +197,7 @@ bool OtlpGrpcExporter::isShutdown() const noexcept return is_shutdown_; } -const nostd::shared_ptr &OtlpGrpcExporter::GetClient() const noexcept +const std::shared_ptr &OtlpGrpcExporter::GetClient() const noexcept { return client_; } diff --git a/exporters/otlp/src/otlp_grpc_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_exporter_factory.cc index d8c78ea617..5ed832a3cd 100644 --- a/exporters/otlp/src/otlp_grpc_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_exporter_factory.cc @@ -29,10 +29,10 @@ std::unique_ptr OtlpGrpcExporterFactory std::unique_ptr OtlpGrpcExporterFactory::Create( const OtlpGrpcExporterOptions &options, - nostd::shared_ptr client) + const std::shared_ptr &client) { std::unique_ptr exporter( - new OtlpGrpcExporter(options, std::move(client))); + new OtlpGrpcExporter(options, client)); return exporter; } diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc index 881d80a0b7..fe05be7b30 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc @@ -57,9 +57,9 @@ OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( const OtlpGrpcLogRecordExporterOptions &options, - nostd::shared_ptr client) + const std::shared_ptr &client) : options_(options), - client_(std::move(client)), + client_(client), client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()) { client_->AddReference(*client_reference_guard_, options_); @@ -69,9 +69,9 @@ OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( std::unique_ptr stub, - nostd::shared_ptr client) + const std::shared_ptr &client) : options_(OtlpGrpcLogRecordExporterOptions()), - client_(std::move(client)), + client_(client), client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()), log_service_stub_(std::move(stub)) { @@ -97,7 +97,7 @@ OtlpGrpcLogRecordExporter::MakeRecordable() noexcept opentelemetry::sdk::common::ExportResult OtlpGrpcLogRecordExporter::Export( const nostd::span> &logs) noexcept { - nostd::shared_ptr client = client_; + std::shared_ptr client = client_; if (isShutdown() || !client) { OTEL_INTERNAL_LOG_ERROR("[OTLP gRPC log] Exporting " << logs.size() @@ -185,7 +185,7 @@ bool OtlpGrpcLogRecordExporter::Shutdown( { is_shutdown_ = true; // Maybe already shutdown, we need to keep thread-safety here. - nostd::shared_ptr client; + std::shared_ptr client; client.swap(client_); if (!client) { @@ -198,7 +198,7 @@ bool OtlpGrpcLogRecordExporter::ForceFlush( OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept { // Maybe already shutdown, we need to keep thread-safety here. - nostd::shared_ptr client = client_; + std::shared_ptr client = client_; if (!client) { return true; @@ -211,7 +211,7 @@ bool OtlpGrpcLogRecordExporter::isShutdown() const noexcept return is_shutdown_; } -const nostd::shared_ptr &OtlpGrpcLogRecordExporter::GetClient() const noexcept +const std::shared_ptr &OtlpGrpcLogRecordExporter::GetClient() const noexcept { return client_; } diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc index f07525e5fe..4b519e37e8 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc @@ -30,10 +30,10 @@ OtlpGrpcLogRecordExporterFactory::Create(const OtlpGrpcLogRecordExporterOptions std::unique_ptr OtlpGrpcLogRecordExporterFactory::Create(const OtlpGrpcLogRecordExporterOptions &options, - nostd::shared_ptr client) + const std::shared_ptr &client) { std::unique_ptr exporter( - new OtlpGrpcLogRecordExporter(options, std::move(client))); + new OtlpGrpcLogRecordExporter(options, client)); return exporter; } diff --git a/exporters/otlp/src/otlp_grpc_metric_exporter.cc b/exporters/otlp/src/otlp_grpc_metric_exporter.cc index b3b5f8a9f2..1723dd557a 100644 --- a/exporters/otlp/src/otlp_grpc_metric_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_metric_exporter.cc @@ -48,9 +48,9 @@ OtlpGrpcMetricExporter::OtlpGrpcMetricExporter( } OtlpGrpcMetricExporter::OtlpGrpcMetricExporter(const OtlpGrpcMetricExporterOptions &options, - nostd::shared_ptr client) + const std::shared_ptr &client) : options_(options), - client_(std::move(client)), + client_(client), client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()) { client_->AddReference(*client_reference_guard_, options_); @@ -60,9 +60,9 @@ OtlpGrpcMetricExporter::OtlpGrpcMetricExporter(const OtlpGrpcMetricExporterOptio OtlpGrpcMetricExporter::OtlpGrpcMetricExporter( std::unique_ptr stub, - nostd::shared_ptr client) + const std::shared_ptr &client) : options_(OtlpGrpcMetricExporterOptions()), - client_(std::move(client)), + client_(client), client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()), metrics_service_stub_(std::move(stub)) { @@ -88,7 +88,7 @@ sdk::metrics::AggregationTemporality OtlpGrpcMetricExporter::GetAggregationTempo opentelemetry::sdk::common::ExportResult OtlpGrpcMetricExporter::Export( const opentelemetry::sdk::metrics::ResourceMetrics &data) noexcept { - nostd::shared_ptr client = client_; + std::shared_ptr client = client_; if (isShutdown() || !client) { OTEL_INTERNAL_LOG_ERROR("[OTLP METRICS gRPC] Exporting " @@ -178,7 +178,7 @@ bool OtlpGrpcMetricExporter::ForceFlush( OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept { // Maybe already shutdown, we need to keep thread-safety here. - nostd::shared_ptr client = client_; + std::shared_ptr client = client_; if (!client) { return true; @@ -191,7 +191,7 @@ bool OtlpGrpcMetricExporter::Shutdown( { is_shutdown_ = true; // Maybe already shutdown, we need to keep thread-safety here. - nostd::shared_ptr client; + std::shared_ptr client; client.swap(client_); if (!client) { @@ -205,7 +205,7 @@ bool OtlpGrpcMetricExporter::isShutdown() const noexcept return is_shutdown_; } -const nostd::shared_ptr &OtlpGrpcMetricExporter::GetClient() const noexcept +const std::shared_ptr &OtlpGrpcMetricExporter::GetClient() const noexcept { return client_; } diff --git a/exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc index a6cd553d84..244d275722 100644 --- a/exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc @@ -30,10 +30,10 @@ OtlpGrpcMetricExporterFactory::Create(const OtlpGrpcMetricExporterOptions &optio std::unique_ptr OtlpGrpcMetricExporterFactory::Create(const OtlpGrpcMetricExporterOptions &options, - nostd::shared_ptr client) + const std::shared_ptr &client) { std::unique_ptr exporter( - new OtlpGrpcMetricExporter(options, std::move(client))); + new OtlpGrpcMetricExporter(options, client)); return exporter; } diff --git a/exporters/otlp/test/otlp_grpc_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_exporter_factory_test.cc index 0685baf7b9..a2fb62dab0 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_factory_test.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_factory_test.cc @@ -39,7 +39,7 @@ TEST(OtlpGrpcExporterFactoryTest, ShareClient) OtlpGrpcExporterOptions opts; opts.endpoint = "localhost:45454"; - nostd::shared_ptr client = OtlpGrpcClientFactory::Create(opts); + std::shared_ptr client = OtlpGrpcClientFactory::Create(opts); std::unique_ptr exporter1 = OtlpGrpcExporterFactory::Create(opts, client); diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc index d7f5032564..0d0ab17d62 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc @@ -39,7 +39,7 @@ TEST(OtlpGrpcLogRecordExporterFactoryTest, ShareClient) OtlpGrpcLogRecordExporterOptions opts; opts.endpoint = "localhost:45454"; - nostd::shared_ptr client = OtlpGrpcClientFactory::Create(opts); + std::shared_ptr client = OtlpGrpcClientFactory::Create(opts); std::unique_ptr exporter1 = OtlpGrpcLogRecordExporterFactory::Create(opts, client); diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc index 6d8e04d429..a2604de096 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -196,7 +196,7 @@ class OtlpGrpcLogRecordExporterTestPeer : public ::testing::Test std::unique_ptr GetExporter( std::unique_ptr &stub_interface, - nostd::shared_ptr client) + const std::shared_ptr &client) { return std::unique_ptr( new OtlpGrpcLogRecordExporter(std::move(stub_interface), std::move(client))); @@ -204,7 +204,7 @@ class OtlpGrpcLogRecordExporterTestPeer : public ::testing::Test std::unique_ptr GetExporter( std::unique_ptr &stub_interface, - nostd::shared_ptr client) + const std::shared_ptr &client) { return std::unique_ptr( new OtlpGrpcExporter(std::move(stub_interface), std::move(client))); @@ -359,7 +359,7 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) // Create spans, let processor call Export() and share client object between trace and logs TEST_F(OtlpGrpcLogRecordExporterTestPeer, ShareClientTest) { - nostd::shared_ptr shared_client = + std::shared_ptr shared_client = OtlpGrpcClientFactory::Create(OtlpGrpcLogRecordExporterOptions()); auto mock_stub = new OtlpMockLogsServiceStub(); diff --git a/exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc index 0e5cf00945..ecad49bee1 100644 --- a/exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc +++ b/exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc @@ -39,7 +39,7 @@ TEST(OtlpGrpcMetricExporterFactory, ShareClient) OtlpGrpcMetricExporterOptions opts; opts.endpoint = "localhost:45454"; - nostd::shared_ptr client = OtlpGrpcClientFactory::Create(opts); + std::shared_ptr client = OtlpGrpcClientFactory::Create(opts); std::unique_ptr exporter1 = OtlpGrpcMetricExporterFactory::Create(opts, client);