Skip to content

Commit

Permalink
Restore nostd::unique_ptr to std::unique_ptr in sdk and exporters.
Browse files Browse the repository at this point in the history
Signed-off-by: WenTao Ou <[email protected]>
  • Loading branch information
owent committed Dec 2, 2022
1 parent d7f7a79 commit 043030a
Show file tree
Hide file tree
Showing 52 changed files with 228 additions and 212 deletions.
8 changes: 8 additions & 0 deletions api/include/opentelemetry/nostd/shared_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ class shared_ptr
new (buffer_.data) shared_ptr_wrapper{std::move(ptr_)};
}

# ifndef HAVE_CPP_STDLIB
shared_ptr(std::unique_ptr<T> &&other) noexcept
{
std::shared_ptr<T> ptr_(other.release());
new (buffer_.data) shared_ptr_wrapper{std::move(ptr_)};
}
# endif

~shared_ptr() { wrapper().~shared_ptr_wrapper(); }

shared_ptr &operator=(shared_ptr &&other) noexcept
Expand Down
2 changes: 1 addition & 1 deletion examples/otlp/http_log_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void InitLogger()
// Create OTLP exporter instance
auto exporter = otlp::OtlpHttpLogRecordExporterFactory::Create(logger_opts);
auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter));
nostd::shared_ptr<logs::LoggerProvider> provider =
std::shared_ptr<logs::LoggerProvider> provider =
logs_sdk::LoggerProviderFactory::Create(std::move(processor));

opentelemetry::logs::Provider::SetLoggerProvider(provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ class ElasticsearchLogRecordExporter final : public opentelemetry::sdk::logs::Lo
* Creates a recordable that stores the data in a JSON object
* @return a newly initialized Recordable object.
*/
nostd::unique_ptr<opentelemetry::sdk::logs::Recordable> MakeRecordable() noexcept override;
std::unique_ptr<opentelemetry::sdk::logs::Recordable> MakeRecordable() noexcept override;

/**
* Exports a vector of log records to the Elasticsearch instance. Guaranteed to return after a
* timeout specified from the options passed from the constructor.
* @param records A list of log records to send to Elasticsearch.
*/
sdk::common::ExportResult Export(
const opentelemetry::nostd::span<nostd::unique_ptr<opentelemetry::sdk::logs::Recordable>>
const opentelemetry::nostd::span<std::unique_ptr<opentelemetry::sdk::logs::Recordable>>
&records) noexcept override;

/**
Expand Down
8 changes: 4 additions & 4 deletions exporters/elasticsearch/src/es_log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter(
: options_{options}, http_client_{ext::http::client::HttpClientFactory::Create()}
{}

nostd::unique_ptr<sdklogs::Recordable> ElasticsearchLogRecordExporter::MakeRecordable() noexcept
std::unique_ptr<sdklogs::Recordable> ElasticsearchLogRecordExporter::MakeRecordable() noexcept
{
return nostd::unique_ptr<sdklogs::Recordable>(new ElasticSearchRecordable());
return std::unique_ptr<sdklogs::Recordable>(new ElasticSearchRecordable());
}

sdk::common::ExportResult ElasticsearchLogRecordExporter::Export(
const nostd::span<nostd::unique_ptr<sdklogs::Recordable>> &records) noexcept
const nostd::span<std::unique_ptr<sdklogs::Recordable>> &records) noexcept
{
// Return failure if this exporter has been shutdown
if (isShutdown())
Expand Down Expand Up @@ -334,7 +334,7 @@ sdk::common::ExportResult ElasticsearchLogRecordExporter::Export(
body += "{\"index\" : {}}\n";

// Add the context of the Recordable
auto json_record = nostd::unique_ptr<ElasticSearchRecordable>(
auto json_record = std::unique_ptr<ElasticSearchRecordable>(
static_cast<ElasticSearchRecordable *>(record.release()));
body += json_record->GetJSON().dump() + "\n";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class OStreamLogRecordExporter final : public opentelemetry::sdk::logs::LogRecor
*/
explicit OStreamLogRecordExporter(std::ostream &sout = std::cout) noexcept;

nostd::unique_ptr<sdk::logs::Recordable> MakeRecordable() noexcept override;
std::unique_ptr<sdk::logs::Recordable> MakeRecordable() noexcept override;

/**
* Exports a span of logs sent from the processor.
*/
opentelemetry::sdk::common::ExportResult Export(
const opentelemetry::nostd::span<nostd::unique_ptr<sdk::logs::Recordable>> &records) noexcept
const opentelemetry::nostd::span<std::unique_ptr<sdk::logs::Recordable>> &records) noexcept
override;

