Skip to content

Commit

Permalink
Do not strip leading zeros from trace IDs and span IDs (jaegertracing…
Browse files Browse the repository at this point in the history
…#259)

* Do not strip leading zeros from trace IDs

Signed-off-by: Tobias Stadler <ts.stadler@gmx.de>

* Do not strip leading zeros from span IDs

Signed-off-by: Tobias Stadler <ts.stadler@gmx.de>

* high should only be used if it is non zero

Signed-off-by: Tobias Stadler <ts.stadler@gmx.de>
  • Loading branch information
tobiasstadler authored and lrouquette committed Oct 27, 2021
1 parent 2d573bd commit 0b1b235
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
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

0 comments on commit 0b1b235

Please sign in to comment.