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

Fix otlp generates null span ids #1113

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 5 additions & 2 deletions exporters/otlp/src/otlp_recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ void OtlpRecordable::SetIdentity(const opentelemetry::trace::SpanContext &span_c
trace::TraceId::kSize);
span_.set_span_id(reinterpret_cast<const char *>(span_context.span_id().Id().data()),
trace::SpanId::kSize);
span_.set_parent_span_id(reinterpret_cast<const char *>(parent_span_id.Id().data()),
trace::SpanId::kSize);
if (parent_span_id.IsValid())
{
span_.set_parent_span_id(reinterpret_cast<const char *>(parent_span_id.Id().data()),
trace::SpanId::kSize);
}
span_.set_trace_state(span_context.trace_state()->ToHeader());
}

Expand Down
8 changes: 8 additions & 0 deletions exporters/otlp/test/otlp_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ TEST(OtlpRecordable, SetIdentity)
EXPECT_EQ(rec.span().parent_span_id(),
std::string(reinterpret_cast<const char *>(parent_span_id.Id().data()),
trace::SpanId::kSize));

OtlpRecordable rec_invalid_parent;

constexpr uint8_t invalid_parent_span_id_buf[] = {0, 0, 0, 0, 0, 0, 0, 0};
trace_api::SpanId invalid_parent_span_id{invalid_parent_span_id_buf};
rec_invalid_parent.SetIdentity(span_context, invalid_parent_span_id);

EXPECT_EQ(rec_invalid_parent.span().parent_span_id(), std::string{});
}

TEST(OtlpRecordable, SetName)
Expand Down