Skip to content
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
2 changes: 1 addition & 1 deletion source/extensions/tracers/zipkin/span_context_extractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ std::pair<SpanContext, bool> SpanContextExtractor::extractSpanContext(bool is_sa
}

auto b3_parent_id_entry = request_headers_.get(ZipkinCoreConstants::get().X_B3_PARENT_SPAN_ID);
if (b3_parent_id_entry) {
if (b3_parent_id_entry && b3_parent_id_entry->value().size() > 0) {
const std::string pspid = b3_parent_id_entry->value().c_str();
if (!StringUtil::atoull(pspid.c_str(), parent_id, 16)) {
throw ExtractorException(fmt::format("Invalid parent span id {}", pspid.c_str()));
Expand Down
21 changes: 21 additions & 0 deletions test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,27 @@ TEST_F(ZipkinDriverTest, ZipkinSpanContextFromB3HeadersTest) {
EXPECT_TRUE(zipkin_span->span().sampled());
}

TEST_F(ZipkinDriverTest, ZipkinSpanContextFromB3HeadersEmptyParentSpanTest) {
setupValidDriver();

// Root span so have same trace and span id
const std::string id = Hex::uint64ToHex(generateRandom64());
request_headers_.addReferenceKey(ZipkinCoreConstants::get().X_B3_TRACE_ID, id);
request_headers_.addReferenceKey(ZipkinCoreConstants::get().X_B3_SPAN_ID, id);
request_headers_.addReferenceKey(ZipkinCoreConstants::get().X_B3_SAMPLED,
ZipkinCoreConstants::get().SAMPLED);

// Set parent span id to empty string, to ensure it is ignored
const std::string parent_span_id = "";
request_headers_.addReferenceKey(ZipkinCoreConstants::get().X_B3_PARENT_SPAN_ID, parent_span_id);

Tracing::SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_,
start_time_, {Tracing::Reason::Sampling, true});

ZipkinSpanPtr zipkin_span(dynamic_cast<ZipkinSpan*>(span.release()));
EXPECT_TRUE(zipkin_span->span().sampled());
}

TEST_F(ZipkinDriverTest, ZipkinSpanContextFromB3Headers128TraceIdTest) {
setupValidDriver();

Expand Down