Skip to content

Commit

Permalink
[Logs SDK] LogProcessor, LogExporter class name (#1736)
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo authored Nov 6, 2022
1 parent ec8895b commit 7efeeab
Show file tree
Hide file tree
Showing 40 changed files with 260 additions and 240 deletions.
4 changes: 2 additions & 2 deletions examples/otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ calls a `foo_library` which has been instrumented using the [OpenTelemetry
API](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/api).

### Logs
The application in `http_log_main.cc` initializes an `OtlpHttpLogExporter` instance,
the application in `grpc_log_main.cc` initializes an `OtlpGrpcLogExporter` instance.
The application in `http_log_main.cc` initializes an `OtlpHttpLogRecordExporter` instance,
the application in `grpc_log_main.cc` initializes an `OtlpGrpcLogRecordExporter` instance.
And they register a logger provider from the [OpenTelemetry
SDK](https://github.com/open-telemetry/opentelemetry-cpp). The application then
calls a `logs_foo_library` which has been instrumented using the [OpenTelemetry
Expand Down
4 changes: 2 additions & 2 deletions examples/otlp/grpc_log_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void InitTracer()
void InitLogger()
{
// Create OTLP exporter instance
auto exporter = otlp::OtlpGrpcLogExporterFactory::Create(opts);
auto processor = logs_sdk::SimpleLogProcessorFactory::Create(std::move(exporter));
auto exporter = otlp::OtlpGrpcLogRecordExporterFactory::Create(opts);
auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter));
nostd::shared_ptr<logs::LoggerProvider> provider(
logs_sdk::LoggerProviderFactory::Create(std::move(processor)));

Expand Down
6 changes: 3 additions & 3 deletions examples/otlp/http_log_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ void InitTracer()
trace::Provider::SetTracerProvider(provider);
}

opentelemetry::exporter::otlp::OtlpHttpLogExporterOptions logger_opts;
opentelemetry::exporter::otlp::OtlpHttpLogRecordExporterOptions logger_opts;
void InitLogger()
{
logger_opts.console_debug = true;
// Create OTLP exporter instance
auto exporter = otlp::OtlpHttpLogExporterFactory::Create(logger_opts);
auto processor = logs_sdk::SimpleLogProcessorFactory::Create(std::move(exporter));
auto exporter = otlp::OtlpHttpLogRecordExporterFactory::Create(logger_opts);
auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter));
std::shared_ptr<logs::LoggerProvider> provider =
logs_sdk::LoggerProviderFactory::Create(std::move(processor));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ struct ElasticsearchExporterOptions
};

/**
* The ElasticsearchLogExporter exports logs to Elasticsearch in JSON format
* The ElasticsearchLogRecordExporter exports logs to Elasticsearch in JSON format
*/
class ElasticsearchLogExporter final : public opentelemetry::sdk::logs::LogRecordExporter
class ElasticsearchLogRecordExporter final : public opentelemetry::sdk::logs::LogRecordExporter
{
public:
/**
* Create an ElasticsearchLogExporter with default exporter options.
* Create an ElasticsearchLogRecordExporter with default exporter options.
*/
ElasticsearchLogExporter();
ElasticsearchLogRecordExporter();

/**
* Create an ElasticsearchLogExporter with user specified options.
* Create an ElasticsearchLogRecordExporter with user specified options.
* @param options An object containing the user's configuration options.
*/
ElasticsearchLogExporter(const ElasticsearchExporterOptions &options);
ElasticsearchLogRecordExporter(const ElasticsearchExporterOptions &options);

/**
* Creates a recordable that stores the data in a JSON object
Expand Down
13 changes: 7 additions & 6 deletions exporters/elasticsearch/src/es_log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,21 +289,22 @@ class AsyncResponseHandler : public http_client::EventHandler
};
# endif

ElasticsearchLogExporter::ElasticsearchLogExporter()
ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter()
: options_{ElasticsearchExporterOptions()},
http_client_{ext::http::client::HttpClientFactory::Create()}
{}

ElasticsearchLogExporter::ElasticsearchLogExporter(const ElasticsearchExporterOptions &options)
ElasticsearchLogRecordExporter::ElasticsearchLogRecordExporter(
const ElasticsearchExporterOptions &options)
: options_{options}, http_client_{ext::http::client::HttpClientFactory::Create()}
{}

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

sdk::common::ExportResult ElasticsearchLogExporter::Export(
sdk::common::ExportResult ElasticsearchLogRecordExporter::Export(
const nostd::span<std::unique_ptr<sdklogs::Recordable>> &records) noexcept
{
// Return failure if this exporter has been shutdown
Expand Down Expand Up @@ -400,7 +401,7 @@ sdk::common::ExportResult ElasticsearchLogExporter::Export(
# endif
}

bool ElasticsearchLogExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept
bool ElasticsearchLogRecordExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
is_shutdown_ = true;
Expand All @@ -412,7 +413,7 @@ bool ElasticsearchLogExporter::Shutdown(std::chrono::microseconds /* timeout */)
return true;
}

