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())