From 53260cec2a11ffb589af0f09cf66ff946f79ba6c Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 21 Jul 2021 10:08:24 -0700 Subject: [PATCH 1/2] Rename Recordable to JaegerRecordable in Jaeger exporter --- .../exporters/jaeger/recordable.h | 4 +- exporters/jaeger/src/jaeger_exporter.cc | 4 +- exporters/jaeger/src/recordable.cc | 38 +++++++++---------- exporters/jaeger/src/sender.h | 2 +- exporters/jaeger/src/thrift_sender.cc | 2 +- exporters/jaeger/src/thrift_sender.h | 4 +- .../jaeger/test/jaeger_recordable_test.cc | 16 ++++---- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h b/exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h index 7829eef011..d7551bfa07 100644 --- a/exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h +++ b/exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h @@ -49,10 +49,10 @@ inline uint64_t otel_bswap_64(uint64_t host_int) using namespace jaegertracing; -class Recordable final : public sdk::trace::Recordable +class JaegerRecordable final : public sdk::trace::Recordable { public: - Recordable(); + JaegerRecordable(); thrift::Span *Span() noexcept { return span_.release(); } std::vector Tags() noexcept { return std::move(tags_); } diff --git a/exporters/jaeger/src/jaeger_exporter.cc b/exporters/jaeger/src/jaeger_exporter.cc index 7770e5c299..5d9388e14f 100644 --- a/exporters/jaeger/src/jaeger_exporter.cc +++ b/exporters/jaeger/src/jaeger_exporter.cc @@ -25,7 +25,7 @@ JaegerExporter::JaegerExporter() : JaegerExporter(JaegerExporterOptions()) {} std::unique_ptr JaegerExporter::MakeRecordable() noexcept { - return std::unique_ptr(new Recordable); + return std::unique_ptr(new JaegerRecordable); } sdk_common::ExportResult JaegerExporter::Export( @@ -40,7 +40,7 @@ sdk_common::ExportResult JaegerExporter::Export( for (auto &recordable : spans) { - auto rec = std::unique_ptr(static_cast(recordable.release())); + auto rec = std::unique_ptr(static_cast(recordable.release())); if (rec != nullptr) { exported_size += sender_->Append(std::move(rec)); diff --git a/exporters/jaeger/src/recordable.cc b/exporters/jaeger/src/recordable.cc index b932140897..7e286a0617 100644 --- a/exporters/jaeger/src/recordable.cc +++ b/exporters/jaeger/src/recordable.cc @@ -12,9 +12,9 @@ namespace jaeger using namespace opentelemetry::sdk::resource; -Recordable::Recordable() : span_{new thrift::Span} {} +JaegerRecordable::JaegerRecordable() : span_{new thrift::Span} {} -void Recordable::PopulateAttribute(nostd::string_view key, +void JaegerRecordable::PopulateAttribute(nostd::string_view key, const common::AttributeValue &value, std::vector &tags) { @@ -41,7 +41,7 @@ void Recordable::PopulateAttribute(nostd::string_view key, // TODO: extend other AttributeType to the types supported by Jaeger. } -void Recordable::PopulateAttribute(nostd::string_view key, +void JaegerRecordable::PopulateAttribute(nostd::string_view key, const sdk::common::OwnedAttributeValue &value, std::vector &tags) { @@ -64,7 +64,7 @@ void Recordable::PopulateAttribute(nostd::string_view key, // TODO: extend other OwnedAttributeType to the types supported by Jaeger. } -void Recordable::SetIdentity(const trace::SpanContext &span_context, +void JaegerRecordable::SetIdentity(const trace::SpanContext &span_context, trace::SpanId parent_span_id) noexcept { // IDs should be converted to big endian before transmission. @@ -90,12 +90,12 @@ void Recordable::SetIdentity(const trace::SpanContext &span_context, // TODO: set trace_state. } -void Recordable::SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept +void JaegerRecordable::SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept { PopulateAttribute(key, value, tags_); } -void Recordable::AddEvent(nostd::string_view name, +void JaegerRecordable::AddEvent(nostd::string_view name, common::SystemTimestamp timestamp, const common::KeyValueIterable &attributes) noexcept { @@ -113,7 +113,7 @@ void Recordable::AddEvent(nostd::string_view name, logs_.push_back(log); } -void Recordable::SetInstrumentationLibrary( +void JaegerRecordable::SetInstrumentationLibrary( const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &instrumentation_library) noexcept { @@ -121,13 +121,13 @@ void Recordable::SetInstrumentationLibrary( AddTag("otel.library.version", instrumentation_library.GetVersion(), tags_); } -void Recordable::AddLink(const trace::SpanContext &span_context, +void JaegerRecordable::AddLink(const trace::SpanContext &span_context, const common::KeyValueIterable &attributes) noexcept { // TODO: convert link to SpanRefernece } -void Recordable::SetStatus(trace::StatusCode code, nostd::string_view description) noexcept +void JaegerRecordable::SetStatus(trace::StatusCode code, nostd::string_view description) noexcept { if (code == trace::StatusCode::kUnset) { @@ -147,12 +147,12 @@ void Recordable::SetStatus(trace::StatusCode code, nostd::string_view descriptio AddTag("otel.status_description", std::string{description}, tags_); } -void Recordable::SetName(nostd::string_view name) noexcept +void JaegerRecordable::SetName(nostd::string_view name) noexcept { span_->__set_operationName(static_cast(name)); } -void Recordable::SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept +void JaegerRecordable::SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept { for (const auto &attribute_iter : resource.GetAttributes()) { @@ -168,18 +168,18 @@ void Recordable::SetResource(const opentelemetry::sdk::resource::Resource &resou } } -void Recordable::SetStartTime(common::SystemTimestamp start_time) noexcept +void JaegerRecordable::SetStartTime(common::SystemTimestamp start_time) noexcept { span_->__set_startTime( std::chrono::duration_cast(start_time.time_since_epoch()).count()); } -void Recordable::SetDuration(std::chrono::nanoseconds duration) noexcept +void JaegerRecordable::SetDuration(std::chrono::nanoseconds duration) noexcept { span_->__set_duration(std::chrono::duration_cast(duration).count()); } -void Recordable::SetSpanKind(trace::SpanKind span_kind) noexcept +void JaegerRecordable::SetSpanKind(trace::SpanKind span_kind) noexcept { const char *span_kind_str = nullptr; @@ -212,7 +212,7 @@ void Recordable::SetSpanKind(trace::SpanKind span_kind) noexcept } } -void Recordable::AddTag(const std::string &key, +void JaegerRecordable::AddTag(const std::string &key, const std::string &value, std::vector &tags) { @@ -225,12 +225,12 @@ void Recordable::AddTag(const std::string &key, tags.push_back(tag); } -void Recordable::AddTag(const std::string &key, const char *value, std::vector &tags) +void JaegerRecordable::AddTag(const std::string &key, const char *value, std::vector &tags) { AddTag(key, std::string{value}, tags); } -void Recordable::AddTag(const std::string &key, bool value, std::vector &tags) +void JaegerRecordable::AddTag(const std::string &key, bool value, std::vector &tags) { thrift::Tag tag; @@ -241,7 +241,7 @@ void Recordable::AddTag(const std::string &key, bool value, std::vector &tags) +void JaegerRecordable::AddTag(const std::string &key, int64_t value, std::vector &tags) { thrift::Tag tag; @@ -252,7 +252,7 @@ void Recordable::AddTag(const std::string &key, int64_t value, std::vector &tags) +void JaegerRecordable::AddTag(const std::string &key, double value, std::vector &tags) { thrift::Tag tag; diff --git a/exporters/jaeger/src/sender.h b/exporters/jaeger/src/sender.h index 9a42e251c6..6162cf0d1b 100644 --- a/exporters/jaeger/src/sender.h +++ b/exporters/jaeger/src/sender.h @@ -19,7 +19,7 @@ class Sender Sender() = default; virtual ~Sender() = default; - virtual int Append(std::unique_ptr &&span) = 0; + virtual int Append(std::unique_ptr &&span) = 0; virtual int Flush() = 0; diff --git a/exporters/jaeger/src/thrift_sender.cc b/exporters/jaeger/src/thrift_sender.cc index 488f4fc8c1..66feb6c64c 100644 --- a/exporters/jaeger/src/thrift_sender.cc +++ b/exporters/jaeger/src/thrift_sender.cc @@ -18,7 +18,7 @@ ThriftSender::ThriftSender(std::unique_ptr &&transport) thrift_buffer_(new apache::thrift::transport::TMemoryBuffer()) {} -int ThriftSender::Append(std::unique_ptr &&span) noexcept +int ThriftSender::Append(std::unique_ptr &&span) noexcept { if (span == nullptr) { diff --git a/exporters/jaeger/src/thrift_sender.h b/exporters/jaeger/src/thrift_sender.h index 23f0d3d5f3..15b37dc231 100644 --- a/exporters/jaeger/src/thrift_sender.h +++ b/exporters/jaeger/src/thrift_sender.h @@ -32,7 +32,7 @@ class ThriftSender : public Sender ThriftSender(std::unique_ptr &&transport); ~ThriftSender() override { Close(); } - int Append(std::unique_ptr &&span) noexcept override; + int Append(std::unique_ptr &&span) noexcept override; int Flush() override; void Close() override; @@ -57,7 +57,7 @@ class ThriftSender : public Sender } private: - std::vector> spans_; + std::vector> spans_; std::vector span_buffer_; std::unique_ptr transport_; std::unique_ptr protocol_factory_; diff --git a/exporters/jaeger/test/jaeger_recordable_test.cc b/exporters/jaeger/test/jaeger_recordable_test.cc index 693e630fe3..04a114c3f7 100644 --- a/exporters/jaeger/test/jaeger_recordable_test.cc +++ b/exporters/jaeger/test/jaeger_recordable_test.cc @@ -20,7 +20,7 @@ using namespace opentelemetry::sdk::instrumentationlibrary; TEST(JaegerSpanRecordable, SetIdentity) { - opentelemetry::exporter::jaeger::Recordable rec; + opentelemetry::exporter::jaeger::JaegerRecordable rec; int64_t trace_id_val[2] = {0x0000000000000000, 0x1000000000000000}; int64_t span_id_val = 0x2000000000000000; @@ -57,7 +57,7 @@ TEST(JaegerSpanRecordable, SetIdentity) TEST(JaegerSpanRecordable, SetName) { - opentelemetry::exporter::jaeger::Recordable rec; + opentelemetry::exporter::jaeger::JaegerRecordable rec; nostd::string_view name = "Test Span"; rec.SetName(name); @@ -69,7 +69,7 @@ TEST(JaegerSpanRecordable, SetName) TEST(JaegerSpanRecordable, SetStartTime) { - opentelemetry::exporter::jaeger::Recordable rec; + opentelemetry::exporter::jaeger::JaegerRecordable rec; std::chrono::system_clock::time_point start_time = std::chrono::system_clock::now(); opentelemetry::common::SystemTimestamp start_timestamp(start_time); @@ -84,7 +84,7 @@ TEST(JaegerSpanRecordable, SetStartTime) TEST(JaegerSpanRecordable, SetDuration) { - opentelemetry::exporter::jaeger::Recordable rec; + opentelemetry::exporter::jaeger::JaegerRecordable rec; opentelemetry::common::SystemTimestamp start_timestamp; @@ -102,7 +102,7 @@ TEST(JaegerSpanRecordable, SetDuration) TEST(JaegerSpanRecordable, SetStatus) { - opentelemetry::exporter::jaeger::Recordable rec; + opentelemetry::exporter::jaeger::JaegerRecordable rec; const char *error_description = "Error test"; rec.SetStatus(trace::StatusCode::kError, error_description); @@ -125,7 +125,7 @@ TEST(JaegerSpanRecordable, SetStatus) TEST(JaegerSpanRecordable, AddEvent) { - opentelemetry::exporter::jaeger::Recordable rec; + opentelemetry::exporter::jaeger::JaegerRecordable rec; nostd::string_view name = "Test Event"; @@ -159,7 +159,7 @@ TEST(JaegerSpanRecordable, AddEvent) TEST(JaegerSpanRecordable, SetInstrumentationLibrary) { - opentelemetry::exporter::jaeger::Recordable rec; + opentelemetry::exporter::jaeger::JaegerRecordable rec; std::string library_name = "opentelemetry-cpp"; std::string library_version = "0.1.0"; @@ -181,7 +181,7 @@ TEST(JaegerSpanRecordable, SetInstrumentationLibrary) TEST(JaegerSpanRecordable, SetResource) { - opentelemetry::exporter::jaeger::Recordable rec; + opentelemetry::exporter::jaeger::JaegerRecordable rec; const std::string service_name_key = "service.name"; std::string service_name_value = "test-jaeger-service-name"; From 1314b896d3802b7184aa23a01f1605f1ecb9e0e5 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 21 Jul 2021 10:17:18 -0700 Subject: [PATCH 2/2] Format --- exporters/jaeger/src/jaeger_exporter.cc | 3 ++- exporters/jaeger/src/recordable.cc | 27 ++++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/exporters/jaeger/src/jaeger_exporter.cc b/exporters/jaeger/src/jaeger_exporter.cc index 5d9388e14f..5546248c82 100644 --- a/exporters/jaeger/src/jaeger_exporter.cc +++ b/exporters/jaeger/src/jaeger_exporter.cc @@ -40,7 +40,8 @@ sdk_common::ExportResult JaegerExporter::Export( for (auto &recordable : spans) { - auto rec = std::unique_ptr(static_cast(recordable.release())); + auto rec = + std::unique_ptr(static_cast(recordable.release())); if (rec != nullptr) { exported_size += sender_->Append(std::move(rec)); diff --git a/exporters/jaeger/src/recordable.cc b/exporters/jaeger/src/recordable.cc index 7e286a0617..f0e455923d 100644 --- a/exporters/jaeger/src/recordable.cc +++ b/exporters/jaeger/src/recordable.cc @@ -15,8 +15,8 @@ using namespace opentelemetry::sdk::resource; JaegerRecordable::JaegerRecordable() : span_{new thrift::Span} {} void JaegerRecordable::PopulateAttribute(nostd::string_view key, - const common::AttributeValue &value, - std::vector &tags) + const common::AttributeValue &value, + std::vector &tags) { if (nostd::holds_alternative(value)) { @@ -42,8 +42,8 @@ void JaegerRecordable::PopulateAttribute(nostd::string_view key, } void JaegerRecordable::PopulateAttribute(nostd::string_view key, - const sdk::common::OwnedAttributeValue &value, - std::vector &tags) + const sdk::common::OwnedAttributeValue &value, + std::vector &tags) { if (nostd::holds_alternative(value)) { @@ -65,7 +65,7 @@ void JaegerRecordable::PopulateAttribute(nostd::string_view key, } void JaegerRecordable::SetIdentity(const trace::SpanContext &span_context, - trace::SpanId parent_span_id) noexcept + trace::SpanId parent_span_id) noexcept { // IDs should be converted to big endian before transmission. // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#ids @@ -90,14 +90,15 @@ void JaegerRecordable::SetIdentity(const trace::SpanContext &span_context, // TODO: set trace_state. } -void JaegerRecordable::SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept +void JaegerRecordable::SetAttribute(nostd::string_view key, + const common::AttributeValue &value) noexcept { PopulateAttribute(key, value, tags_); } void JaegerRecordable::AddEvent(nostd::string_view name, - common::SystemTimestamp timestamp, - const common::KeyValueIterable &attributes) noexcept + common::SystemTimestamp timestamp, + const common::KeyValueIterable &attributes) noexcept { std::vector tags; PopulateAttribute("event", static_cast(name.data()), tags); @@ -122,7 +123,7 @@ void JaegerRecordable::SetInstrumentationLibrary( } void JaegerRecordable::AddLink(const trace::SpanContext &span_context, - const common::KeyValueIterable &attributes) noexcept + const common::KeyValueIterable &attributes) noexcept { // TODO: convert link to SpanRefernece } @@ -213,8 +214,8 @@ void JaegerRecordable::SetSpanKind(trace::SpanKind span_kind) noexcept } void JaegerRecordable::AddTag(const std::string &key, - const std::string &value, - std::vector &tags) + const std::string &value, + std::vector &tags) { thrift::Tag tag; @@ -225,7 +226,9 @@ void JaegerRecordable::AddTag(const std::string &key, tags.push_back(tag); } -void JaegerRecordable::AddTag(const std::string &key, const char *value, std::vector &tags) +void JaegerRecordable::AddTag(const std::string &key, + const char *value, + std::vector &tags) { AddTag(key, std::string{value}, tags); }