/**
Expand Down
8 changes: 4 additions & 4 deletions exporters/ostream/src/log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ OStreamLogRecordExporter::OStreamLogRecordExporter(std::ostream &sout) noexcept

/*********************** Exporter methods ***********************/

nostd::unique_ptr<sdklogs::Recordable> OStreamLogRecordExporter::MakeRecordable() noexcept
std::unique_ptr<sdklogs::Recordable> OStreamLogRecordExporter::MakeRecordable() noexcept
{
return nostd::unique_ptr<sdklogs::Recordable>(new sdklogs::ReadWriteLogRecord());
return std::unique_ptr<sdklogs::Recordable>(new sdklogs::ReadWriteLogRecord());
}

sdk::common::ExportResult OStreamLogRecordExporter::Export(
const nostd::span<nostd::unique_ptr<sdklogs::Recordable>> &records) noexcept
const nostd::span<std::unique_ptr<sdklogs::Recordable>> &records) noexcept
{
if (isShutdown())
{
Expand All @@ -43,7 +43,7 @@ sdk::common::ExportResult OStreamLogRecordExporter::Export(

for (auto &record : records)
{
auto log_record = nostd::unique_ptr<sdklogs::ReadWriteLogRecord>(
auto log_record = std::unique_ptr<sdklogs::ReadWriteLogRecord>(
static_cast<sdklogs::ReadWriteLogRecord *>(record.release()));

if (log_record == nullptr)
Expand Down
12 changes: 6 additions & 6 deletions exporters/ostream/test/ostream_log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TEST(OStreamLogRecordExporter, Shutdown)
// After processor/exporter is shutdown, no logs should be sent to stream
auto record = exporter->MakeRecordable();
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetBody("Log record not empty");
exporter->Export(nostd::span<nostd::unique_ptr<sdklogs::Recordable>>(&record, 1));
exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

// Restore original stringstream buffer
std::cout.rdbuf(original);
Expand All @@ -71,7 +71,7 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout)

// Pass a default recordable created by the exporter to be exported
auto log_record = exporter->MakeRecordable();
exporter->Export(nostd::span<nostd::unique_ptr<sdklogs::Recordable>>(&log_record, 1));
exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&log_record, 1));

// Restore cout's original stringstream
std::cout.rdbuf(original);
Expand Down Expand Up @@ -115,15 +115,15 @@ TEST(OStreamLogRecordExporter, SimpleLogToCout)
// Create a log record and manually timestamp, severity, name, message
common::SystemTimestamp now(std::chrono::system_clock::now());

auto record = nostd::unique_ptr<sdklogs::Recordable>(new sdklogs::ReadWriteLogRecord());
auto record = std::unique_ptr<sdklogs::Recordable>(new sdklogs::ReadWriteLogRecord());
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetTimestamp(now);
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetObservedTimestamp(now);
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())
->SetSeverity(logs_api::Severity::kTrace); // kTrace has enum value of 1
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetBody("Message");

// Log a record to cout
exporter->Export(nostd::span<nostd::unique_ptr<sdklogs::Recordable>>(&record, 1));
exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

// Reset cout's original stringstream buffer
std::cout.rdbuf(original);
Expand Down Expand Up @@ -181,7 +181,7 @@ TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr)
static_cast<sdklogs::ReadWriteLogRecord *>(record.get())->SetAttribute("a", true);

// Log record to cerr
exporter->Export(nostd::span<nostd::unique_ptr<sdklogs::Recordable>>(&record, 1));
exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

// Reset cerr's original stringstream buffer
std::cerr.rdbuf(original);
Expand Down Expand Up @@ -244,7 +244,7 @@ TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog)
->SetAttribute("attr1", nostd::span<bool>{array.data(), array.size()});

// Log a record to clog
exporter->Export(nostd::span<nostd::unique_ptr<sdklogs::Recordable>>(&record, 1));
exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