bool ElasticsearchLogExporter::isShutdown() const noexcept
bool ElasticsearchLogRecordExporter::isShutdown() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return is_shutdown_;
Expand Down
6 changes: 3 additions & 3 deletions exporters/elasticsearch/test/es_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST(ElasticsearchLogsExporterTests, InvalidEndpoint)

// Create an elasticsearch exporter
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogExporter(options));
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogRecordExporter(options));

// Create a log record and send to the exporter
auto record = exporter->MakeRecordable();
Expand All @@ -48,7 +48,7 @@ TEST(ElasticsearchLogsExporterTests, Shutdown)
{
// Create an elasticsearch exporter and immediately shut it down
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogExporter);
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogRecordExporter);
bool shutdownResult = exporter->Shutdown();
ASSERT_TRUE(shutdownResult);

Expand All @@ -65,7 +65,7 @@ TEST(ElasticsearchLogsExporterTests, RecordableCreation)
{
// Create an elasticsearch exporter
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogExporter);
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogRecordExporter);

// Create a recordable
auto record = exporter->MakeRecordable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ namespace exporter
namespace logs
{
/**
* The OStreamLogExporter exports logs through an ostream (default set to std::cout)
* The OStreamLogRecordExporter exports logs through an ostream (default set to std::cout)
*/
class OStreamLogExporter final : public opentelemetry::sdk::logs::LogRecordExporter
class OStreamLogRecordExporter final : public opentelemetry::sdk::logs::LogRecordExporter
{
public:
/**
* Create an OStreamLogExporter. This constructor takes in a reference to an ostream that the
* Export() method will send log data into. The default ostream is set to stdout.
* Create an OStreamLogRecordExporter. This constructor takes in a reference to an ostream that
* the Export() method will send log data into. The default ostream is set to stdout.
*/
explicit OStreamLogExporter(std::ostream &sout = std::cout) noexcept;
explicit OStreamLogRecordExporter(std::ostream &sout = std::cout) noexcept;

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

Expand Down
12 changes: 6 additions & 6 deletions exporters/ostream/src/log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ namespace logs

/*********************** Constructor ***********************/

OStreamLogExporter::OStreamLogExporter(std::ostream &sout) noexcept : sout_(sout) {}
OStreamLogRecordExporter::OStreamLogRecordExporter(std::ostream &sout) noexcept : sout_(sout) {}

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

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

sdk::common::ExportResult OStreamLogExporter::Export(
sdk::common::ExportResult OStreamLogRecordExporter::Export(
const nostd::span<std::unique_ptr<sdklogs::Recordable>> &records) noexcept
{
if (isShutdown())
Expand Down Expand Up @@ -102,20 +102,20 @@ sdk::common::ExportResult OStreamLogExporter::Export(
return sdk::common::ExportResult::kSuccess;
}

bool OStreamLogExporter::Shutdown(std::chrono::microseconds) noexcept
bool OStreamLogRecordExporter::Shutdown(std::chrono::microseconds) noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
is_shutdown_ = true;
return true;
}

bool OStreamLogExporter::isShutdown() const noexcept
bool OStreamLogRecordExporter::isShutdown() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return is_shutdown_;
}

void OStreamLogExporter::printAttributes(
void OStreamLogRecordExporter::printAttributes(
const std::unordered_map<std::string, sdkcommon::OwnedAttributeValue> &map,
const std::string prefix)
{
Expand Down
34 changes: 18 additions & 16 deletions exporters/ostream/test/ostream_log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ namespace logs
{

// Test that when OStream Log exporter is shutdown, no logs should be sent to stream
TEST(OStreamLogExporter, Shutdown)
TEST(OStreamLogRecordExporter, Shutdown)
{
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogExporter);
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogRecordExporter);

// Save cout's original buffer here
std::streambuf *original = std::cout.rdbuf();
Expand Down Expand Up @@ -57,8 +58,8 @@ TEST(OStreamLogExporter, Shutdown)
// This function tests MakeRecordable() as well as Export().
TEST(OstreamLogExporter, DefaultLogRecordToCout)
{
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogExporter(std::cout));
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
new exporterlogs::OStreamLogRecordExporter(std::cout));

// Save cout's original buffer here
std::streambuf *original = std::cout.rdbuf();
Expand Down Expand Up @@ -98,11 +99,11 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout)

// Testing what a log record with only the "timestamp", "severity", "name" and "message" fields set,
// will print out
TEST(OStreamLogExporter, SimpleLogToCout)
TEST(OStreamLogRecordExporter, SimpleLogToCout)
{
// Initialize an Ostream exporter to std::cout
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogExporter(std::cout));
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
new exporterlogs::OStreamLogRecordExporter(std::cout));

// Save original stream buffer, then redirect cout to our new stream buffer
std::streambuf *original = std::cout.rdbuf();
Expand Down Expand Up @@ -152,11 +153,11 @@ TEST(OStreamLogExporter, SimpleLogToCout)

// Testing what a log record with only the "resource" and "attributes" fields
// (i.e. KeyValueIterable types) set with primitive types, will print out
TEST(OStreamLogExporter, LogWithStringAttributesToCerr)
TEST(OStreamLogRecordExporter, LogWithStringAttributesToCerr)
{
// Initialize an Ostream exporter to cerr
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogExporter(std::cerr));
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
new exporterlogs::OStreamLogRecordExporter(std::cerr));

