Skip to content

Commit

Permalink
Change unique_ptr and shared_ptr from nostd:: to std::. Change th…
Browse files Browse the repository at this point in the history
…e include order
  • Loading branch information
owent committed Oct 30, 2024
1 parent 94260b3 commit 4367e62
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 79 deletions.
12 changes: 3 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion cmake/opentelemetry-cpp-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#
# Find the native opentelemetry-cpp includes and library.
#
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
Expand Down Expand Up @@ -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@")

Expand Down
16 changes: 12 additions & 4 deletions cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<BUILD_INTERFACE:${Protobuf_INCLUDE_DIRS}")
endif()

if(WITH_OTLP_GRPC)
add_library(
opentelemetry_proto_grpc
Expand All @@ -356,7 +366,7 @@ if(WITH_OTLP_GRPC)
INTERFACE_INCLUDE_DIRECTORIES)
if(GRPC_INCLUDE_DIRECTORY)
target_include_directories(
opentelemetry_proto_grpc
opentelemetry_proto_grpc BEFORE
PUBLIC "$<BUILD_INTERFACE:${GRPC_INCLUDE_DIRECTORY}>")
endif()
endif()
Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class OPENTELEMETRY_EXPORT OtlpGrpcClientFactory
/**
* Create an OtlpGrpcClient using all default options.
*/
static nostd::shared_ptr<OtlpGrpcClient> Create(const OtlpGrpcClientOptions &options);
static std::shared_ptr<OtlpGrpcClient> Create(const OtlpGrpcClientOptions &options);

static nostd::shared_ptr<OtlpGrpcClientReferenceGuard> CreateReferenceGuard();
static std::shared_ptr<OtlpGrpcClientReferenceGuard> CreateReferenceGuard();
};

} // namespace otlp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OtlpGrpcClient> client);
const std::shared_ptr<OtlpGrpcClient> &client);

/**
* Create an OtlpGrpcExporter using the given options.
Expand Down Expand Up @@ -94,21 +94,21 @@ class OtlpGrpcExporter final : public opentelemetry::sdk::trace::SpanExporter
*
* @return return binded gRPC client
*/
const nostd::shared_ptr<OtlpGrpcClient> &GetClient() const noexcept;
const std::shared_ptr<OtlpGrpcClient> &GetClient() const noexcept;

private:
// The configuration options associated with this exporter.
const OtlpGrpcExporterOptions options_;

nostd::shared_ptr<OtlpGrpcClient> client_;
nostd::shared_ptr<OtlpGrpcClientReferenceGuard> client_reference_guard_;
std::shared_ptr<OtlpGrpcClient> client_;
std::shared_ptr<OtlpGrpcClientReferenceGuard> client_reference_guard_;

// For testing
friend class OtlpGrpcExporterTestPeer;
friend class OtlpGrpcLogRecordExporterTestPeer;

// Store service stub internally. Useful for testing.
nostd::shared_ptr<proto::collector::trace::v1::TraceService::StubInterface> trace_service_stub_;
std::shared_ptr<proto::collector::trace::v1::TraceService::StubInterface> trace_service_stub_;

/**
* Create an OtlpGrpcExporter using the specified service stub.
Expand All @@ -124,7 +124,7 @@ class OtlpGrpcExporter final : public opentelemetry::sdk::trace::SpanExporter
* @param client the gRPC client to use
*/
OtlpGrpcExporter(std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface> stub,
nostd::shared_ptr<OtlpGrpcClient> client);
const std::shared_ptr<OtlpGrpcClient> &client);

std::atomic<bool> is_shutdown_{false};
bool isShutdown() const noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OPENTELEMETRY_EXPORT OtlpGrpcExporterFactory
*/
static std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> Create(
const OtlpGrpcExporterOptions &options,
nostd::shared_ptr<OtlpGrpcClient> client);
const std::shared_ptr<OtlpGrpcClient> &client);
};

} // namespace otlp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OtlpGrpcClient> client);
const std::shared_ptr<OtlpGrpcClient> &client);

