Skip to content

Commit

Permalink
Fix otlp generates null span ids (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo authored Dec 4, 2021
1 parent a92340d commit baeee42
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Increment the:

## [Unreleased]

* [EXPORTER] Fix otlp generates null span ids ([#1106](https://github.com/open-telemetry/opentelemetry-cpp/pull/1106))

## [1.1.0] 2021-11-19

* [BUILD] build release tarball when nlohmann-json not installed ([#1074](https://github.com/open-telemetry/opentelemetry-cpp/pull/1074))
Expand Down
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

0 comments on commit baeee42

Please sign in to comment.