Skip to content

Commit

Permalink
Extend IsEmpty to SpanID, remove usage of IsValid (#2342)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Jan 11, 2021
1 parent 60b5a25 commit 28e3cc1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions consumer/pdata/spanid.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func (t SpanID) HexString() string {
}

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

// IsEmpty returns true if id doesn't contain at least one non-zero byte.
func (t SpanID) IsEmpty() bool {
return !data.SpanID(t).IsValid()
}
2 changes: 2 additions & 0 deletions consumer/pdata/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ func TestSpanCountWithEmpty(t *testing.T) {
func TestSpanID(t *testing.T) {
sid := InvalidSpanID()
assert.EqualValues(t, [8]byte{}, sid.Bytes())
assert.True(t, sid.IsEmpty())

sid = NewSpanID([8]byte{1, 2, 3, 4, 4, 3, 2, 1})
assert.EqualValues(t, [8]byte{1, 2, 3, 4, 4, 3, 2, 1}, sid.Bytes())
assert.False(t, sid.IsEmpty())
}

func TestTraceID(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions translator/internaldata/traces_to_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,15 @@ func linksToOC(links pdata.SpanLinkSlice, droppedCount uint32) *octrace.Span_Lin
}

func traceIDToOC(tid pdata.TraceID) []byte {
if !tid.IsValid() {
if tid.IsEmpty() {
return nil
}
tidBytes := tid.Bytes()
return tidBytes[:]
}

func spanIDToOC(sid pdata.SpanID) []byte {
if !sid.IsValid() {
if sid.IsEmpty() {
return nil
}
sidBytes := sid.Bytes()
Expand Down
2 changes: 1 addition & 1 deletion translator/trace/jaeger/traces_to_jaegerproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func makeJaegerProtoReferences(
parentSpanID pdata.SpanID,
traceID model.TraceID,
) ([]model.SpanRef, error) {
parentSpanIDSet := parentSpanID.IsValid()
parentSpanIDSet := !parentSpanID.IsEmpty()
if !parentSpanIDSet && links.Len() == 0 {
return nil, nil
}
Expand Down
6 changes: 3 additions & 3 deletions translator/trace/zipkin/traces_to_zipkinv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ func spanToZipkinSpan(

zs := &zipkinmodel.SpanModel{}

if !span.TraceID().IsValid() {
if span.TraceID().IsEmpty() {
return zs, errors.New("TraceID is invalid")
}
zs.TraceID = convertTraceID(span.TraceID())
if !span.SpanID().IsValid() {
if span.SpanID().IsEmpty() {
return zs, errors.New("SpanID is invalid")
}
zs.ID = convertSpanID(span.SpanID())
Expand All @@ -114,7 +114,7 @@ func spanToZipkinSpan(
tags[tracetranslator.TagW3CTraceState] = string(span.TraceState())
}

if span.ParentSpanID().IsValid() {
if !span.ParentSpanID().IsEmpty() {
id := convertSpanID(span.ParentSpanID())
zs.ParentID = &id
}
Expand Down

0 comments on commit 28e3cc1

Please sign in to comment.