/**
* Create an OtlpGrpcLogRecordExporter with user specified options.
Expand Down Expand Up @@ -93,20 +93,20 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo
*
* @return return binded gRPC client
*/
const nostd::shared_ptr<OtlpGrpcClient> &GetClient() const noexcept;
const std::shared_ptr<OtlpGrpcClient> &GetClient() const noexcept;

private:
// Configuration options for the exporter
const OtlpGrpcLogRecordExporterOptions options_;

nostd::shared_ptr<OtlpGrpcClient> client_;
nostd::shared_ptr<OtlpGrpcClientReferenceGuard> client_reference_guard_;
std::shared_ptr<OtlpGrpcClient> client_;
std::shared_ptr<OtlpGrpcClientReferenceGuard> client_reference_guard_;

// For testing
friend class OtlpGrpcLogRecordExporterTestPeer;

// Store service stub internally. Useful for testing.
nostd::shared_ptr<proto::collector::logs::v1::LogsService::StubInterface> log_service_stub_;
std::shared_ptr<proto::collector::logs::v1::LogsService::StubInterface> log_service_stub_;

/**
* Create an OtlpGrpcLogRecordExporter using the specified service stub.
Expand All @@ -124,7 +124,7 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo
*/
OtlpGrpcLogRecordExporter(
std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface> stub,
nostd::shared_ptr<OtlpGrpcClient> client);
const std::shared_ptr<OtlpGrpcClient> &client);

std::atomic<bool> is_shutdown_{false};
bool isShutdown() const noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class OPENTELEMETRY_EXPORT OtlpGrpcLogRecordExporterFactory
*/
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(
const OtlpGrpcLogRecordExporterOptions &options,
nostd::shared_ptr<OtlpGrpcClient> client);
const std::shared_ptr<OtlpGrpcClient> &client);
};

} // namespace otlp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OtlpGrpcClient> client);
const std::shared_ptr<OtlpGrpcClient> &client);

/**
* Create an OtlpGrpcMetricExporter using the given options.
Expand Down Expand Up @@ -78,14 +78,14 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp
*
* @return return binded gRPC client
*/
const nostd::shared_ptr<OtlpGrpcClient> &GetClient() const noexcept;
const std::shared_ptr<OtlpGrpcClient> &GetClient() const noexcept;

private:
// The configuration options associated with this exporter.
const OtlpGrpcMetricExporterOptions options_;

nostd::shared_ptr<OtlpGrpcClient> client_;
nostd::shared_ptr<OtlpGrpcClientReferenceGuard> client_reference_guard_;
std::shared_ptr<OtlpGrpcClient> client_;
std::shared_ptr<OtlpGrpcClientReferenceGuard> client_reference_guard_;

// Aggregation Temporality selector
const sdk::metrics::AggregationTemporalitySelector aggregation_temporality_selector_;
Expand All @@ -94,7 +94,7 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp
friend class OtlpGrpcMetricExporterTestPeer;

// Store service stub internally. Useful for testing.
nostd::shared_ptr<proto::collector::metrics::v1::MetricsService::StubInterface>
std::shared_ptr<proto::collector::metrics::v1::MetricsService::StubInterface>
metrics_service_stub_;

/**
Expand All @@ -113,7 +113,7 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp
*/
OtlpGrpcMetricExporter(
std::unique_ptr<proto::collector::metrics::v1::MetricsService::StubInterface> stub,
nostd::shared_ptr<OtlpGrpcClient> client);
const std::shared_ptr<OtlpGrpcClient> &client);

