Skip to content

Commit

Permalink
Add pdata TraceID.IsEmpty() method (#2331)
Browse files Browse the repository at this point in the history
* Add pdata TraceID.IsEmpty() method

Add the new method that equals to calling !data.TraceID(t).IsValid() for
the internal data.TraceID.

* Add a deprecation note for the TraceID.IsValid

We don't need both since they are equivalent.

* Add TraceID.IsEmpty method call to tests

Extend TestTraceID.
  • Loading branch information
ozerovandrei authored Jan 7, 2021
1 parent a263ced commit 4380571
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions consumer/pdata/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ func TestSpanID(t *testing.T) {
func TestTraceID(t *testing.T) {
tid := InvalidTraceID()
assert.EqualValues(t, [16]byte{}, tid.Bytes())
assert.True(t, tid.IsEmpty())

tid = NewTraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1})
assert.EqualValues(t, [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}, tid.Bytes())
assert.False(t, tid.IsEmpty())
}

func TestSpanStatusCode(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions consumer/pdata/traceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func (t TraceID) HexString() string {
}

// IsValid returns true if id contains at leas one non-zero byte.
// Deprecated: use !IsEmpty() instead.
func (t TraceID) IsValid() bool {
return data.TraceID(t).IsValid()
}

// IsEmpty returns true if id doesn't contain at least one non-zero byte.
func (t TraceID) IsEmpty() bool {
return !data.TraceID(t).IsValid()
}

0 comments on commit 4380571

Please sign in to comment.