Skip to content

Commit

Permalink
Use lowercase base 16 representation of ids (open-telemetry#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Tax authored May 20, 2020
1 parent fd0e3e2 commit cee4804
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/include/opentelemetry/trace/span_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SpanId final
// Populates the buffer with the lowercase base16 representation of the ID.
void ToLowerBase16(nostd::span<char, 2 * kSize> buffer) const noexcept
{
constexpr char kHex[] = "0123456789ABCDEF";
constexpr char kHex[] = "0123456789abcdef";
for (int i = 0; i < kSize; ++i)
{
buffer[i * 2 + 0] = kHex[(rep_[i] >> 4) & 0xF];
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/trace/trace_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TraceId final
// Populates the buffer with the lowercase base16 representation of the ID.
void ToLowerBase16(nostd::span<char, 2 * kSize> buffer) const noexcept
{
constexpr char kHex[] = "0123456789ABCDEF";
constexpr char kHex[] = "0123456789abcdef";
for (int i = 0; i < kSize; ++i)
{
buffer[i * 2 + 0] = kHex[(rep_[i] >> 4) & 0xF];
Expand Down
10 changes: 10 additions & 0 deletions api/test/trace/span_id_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ TEST(SpanIdTest, ValidId)
EXPECT_EQ(SpanId(buf), id);
}

TEST(SpanIdTest, LowercaseBase16)
{
constexpr uint8_t buf[] = {1, 2, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
SpanId id(buf);
EXPECT_TRUE(id.IsValid());
EXPECT_EQ("0102aabbccddeeff", Hex(id));
EXPECT_NE(SpanId(), id);
EXPECT_EQ(SpanId(buf), id);
}

TEST(SpanIdTest, CopyBytesTo)
{
constexpr uint8_t src[] = {1, 2, 3, 4, 5, 6, 7, 8};
Expand Down
10 changes: 10 additions & 0 deletions api/test/trace/trace_id_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ TEST(TraceIdTest, ValidId)
EXPECT_EQ(TraceId(buf), id);
}

TEST(TraceIdTest, LowercaseBase16)
{
constexpr uint8_t buf[] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
TraceId id(buf);
EXPECT_TRUE(id.IsValid());
EXPECT_EQ("01020304050607080807aabbccddeeff", Hex(id));
EXPECT_NE(TraceId(), id);
EXPECT_EQ(TraceId(buf), id);
}

TEST(TraceIdTest, CopyBytesTo)
{
constexpr uint8_t src[] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1};
Expand Down

0 comments on commit cee4804

Please sign in to comment.