std::atomic<bool> is_shutdown_{false};
bool isShutdown() const noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OPENTELEMETRY_EXPORT OtlpGrpcMetricExporterFactory
*/
static std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter> Create(
const OtlpGrpcMetricExporterOptions &options,
nostd::shared_ptr<OtlpGrpcClient> client);
const std::shared_ptr<OtlpGrpcClient> &client);
};

} // namespace otlp
Expand Down
9 changes: 4 additions & 5 deletions exporters/otlp/src/otlp_grpc_client_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ namespace exporter
namespace otlp
{

nostd::shared_ptr<OtlpGrpcClient> OtlpGrpcClientFactory::Create(
const OtlpGrpcClientOptions &options)
std::shared_ptr<OtlpGrpcClient> OtlpGrpcClientFactory::Create(const OtlpGrpcClientOptions &options)
{
return nostd::shared_ptr<OtlpGrpcClient>(new OtlpGrpcClient(options));
return std::make_shared<OtlpGrpcClient>(options);
}

nostd::shared_ptr<OtlpGrpcClientReferenceGuard> OtlpGrpcClientFactory::CreateReferenceGuard()
std::shared_ptr<OtlpGrpcClientReferenceGuard> OtlpGrpcClientFactory::CreateReferenceGuard()
{
return nostd::shared_ptr<OtlpGrpcClientReferenceGuard>(new OtlpGrpcClientReferenceGuard());
return std::make_shared<OtlpGrpcClientReferenceGuard>();
}

} // namespace otlp
Expand Down
16 changes: 8 additions & 8 deletions exporters/otlp/src/otlp_grpc_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ OtlpGrpcExporter::OtlpGrpcExporter(
}

OtlpGrpcExporter::OtlpGrpcExporter(const OtlpGrpcExporterOptions &options,
nostd::shared_ptr<OtlpGrpcClient> client)
const std::shared_ptr<OtlpGrpcClient> &client)
: options_(options),
client_(std::move(client)),
client_(client),
client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard())
{
client_->AddReference(*client_reference_guard_, options_);
Expand All @@ -55,9 +55,9 @@ OtlpGrpcExporter::OtlpGrpcExporter(const OtlpGrpcExporterOptions &options,

OtlpGrpcExporter::OtlpGrpcExporter(
std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface> stub,
nostd::shared_ptr<OtlpGrpcClient> client)
const std::shared_ptr<OtlpGrpcClient> &client)
: options_(OtlpGrpcExporterOptions()),
client_(std::move(client)),
client_(client),
client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()),
trace_service_stub_(std::move(stub))
{
Expand All @@ -82,7 +82,7 @@ std::unique_ptr<sdk::trace::Recordable> OtlpGrpcExporter::MakeRecordable() noexc
sdk::common::ExportResult OtlpGrpcExporter::Export(
const nostd::span<std::unique_ptr<sdk::trace::Recordable>> &spans) noexcept
{
nostd::shared_ptr<OtlpGrpcClient> client = client_;
std::shared_ptr<OtlpGrpcClient> client = client_;
if (isShutdown() || !client)
{
OTEL_INTERNAL_LOG_ERROR("[OTLP gRPC] Exporting " << spans.size()
Expand Down Expand Up @@ -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<OtlpGrpcClient> client = client_;
std::shared_ptr<OtlpGrpcClient> client = client_;
if (!client)
{
return true;
Expand All @@ -183,7 +183,7 @@ bool OtlpGrpcExporter::Shutdown(
{
is_shutdown_ = true;
// Maybe already shutdown, we need to keep thread-safety here.
nostd::shared_ptr<OtlpGrpcClient> client;
std::shared_ptr<OtlpGrpcClient> client;
client.swap(client_);
if (!client)
{
Expand All @@ -197,7 +197,7 @@ bool OtlpGrpcExporter::isShutdown() const noexcept
return is_shutdown_;
}

const nostd::shared_ptr<OtlpGrpcClient> &OtlpGrpcExporter::GetClient() const noexcept
const std::shared_ptr<OtlpGrpcClient> &OtlpGrpcExporter::GetClient() const noexcept
{
return client_;
}
Expand Down
4 changes: 2 additions & 2 deletions exporters/otlp/src/otlp_grpc_exporter_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> OtlpGrpcExporterFactory

std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> OtlpGrpcExporterFactory::Create(
const OtlpGrpcExporterOptions &options,
nostd::shared_ptr<OtlpGrpcClient> client)
const std::shared_ptr<OtlpGrpcClient> &client)
{
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> exporter(
new OtlpGrpcExporter(options, std::move(client)));
new OtlpGrpcExporter(options, client));
return exporter;
}

Expand Down
Loading

0 comments on commit 4367e62

Please sign in to comment.