From 9ba35cd40b464ea70c2d07effd268330540b6c2b Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 29 Aug 2022 16:18:18 -0700 Subject: [PATCH] Rever breaking change to [Trace|Span]ID.HexString() (#5995) Signed-off-by: Bogdan Signed-off-by: Bogdan --- pdata/pcommon/spanid.go | 3 +++ pdata/pcommon/spanid_test.go | 2 +- pdata/pcommon/traceid.go | 3 +++ pdata/pcommon/traceid_test.go | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pdata/pcommon/spanid.go b/pdata/pcommon/spanid.go index 8163646fc09..3ceae2c3aca 100644 --- a/pdata/pcommon/spanid.go +++ b/pdata/pcommon/spanid.go @@ -44,6 +44,9 @@ func (ms SpanID) Bytes() [8]byte { // HexString returns hex representation of the SpanID. func (ms SpanID) HexString() string { + if ms.IsEmpty() { + return "" + } return hex.EncodeToString(ms.orig[:]) } diff --git a/pdata/pcommon/spanid_test.go b/pdata/pcommon/spanid_test.go index 6a8b2d87ccb..a81cf01af49 100644 --- a/pdata/pcommon/spanid_test.go +++ b/pdata/pcommon/spanid_test.go @@ -34,7 +34,7 @@ func TestNewSpanID(t *testing.T) { func TestSpanIDHexString(t *testing.T) { sid := NewSpanID([8]byte{}) - assert.Equal(t, "0000000000000000", sid.HexString()) + assert.Equal(t, "", sid.HexString()) sid = NewSpanID([8]byte{0x12, 0x23, 0xAD, 0x12, 0x23, 0xAD, 0x12, 0x23}) assert.Equal(t, "1223ad1223ad1223", sid.HexString()) diff --git a/pdata/pcommon/traceid.go b/pdata/pcommon/traceid.go index 4a12199893f..e3a0dbf45d4 100644 --- a/pdata/pcommon/traceid.go +++ b/pdata/pcommon/traceid.go @@ -45,6 +45,9 @@ func (ms TraceID) Bytes() [16]byte { // HexString returns hex representation of the TraceID. func (ms TraceID) HexString() string { + if ms.IsEmpty() { + return "" + } return hex.EncodeToString(ms.orig[:]) } diff --git a/pdata/pcommon/traceid_test.go b/pdata/pcommon/traceid_test.go index 8159904abb4..2e4ee382df8 100644 --- a/pdata/pcommon/traceid_test.go +++ b/pdata/pcommon/traceid_test.go @@ -35,7 +35,7 @@ func TestNewTraceID(t *testing.T) { func TestTraceIDHexString(t *testing.T) { tid := NewTraceID([16]byte{}) - assert.Equal(t, "00000000000000000000000000000000", tid.HexString()) + assert.Equal(t, "", tid.HexString()) tid = NewTraceID([16]byte{0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78}) assert.Equal(t, "12345678123456781234567812345678", tid.HexString())