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

Not set parentId in case parentId is empty #943

Merged
merged 2 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 9 additions & 5 deletions exporters/zipkin/src/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ 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);
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);
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_["traceId"] = std::string(trace_id_lower_base16, 32);
}

void PopulateAttribute(nlohmann::json &attribute,
Expand Down
23 changes: 23 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,29 @@ 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