Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions exporters/zipkin/src/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ void Recordable::SetIdentity(const opentelemetry::trace::SpanContext &span_conte
span_context.trace_id().ToLowerBase16(trace_id_lower_base16);
char span_id_lower_base16[trace::SpanId::kSize * 2] = {0};
span_context.span_id().ToLowerBase16(span_id_lower_base16);
char parent_span_id_lower_base16[trace::SpanId::kSize * 2] = {0};
parent_span_id.ToLowerBase16(parent_span_id_lower_base16);
if (parent_span_id.IsValid())
{
char parent_span_id_lower_base16[trace::SpanId::kSize * 2] = {0};
parent_span_id.ToLowerBase16(parent_span_id_lower_base16);
span_["parentId"] = std::string(parent_span_id_lower_base16, 16);
}

span_["id"] = std::string(span_id_lower_base16, 16);
span_["parentId"] = std::string(parent_span_id_lower_base16, 16);
span_["traceId"] = std::string(trace_id_lower_base16, 32);
}

Expand Down
24 changes: 24 additions & 0 deletions exporters/zipkin/test/zipkin_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ TEST(ZipkinSpanRecordable, SetIdentity)
EXPECT_EQ(rec.span(), j_span);
}

// according to https://zipkin.io/zipkin-api/#/ in case root span is created
// the parentId filed should be absent.
TEST(ZipkinSpanRecordable, SetIdentityEmptyParent)
{
json j_span = {{"id", "0000000000000002"},
{"traceId", "00000000000000000000000000000001"}};
opentelemetry::exporter::zipkin::Recordable rec;
const trace::TraceId trace_id(std::array<const uint8_t, trace::TraceId::kSize>(
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}));

const trace::SpanId span_id(
std::array<const uint8_t, trace::SpanId::kSize>({0, 0, 0, 0, 0, 0, 0, 2}));

const trace::SpanId parent_span_id(
std::array<const uint8_t, trace::SpanId::kSize>({0, 0, 0, 0, 0, 0, 0, 0}));

const opentelemetry::trace::SpanContext span_context{
trace_id, span_id,
opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true};

rec.SetIdentity(span_context, parent_span_id);
EXPECT_EQ(rec.span(), j_span);
}

TEST(ZipkinSpanRecordable, SetName)
{
nostd::string_view name = "Test Span";
Expand Down