diff --git a/.chloggen/deprecate_hexstring.yaml b/.chloggen/deprecate_hexstring.yaml new file mode 100755 index 000000000000..465e779a7f2f --- /dev/null +++ b/.chloggen/deprecate_hexstring.yaml @@ -0,0 +1,4 @@ +change_type: 'deprecation' +component: pdata +note: Deprecate `pcommon.[Span|Trace]ID.HexString` methods. Call `hex.EncodeToString` explicitly instead. +issues: [6514] diff --git a/pdata/pcommon/spanid.go b/pdata/pcommon/spanid.go index 44c4f249fae3..4052297ed523 100644 --- a/pdata/pcommon/spanid.go +++ b/pdata/pcommon/spanid.go @@ -29,7 +29,19 @@ func NewSpanIDEmpty() SpanID { return emptySpanID } -// HexString returns hex representation of the SpanID. +// HexString returns string representation of the SpanID. +// +// Important: Don't rely on this method to get a string identifier of SpanID, +// Use hex.EncodeToString explicitly instead. +// This method meant to implement Stringer interface for display purposes only. +func (ms SpanID) String() string { + if ms.IsEmpty() { + return "" + } + return hex.EncodeToString(ms[:]) +} + +// Deprecated: [0.65.0] Call hex.EncodeToString explicitly instead. func (ms SpanID) HexString() string { if ms.IsEmpty() { return "" diff --git a/pdata/pcommon/spanid_test.go b/pdata/pcommon/spanid_test.go index c8ce41321953..61b68c3ddac6 100644 --- a/pdata/pcommon/spanid_test.go +++ b/pdata/pcommon/spanid_test.go @@ -40,6 +40,14 @@ func TestSpanIDHexString(t *testing.T) { assert.Equal(t, "1223ad1223ad1223", sid.HexString()) } +func TestSpanIDString(t *testing.T) { + sid := SpanID([8]byte{}) + assert.Equal(t, "", sid.String()) + + sid = SpanID([8]byte{0x12, 0x23, 0xAD, 0x12, 0x23, 0xAD, 0x12, 0x23}) + assert.Equal(t, "1223ad1223ad1223", sid.String()) +} + func TestSpanIDImmutable(t *testing.T) { initialBytes := [8]byte{0x12, 0x23, 0xAD, 0x12, 0x23, 0xAD, 0x12, 0x23} sid := SpanID(initialBytes) diff --git a/pdata/pcommon/traceid.go b/pdata/pcommon/traceid.go index ed47d67a6d54..e40cc8740188 100644 --- a/pdata/pcommon/traceid.go +++ b/pdata/pcommon/traceid.go @@ -30,7 +30,19 @@ func NewTraceIDEmpty() TraceID { return emptyTraceID } -// HexString returns hex representation of the TraceID. +// HexString returns string representation of the TraceID. +// +// Important: Don't rely on this method to get a string identifier of TraceID. +// Use hex.EncodeToString explicitly instead. +// This method meant to implement Stringer interface for display purposes only. +func (ms TraceID) String() string { + if ms.IsEmpty() { + return "" + } + return hex.EncodeToString(ms[:]) +} + +// Deprecated: [0.65.0] Call hex.EncodeToString explicitly instead. func (ms TraceID) HexString() string { if ms.IsEmpty() { return "" diff --git a/pdata/pcommon/traceid_test.go b/pdata/pcommon/traceid_test.go index 9aaa476daa0d..665eee9f20e4 100644 --- a/pdata/pcommon/traceid_test.go +++ b/pdata/pcommon/traceid_test.go @@ -41,6 +41,14 @@ func TestTraceIDHexString(t *testing.T) { assert.Equal(t, "12345678123456781234567812345678", tid.HexString()) } +func TestTraceIDString(t *testing.T) { + tid := TraceID([16]byte{}) + assert.Equal(t, "", tid.String()) + + tid = [16]byte{0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78} + assert.Equal(t, "12345678123456781234567812345678", tid.String()) +} + func TestTraceIDImmutable(t *testing.T) { initialBytes := [16]byte{0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78} tid := TraceID(initialBytes)