Skip to content

Commit

Permalink
treat child-of ref as priority
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Rydz <niechzyjetequila@gmail.com>
  • Loading branch information
kubarydz committed Apr 14, 2023
1 parent cc6bd7a commit 3f09c0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions model/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,23 @@ func (s *Span) NormalizeTimestamps() {
}

// ParentSpanID returns ID of a parent span if it exists.
// It searches for the first child-of reference pointing to the same trace ID.
// It searches for the first child-of or follows-from reference pointing to the same trace ID.
func (s *Span) ParentSpanID() SpanID {
var followsFromRef *SpanRef
for i := range s.References {
ref := &s.References[i]
if ref.TraceID == s.TraceID && (ref.RefType == ChildOf || ref.RefType == FollowsFrom) {
if ref.TraceID != s.TraceID {
continue
}
if ref.RefType == ChildOf {
return ref.SpanID
}
if followsFromRef == nil && ref.RefType == FollowsFrom {
followsFromRef = ref
}
}
if followsFromRef != nil {
return followsFromRef.SpanID
}
return SpanID(0)
}
Expand Down
1 change: 1 addition & 0 deletions model/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func TestParentSpanID(t *testing.T) {
assert.Equal(t, model.NewSpanID(777), span.ParentSpanID())

span.References = []model.SpanRef{
model.NewFollowsFromRef(span.TraceID, model.NewSpanID(777)),
model.NewChildOfRef(span.TraceID, model.NewSpanID(888)),
}
assert.Equal(t, model.NewSpanID(888), span.ParentSpanID())
Expand Down

0 comments on commit 3f09c0f

Please sign in to comment.