From 1e36d095f71b82b9610a365ea4e1a37ce3046ce9 Mon Sep 17 00:00:00 2001 From: Tobias Stadler Date: Fri, 29 Jan 2021 09:55:29 +0100 Subject: [PATCH 1/3] Do not strip leading zeros from trace IDs Signed-off-by: Tobias Stadler --- src/jaegertracing/SpanContextTest.cpp | 2 +- src/jaegertracing/TraceID.h | 9 ++------- src/jaegertracing/TraceIDTest.cpp | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/jaegertracing/SpanContextTest.cpp b/src/jaegertracing/SpanContextTest.cpp index 6eef6b3c..33530668 100644 --- a/src/jaegertracing/SpanContextTest.cpp +++ b/src/jaegertracing/SpanContextTest.cpp @@ -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:0:0:0", oss.str()); } TEST(SpanContext, testBaggage) diff --git a/src/jaegertracing/TraceID.h b/src/jaegertracing/TraceID.h index 867f0c29..4348a3dc 100644 --- a/src/jaegertracing/TraceID.h +++ b/src/jaegertracing/TraceID.h @@ -43,13 +43,8 @@ class TraceID { template void print(Stream& out) const { - if (_high == 0) { - out << 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; } uint64_t high() const { return _high; } diff --git a/src/jaegertracing/TraceIDTest.cpp b/src/jaegertracing/TraceIDTest.cpp index ece21cfe..678d150f 100644 --- a/src/jaegertracing/TraceIDTest.cpp +++ b/src/jaegertracing/TraceIDTest.cpp @@ -24,7 +24,7 @@ TEST(TraceID, testPrint) { std::ostringstream oss; oss << TraceID(0, 10); - ASSERT_EQ("a", oss.str()); + ASSERT_EQ("0000000000000000000000000000000a", oss.str()); } } // namespace jaegertracing From cff57dc48531af4f9e927bafe4226ad23a730f1b Mon Sep 17 00:00:00 2001 From: Tobias Stadler Date: Fri, 29 Jan 2021 09:55:47 +0100 Subject: [PATCH 2/3] Do not strip leading zeros from span IDs Signed-off-by: Tobias Stadler --- src/jaegertracing/SpanContext.h | 5 +++-- src/jaegertracing/SpanContextTest.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/jaegertracing/SpanContext.h b/src/jaegertracing/SpanContext.h index 295a7e91..4055e4e5 100644 --- a/src/jaegertracing/SpanContext.h +++ b/src/jaegertracing/SpanContext.h @@ -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(_flags); + out << ':' << std::setw(16) << std::setfill('0') << std::hex << _spanID + << ':' << std::setw(16) << std::setfill('0') << std::hex << _parentID + << ':' << std::hex << static_cast(_flags); } void ForeachBaggageItem( diff --git a/src/jaegertracing/SpanContextTest.cpp b/src/jaegertracing/SpanContextTest.cpp index 33530668..bcb4b177 100644 --- a/src/jaegertracing/SpanContextTest.cpp +++ b/src/jaegertracing/SpanContextTest.cpp @@ -78,7 +78,7 @@ TEST(SpanContext, testFormatting) SpanContext spanContext(TraceID(255, 255), 0, 0, 0, SpanContext::StrMap()); std::ostringstream oss; oss << spanContext; - ASSERT_EQ("00000000000000ff00000000000000ff:0:0:0", oss.str()); + ASSERT_EQ("00000000000000ff00000000000000ff:0000000000000000:0000000000000000:0", oss.str()); } TEST(SpanContext, testBaggage) From b5a7328b5957b466266acbbf17c56f8d43039e7d Mon Sep 17 00:00:00 2001 From: Tobias Stadler Date: Fri, 29 Jan 2021 19:25:17 +0100 Subject: [PATCH 3/3] high should only be used if it is non zero Signed-off-by: Tobias Stadler --- src/jaegertracing/TraceID.h | 9 +++++++-- src/jaegertracing/TraceIDTest.cpp | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/jaegertracing/TraceID.h b/src/jaegertracing/TraceID.h index 4348a3dc..5b9c5a95 100644 --- a/src/jaegertracing/TraceID.h +++ b/src/jaegertracing/TraceID.h @@ -43,8 +43,13 @@ class TraceID { template void print(Stream& out) const { - out << std::setw(16) << std::setfill('0') << std::hex << _high - << std::setw(16) << std::setfill('0') << std::hex << _low; + if (_high == 0) { + out << std::setw(16) << std::setfill('0') << std::hex << _low; + } + else { + out << std::setw(16) << std::setfill('0') << std::hex << _high + << std::setw(16) << std::setfill('0') << std::hex << _low; + } } uint64_t high() const { return _high; } diff --git a/src/jaegertracing/TraceIDTest.cpp b/src/jaegertracing/TraceIDTest.cpp index 678d150f..136e6e5f 100644 --- a/src/jaegertracing/TraceIDTest.cpp +++ b/src/jaegertracing/TraceIDTest.cpp @@ -20,11 +20,18 @@ namespace jaegertracing { -TEST(TraceID, testPrint) +TEST(TraceID, testPrintWithouthHigh) { std::ostringstream oss; oss << TraceID(0, 10); - ASSERT_EQ("0000000000000000000000000000000a", oss.str()); + ASSERT_EQ("000000000000000a", oss.str()); +} + +TEST(TraceID, testPrintWithHigh) +{ + std::ostringstream oss; + oss << TraceID(1, 10); + ASSERT_EQ("0000000000000001000000000000000a", oss.str()); } } // namespace jaegertracing