Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Recordable to JaegerRecordable in Jaeger exporter #919

Merged
merged 3 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<thrift::Tag> Tags() noexcept { return std::move(tags_); }
Expand Down
5 changes: 3 additions & 2 deletions exporters/jaeger/src/jaeger_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ JaegerExporter::JaegerExporter() : JaegerExporter(JaegerExporterOptions()) {}

std::unique_ptr<trace_sdk::Recordable> JaegerExporter::MakeRecordable() noexcept
{
return std::unique_ptr<sdk::trace::Recordable>(new Recordable);
return std::unique_ptr<sdk::trace::Recordable>(new JaegerRecordable);
}

sdk_common::ExportResult JaegerExporter::Export(
Expand All @@ -40,7 +40,8 @@ sdk_common::ExportResult JaegerExporter::Export(

for (auto &recordable : spans)
{
auto rec = std::unique_ptr<Recordable>(static_cast<Recordable *>(recordable.release()));
auto rec =
std::unique_ptr<JaegerRecordable>(static_cast<JaegerRecordable *>(recordable.release()));
if (rec != nullptr)
{
exported_size += sender_->Append(std::move(rec));
Expand Down
61 changes: 32 additions & 29 deletions exporters/jaeger/src/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ 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,
const common::AttributeValue &value,
std::vector<thrift::Tag> &tags)
void JaegerRecordable::PopulateAttribute(nostd::string_view key,
const common::AttributeValue &value,
std::vector<thrift::Tag> &tags)
{
if (nostd::holds_alternative<int64_t>(value))
{
Expand All @@ -41,9 +41,9 @@ void Recordable::PopulateAttribute(nostd::string_view key,
// TODO: extend other AttributeType to the types supported by Jaeger.
}

void Recordable::PopulateAttribute(nostd::string_view key,
const sdk::common::OwnedAttributeValue &value,
std::vector<thrift::Tag> &tags)
void JaegerRecordable::PopulateAttribute(nostd::string_view key,
const sdk::common::OwnedAttributeValue &value,
std::vector<thrift::Tag> &tags)
{
if (nostd::holds_alternative<int64_t>(value))
{
Expand All @@ -64,8 +64,8 @@ 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,
trace::SpanId parent_span_id) noexcept
void JaegerRecordable::SetIdentity(const trace::SpanContext &span_context,
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
Expand All @@ -90,14 +90,15 @@ 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,
common::SystemTimestamp timestamp,
const common::KeyValueIterable &attributes) noexcept
void JaegerRecordable::AddEvent(nostd::string_view name,
common::SystemTimestamp timestamp,
const common::KeyValueIterable &attributes) noexcept
{
std::vector<thrift::Tag> tags;
PopulateAttribute("event", static_cast<common::AttributeValue>(name.data()), tags);
Expand All @@ -113,21 +114,21 @@ 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
{
AddTag("otel.library.name", instrumentation_library.GetName(), tags_);
AddTag("otel.library.version", instrumentation_library.GetVersion(), tags_);
}

void Recordable::AddLink(const trace::SpanContext &span_context,
const common::KeyValueIterable &attributes) noexcept
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)
{
Expand All @@ -147,12 +148,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<std::string>(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())
{
Expand All @@ -168,18 +169,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<std::chrono::microseconds>(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<std::chrono::microseconds>(duration).count());
}

void Recordable::SetSpanKind(trace::SpanKind span_kind) noexcept
void JaegerRecordable::SetSpanKind(trace::SpanKind span_kind) noexcept
{
const char *span_kind_str = nullptr;

Expand Down Expand Up @@ -212,9 +213,9 @@ void Recordable::SetSpanKind(trace::SpanKind span_kind) noexcept
}
}

void Recordable::AddTag(const std::string &key,
const std::string &value,
std::vector<thrift::Tag> &tags)
void JaegerRecordable::AddTag(const std::string &key,
const std::string &value,
std::vector<thrift::Tag> &tags)
{
thrift::Tag tag;

Expand All @@ -225,12 +226,14 @@ void Recordable::AddTag(const std::string &key,
tags.push_back(tag);
}

void Recordable::AddTag(const std::string &key, const char *value, std::vector<thrift::Tag> &tags)
void JaegerRecordable::AddTag(const std::string &key,
const char *value,
std::vector<thrift::Tag> &tags)
{
AddTag(key, std::string{value}, tags);
}

void Recordable::AddTag(const std::string &key, bool value, std::vector<thrift::Tag> &tags)
void JaegerRecordable::AddTag(const std::string &key, bool value, std::vector<thrift::Tag> &tags)
{
thrift::Tag tag;

Expand All @@ -241,7 +244,7 @@ void Recordable::AddTag(const std::string &key, bool value, std::vector<thrift::
tags.push_back(tag);
}

void Recordable::AddTag(const std::string &key, int64_t value, std::vector<thrift::Tag> &tags)
void JaegerRecordable::AddTag(const std::string &key, int64_t value, std::vector<thrift::Tag> &tags)
{
thrift::Tag tag;

Expand All @@ -252,7 +255,7 @@ void Recordable::AddTag(const std::string &key, int64_t value, std::vector<thrif
tags.push_back(tag);
}

void Recordable::AddTag(const std::string &key, double value, std::vector<thrift::Tag> &tags)
void JaegerRecordable::AddTag(const std::string &key, double value, std::vector<thrift::Tag> &tags)
{
thrift::Tag tag;

Expand Down
2 changes: 1 addition & 1 deletion exporters/jaeger/src/sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Sender
Sender() = default;
virtual ~Sender() = default;

virtual int Append(std::unique_ptr<Recordable> &&span) = 0;
virtual int Append(std::unique_ptr<JaegerRecordable> &&span) = 0;

virtual int Flush() = 0;

Expand Down
2 changes: 1 addition & 1 deletion exporters/jaeger/src/thrift_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ThriftSender::ThriftSender(std::unique_ptr<Transport> &&transport)
thrift_buffer_(new apache::thrift::transport::TMemoryBuffer())
{}

int ThriftSender::Append(std::unique_ptr<Recordable> &&span) noexcept
int ThriftSender::Append(std::unique_ptr<JaegerRecordable> &&span) noexcept
{
if (span == nullptr)
{
Expand Down
4 changes: 2 additions & 2 deletions exporters/jaeger/src/thrift_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ThriftSender : public Sender
ThriftSender(std::unique_ptr<Transport> &&transport);
~ThriftSender() override { Close(); }

int Append(std::unique_ptr<Recordable> &&span) noexcept override;
int Append(std::unique_ptr<JaegerRecordable> &&span) noexcept override;
int Flush() override;
void Close() override;

Expand All @@ -57,7 +57,7 @@ class ThriftSender : public Sender
}

private:
std::vector<std::unique_ptr<Recordable>> spans_;
std::vector<std::unique_ptr<JaegerRecordable>> spans_;
std::vector<thrift::Span> span_buffer_;
std::unique_ptr<Transport> transport_;
std::unique_ptr<apache::thrift::protocol::TProtocolFactory> protocol_factory_;
Expand Down
16 changes: 8 additions & 8 deletions exporters/jaeger/test/jaeger_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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";

Expand Down Expand Up @@ -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";
Expand All @@ -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";
Expand Down