// Reset clog's original stringstream buffer
std::clog.rdbuf(original);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo
* Creates a recordable that stores the data in protobuf.
* @return a newly initialized Recordable object.
*/
nostd::unique_ptr<opentelemetry::sdk::logs::Recordable> MakeRecordable() noexcept override;
std::unique_ptr<opentelemetry::sdk::logs::Recordable> MakeRecordable() noexcept override;

/**
* Exports a vector of log records to the configured gRPC endpoint. Guaranteed to return after a
* timeout specified from the options passed to the constructor.
* @param records A list of log records.
*/
opentelemetry::sdk::common::ExportResult Export(
const nostd::span<nostd::unique_ptr<opentelemetry::sdk::logs::Recordable>> &records) noexcept
const nostd::span<std::unique_ptr<opentelemetry::sdk::logs::Recordable>> &records) noexcept
override;

/**
Expand All @@ -70,15 +70,15 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo
friend class OtlpGrpcLogRecordExporterTestPeer;

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

/**
* Create an OtlpGrpcLogRecordExporter using the specified service stub.
* Only tests can call this constructor directly.
* @param stub the service stub to be used for exporting
*/
OtlpGrpcLogRecordExporter(
nostd::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface> stub);
std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface> stub);
bool is_shutdown_ = false;
mutable opentelemetry::common::SpinLockMutex lock_;
bool isShutdown() const noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class OtlpGrpcLogRecordExporterFactory
/**
* Create a OtlpGrpcLogRecordExporter.
*/
static nostd::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create();
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create();

/**
* Create a OtlpGrpcLogRecordExporter.
*/
static nostd::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(
const OtlpGrpcExporterOptions &options);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class OtlpHttpLogRecordExporter final : public opentelemetry::sdk::logs::LogReco
/**
* Creates a recordable that stores the data in a JSON object
*/
nostd::unique_ptr<opentelemetry::sdk::logs::Recordable> MakeRecordable() noexcept override;
std::unique_ptr<opentelemetry::sdk::logs::Recordable> MakeRecordable() noexcept override;

/**
* Exports a vector of log records to the Elasticsearch instance. Guaranteed to return after a
* timeout specified from the options passed from the constructor.
* @param records A list of log records to send to Elasticsearch.
*/
opentelemetry::sdk::common::ExportResult Export(
const nostd::span<nostd::unique_ptr<opentelemetry::sdk::logs::Recordable>> &records) noexcept
const nostd::span<std::unique_ptr<opentelemetry::sdk::logs::Recordable>> &records) noexcept
override;

/**
Expand All @@ -65,15 +65,15 @@ class OtlpHttpLogRecordExporter final : public opentelemetry::sdk::logs::LogReco
const OtlpHttpLogRecordExporterOptions options_;

// Object that stores the HTTP sessions that have been created
nostd::unique_ptr<OtlpHttpClient> http_client_;
std::unique_ptr<OtlpHttpClient> http_client_;
// For testing
friend class OtlpHttpLogRecordExporterTestPeer;
/**
* Create an OtlpHttpLogRecordExporter using the specified http client.
* Only tests can call this constructor directly.
* @param http_client the http client to be used for exporting
*/
OtlpHttpLogRecordExporter(nostd::unique_ptr<OtlpHttpClient> http_client);
OtlpHttpLogRecordExporter(std::unique_ptr<OtlpHttpClient> http_client);
};
} // namespace otlp
} // namespace exporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class OtlpHttpLogRecordExporterFactory
/**
* Create a OtlpHttpLogRecordExporter.
*/
static nostd::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create();
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create();

/**
* Create a OtlpHttpLogRecordExporter.
*/
static nostd::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(
const OtlpHttpLogRecordExporterOptions &options);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class OtlpRecordableUtils

#ifdef ENABLE_LOGS_PREVIEW
static void PopulateRequest(
const nostd::span<nostd::unique_ptr<opentelemetry::sdk::logs::Recordable>> &logs,
const nostd::span<std::unique_ptr<opentelemetry::sdk::logs::Recordable>> &logs,
proto::collector::logs::v1::ExportLogsServiceRequest *request) noexcept;
#endif
};
Expand Down
8 changes: 4 additions & 4 deletions exporters/otlp/src/otlp_grpc_log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter(const OtlpGrpcExporterOptio
{}

OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter(
nostd::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface> stub)
std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface> stub)
: options_(OtlpGrpcExporterOptions()), log_service_stub_(std::move(stub))
{}

