Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Do not strip leading zeros from trace IDs and span IDs #259

Merged
merged 3 commits into from
Jan 29, 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
5 changes: 3 additions & 2 deletions src/jaegertracing/SpanContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ class SpanContext : public opentracing::SpanContext {
void print(Stream& out) const
{
_traceID.print(out);
out << ':' << std::hex << _spanID << ':' << std::hex << _parentID << ':'
<< std::hex << static_cast<size_t>(_flags);
out << ':' << std::setw(16) << std::setfill('0') << std::hex << _spanID
<< ':' << std::setw(16) << std::setfill('0') << std::hex << _parentID
<< ':' << std::hex << static_cast<size_t>(_flags);
}

void ForeachBaggageItem(
Expand Down
2 changes: 1 addition & 1 deletion src/jaegertracing/SpanContextTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TEST(SpanContext, testFormatting)
SpanContext spanContext(TraceID(255, 255), 0, 0, 0, SpanContext::StrMap());
std::ostringstream oss;
oss << spanContext;
ASSERT_EQ("ff00000000000000ff:0:0:0", oss.str());
ASSERT_EQ("00000000000000ff00000000000000ff:0000000000000000:0000000000000000:0", oss.str());
}

TEST(SpanContext, testBaggage)
Expand Down
6 changes: 3 additions & 3 deletions src/jaegertracing/TraceID.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class TraceID {
void print(Stream& out) const
{
if (_high == 0) {
out << std::hex << _low;
out << std::setw(16) << std::setfill('0') << std::hex << _low;
}
else {
out << std::hex << _high << std::setw(16) << std::setfill('0')
<< std::hex << _low;
out << std::setw(16) << std::setfill('0') << std::hex << _high
<< std::setw(16) << std::setfill('0') << std::hex << _low;
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/jaegertracing/TraceIDTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@

namespace jaegertracing {

TEST(TraceID, testPrint)
TEST(TraceID, testPrintWithouthHigh)
{
std::ostringstream oss;
oss << TraceID(0, 10);
ASSERT_EQ("a", oss.str());
ASSERT_EQ("000000000000000a", oss.str());
}

TEST(TraceID, testPrintWithHigh)
{
std::ostringstream oss;
oss << TraceID(1, 10);
ASSERT_EQ("0000000000000001000000000000000a", oss.str());
}

} // namespace jaegertracing