// Save original stream buffer, then redirect cout to our new stream buffer
std::streambuf *original = std::cerr.rdbuf();
Expand Down Expand Up @@ -208,12 +209,12 @@ TEST(OStreamLogExporter, LogWithStringAttributesToCerr)

// Testing what a log record with only the "resource", and "attributes" fields
// (i.e. KeyValueIterable types), set with 2D arrays as values, will print out
TEST(OStreamLogExporter, LogWithVariantTypesToClog)
TEST(OStreamLogRecordExporter, LogWithVariantTypesToClog)
{

// Initialize an Ostream exporter to cerr
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogExporter(std::clog));
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
new exporterlogs::OStreamLogRecordExporter(std::clog));

// Save original stream buffer, then redirect cout to our new stream buffer
std::streambuf *original = std::clog.rdbuf();
Expand Down Expand Up @@ -270,13 +271,14 @@ TEST(OStreamLogExporter, LogWithVariantTypesToClog)

// Test using the simple log processor and ostream exporter to cout
// and use the rest of the logging pipeline (Logger, LoggerProvider, Provider) as well
TEST(OStreamLogExporter, IntegrationTest)
TEST(OStreamLogRecordExporter, IntegrationTest)
{
// Initialize a logger
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogExporter);
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogRecordExporter);
auto sdkProvider = std::shared_ptr<sdklogs::LoggerProvider>(new sdklogs::LoggerProvider());
sdkProvider->AddProcessor(std::unique_ptr<sdklogs::LogRecordProcessor>(
new sdklogs::SimpleLogProcessor(std::move(exporter))));
new sdklogs::SimpleLogRecordProcessor(std::move(exporter))));
auto apiProvider = nostd::shared_ptr<logs_api::LoggerProvider>(sdkProvider);
auto provider = nostd::shared_ptr<logs_api::LoggerProvider>(apiProvider);
logs_api::Provider::SetLoggerProvider(provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ namespace otlp
/**
* The OTLP exporter exports log data in OpenTelemetry Protocol (OTLP) format in gRPC.
*/
class OtlpGrpcLogExporter : public opentelemetry::sdk::logs::LogRecordExporter
class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExporter
{
public:
/**
* Create an OtlpGrpcLogExporter with default exporter options.
* Create an OtlpGrpcLogRecordExporter with default exporter options.
*/
OtlpGrpcLogExporter();
OtlpGrpcLogRecordExporter();

/**
* Create an OtlpGrpcLogExporter with user specified options.
* Create an OtlpGrpcLogRecordExporter with user specified options.
* @param options An object containing the user's configuration options.
*/
OtlpGrpcLogExporter(const OtlpGrpcExporterOptions &options);
OtlpGrpcLogRecordExporter(const OtlpGrpcExporterOptions &options);

/**
* Creates a recordable that stores the data in protobuf.
Expand Down Expand Up @@ -67,17 +67,18 @@ class OtlpGrpcLogExporter : public opentelemetry::sdk::logs::LogRecordExporter
const OtlpGrpcExporterOptions options_;

// For testing
friend class OtlpGrpcLogExporterTestPeer;
friend class OtlpGrpcLogRecordExporterTestPeer;

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

/**
* Create an OtlpGrpcLogExporter using the specified 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
*/
OtlpGrpcLogExporter(std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface> stub);
OtlpGrpcLogRecordExporter(
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 @@ -15,18 +15,18 @@ namespace otlp
{

/**
* Factory class for OtlpGrpcLogExporter.
* Factory class for OtlpGrpcLogRecordExporter.
*/
class OtlpGrpcLogExporterFactory
class OtlpGrpcLogRecordExporterFactory
{
public:
/**
* Create a OtlpGrpcLogExporter.
* Create a OtlpGrpcLogRecordExporter.
*/
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create();

/**
* Create a OtlpGrpcLogExporter.
* Create a OtlpGrpcLogRecordExporter.
*/
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 @@ -230,7 +230,7 @@ class OtlpHttpClient

// For testing
friend class OtlpHttpExporterTestPeer;
friend class OtlpHttpLogExporterTestPeer;
friend class OtlpHttpLogRecordExporterTestPeer;
friend class OtlpHttpMetricExporterTestPeer;

/**
Expand Down
Loading

2 comments on commit 7efeeab

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 7efeeab Previous: ec8895b Ratio
BM_NaiveSpinLockThrashing/2/process_time/real_time 6.665706634521484 ms/iter 0.6459938204156517 ms/iter 10.32

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 7efeeab Previous: ec8895b Ratio
BM_LockFreeBuffer/2 1788195.8484649658 ns/iter 860638.1416320801 ns/iter 2.08

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.