Skip to content

Commit baeee42

Browse files
authored
Fix otlp generates null span ids (#1113)
1 parent a92340d commit baeee42

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Increment the:
1515

1616
## [Unreleased]
1717

18+
* [EXPORTER] Fix otlp generates null span ids ([#1106](https://github.com/open-telemetry/opentelemetry-cpp/pull/1106))
19+
1820
## [1.1.0] 2021-11-19
1921

2022
* [BUILD] build release tarball when nlohmann-json not installed ([#1074](https://github.com/open-telemetry/opentelemetry-cpp/pull/1074))

exporters/otlp/src/otlp_recordable.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ void OtlpRecordable::SetIdentity(const opentelemetry::trace::SpanContext &span_c
2020
trace::TraceId::kSize);
2121
span_.set_span_id(reinterpret_cast<const char *>(span_context.span_id().Id().data()),
2222
trace::SpanId::kSize);
23-
span_.set_parent_span_id(reinterpret_cast<const char *>(parent_span_id.Id().data()),
24-
trace::SpanId::kSize);
23+
if (parent_span_id.IsValid())
24+
{
25+
span_.set_parent_span_id(reinterpret_cast<const char *>(parent_span_id.Id().data()),
26+
trace::SpanId::kSize);
27+
}
2528
span_.set_trace_state(span_context.trace_state()->ToHeader());
2629
}
2730

exporters/otlp/test/otlp_recordable_test.cc

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ TEST(OtlpRecordable, SetIdentity)
3939
EXPECT_EQ(rec.span().parent_span_id(),
4040
std::string(reinterpret_cast<const char *>(parent_span_id.Id().data()),
4141
trace::SpanId::kSize));
42+
43+
OtlpRecordable rec_invalid_parent;
44+
45+
constexpr uint8_t invalid_parent_span_id_buf[] = {0, 0, 0, 0, 0, 0, 0, 0};
46+
trace_api::SpanId invalid_parent_span_id{invalid_parent_span_id_buf};
47+
rec_invalid_parent.SetIdentity(span_context, invalid_parent_span_id);
48+
49+
EXPECT_EQ(rec_invalid_parent.span().parent_span_id(), std::string{});
4250
}
4351

4452
TEST(OtlpRecordable, SetName)

0 commit comments

Comments
 (0)