Skip to content

Commit 0b1b235

Browse files
tobiasstadlerlrouquette
authored andcommitted
Do not strip leading zeros from trace IDs and span IDs (jaegertracing#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>
1 parent 2d573bd commit 0b1b235

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

src/jaegertracing/SpanContext.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ class SpanContext : public opentracing::SpanContext {
156156
void print(Stream& out) const
157157
{
158158
_traceID.print(out);
159-
out << ':' << std::hex << _spanID << ':' << std::hex << _parentID << ':'
160-
<< std::hex << static_cast<size_t>(_flags);
159+
out << ':' << std::setw(16) << std::setfill('0') << std::hex << _spanID
160+
<< ':' << std::setw(16) << std::setfill('0') << std::hex << _parentID
161+
<< ':' << std::hex << static_cast<size_t>(_flags);
161162
}
162163

163164
void ForeachBaggageItem(

src/jaegertracing/SpanContextTest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ TEST(SpanContext, testFormatting)
7878
SpanContext spanContext(TraceID(255, 255), 0, 0, 0, SpanContext::StrMap());
7979
std::ostringstream oss;
8080
oss << spanContext;
81-
ASSERT_EQ("ff00000000000000ff:0:0:0", oss.str());
81+
ASSERT_EQ("00000000000000ff00000000000000ff:0000000000000000:0000000000000000:0", oss.str());
8282
}
8383

8484
TEST(SpanContext, testBaggage)

src/jaegertracing/TraceID.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ class TraceID {
4444
void print(Stream& out) const
4545
{
4646
if (_high == 0) {
47-
out << std::hex << _low;
47+
out << std::setw(16) << std::setfill('0') << std::hex << _low;
4848
}
4949
else {
50-
out << std::hex << _high << std::setw(16) << std::setfill('0')
51-
<< std::hex << _low;
50+
out << std::setw(16) << std::setfill('0') << std::hex << _high
51+
<< std::setw(16) << std::setfill('0') << std::hex << _low;
5252
}
5353
}
5454

src/jaegertracing/TraceIDTest.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@
2020

2121
namespace jaegertracing {
2222

23-
TEST(TraceID, testPrint)
23+
TEST(TraceID, testPrintWithouthHigh)
2424
{
2525
std::ostringstream oss;
2626
oss << TraceID(0, 10);
27-
ASSERT_EQ("a", oss.str());
27+
ASSERT_EQ("000000000000000a", oss.str());
28+
}
29+
30+
TEST(TraceID, testPrintWithHigh)
31+
{
32+
std::ostringstream oss;
33+
oss << TraceID(1, 10);
34+
ASSERT_EQ("0000000000000001000000000000000a", oss.str());
2835
}
2936

3037
} // namespace jaegertracing

0 commit comments

Comments
 (0)