// ----------------------------- Exporter methods ------------------------------

nostd::unique_ptr<opentelemetry::sdk::logs::Recordable>
std::unique_ptr<opentelemetry::sdk::logs::Recordable>
OtlpGrpcLogRecordExporter::MakeRecordable() noexcept
{
return nostd::unique_ptr<opentelemetry::sdk::logs::Recordable>(new OtlpLogRecordable());
return std::unique_ptr<opentelemetry::sdk::logs::Recordable>(new OtlpLogRecordable());
}

opentelemetry::sdk::common::ExportResult OtlpGrpcLogRecordExporter::Export(
const nostd::span<nostd::unique_ptr<opentelemetry::sdk::logs::Recordable>> &logs) noexcept
const nostd::span<std::unique_ptr<opentelemetry::sdk::logs::Recordable>> &logs) noexcept
{
if (isShutdown())
{
Expand Down
6 changes: 3 additions & 3 deletions exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ namespace exporter
namespace otlp
{

nostd::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
OtlpGrpcLogRecordExporterFactory::Create()
{
OtlpGrpcExporterOptions options;
return Create(options);
}

nostd::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
OtlpGrpcLogRecordExporterFactory::Create(const OtlpGrpcExporterOptions &options)
{
nostd::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> exporter(
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> exporter(
new OtlpGrpcLogRecordExporter(options));
return exporter;
}
Expand Down
8 changes: 4 additions & 4 deletions exporters/otlp/src/otlp_http_log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(
)))
{}

OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(nostd::unique_ptr<OtlpHttpClient> http_client)
OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(std::unique_ptr<OtlpHttpClient> http_client)
: options_(OtlpHttpLogRecordExporterOptions()), http_client_(std::move(http_client))
{
OtlpHttpLogRecordExporterOptions &options =
Expand All @@ -64,14 +64,14 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(nostd::unique_ptr<OtlpHttpC
}
// ----------------------------- Exporter methods ------------------------------

nostd::unique_ptr<opentelemetry::sdk::logs::Recordable>
std::unique_ptr<opentelemetry::sdk::logs::Recordable>
OtlpHttpLogRecordExporter::MakeRecordable() noexcept
{
return nostd::unique_ptr<opentelemetry::sdk::logs::Recordable>(new OtlpLogRecordable());
return std::unique_ptr<opentelemetry::sdk::logs::Recordable>(new OtlpLogRecordable());
}

opentelemetry::sdk::common::ExportResult OtlpHttpLogRecordExporter::Export(
const nostd::span<nostd::unique_ptr<opentelemetry::sdk::logs::Recordable>> &logs) noexcept
const nostd::span<std::unique_ptr<opentelemetry::sdk::logs::Recordable>> &logs) noexcept
{
if (http_client_->IsShutdown())
{
Expand Down
6 changes: 3 additions & 3 deletions exporters/otlp/src/otlp_http_log_record_exporter_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ namespace exporter
namespace otlp
{

nostd::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
OtlpHttpLogRecordExporterFactory::Create()
{
OtlpHttpLogRecordExporterOptions options;
return Create(options);
}

nostd::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
OtlpHttpLogRecordExporterFactory::Create(const OtlpHttpLogRecordExporterOptions &options)
{
nostd::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> exporter(
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> exporter(
new OtlpHttpLogRecordExporter(options));
return exporter;
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/src/otlp_recordable_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void OtlpRecordableUtils::PopulateRequest(

#ifdef ENABLE_LOGS_PREVIEW
void OtlpRecordableUtils::PopulateRequest(
const nostd::span<nostd::unique_ptr<opentelemetry::sdk::logs::Recordable>> &logs,
const nostd::span<std::unique_ptr<opentelemetry::sdk::logs::Recordable>> &logs,
proto::collector::logs::v1::ExportLogsServiceRequest *request) noexcept
{
if (nullptr == request)
Expand Down
Loading

0 comments on commit 043030a

Please sign in to comment.