Skip to content

Commit

Permalink
Allow follows-from reference as a parent span id (jaegertracing#4382)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
Resolves jaegertracing#4380

## Short description of the changes
handle FOLLOWS_FROM as a parent span ID

---------

Signed-off-by: Jakub Rydz <[email protected]>
Co-authored-by: Yuri Shkuro <[email protected]>
  • Loading branch information
kubarydz and yurishkuro authored Apr 16, 2023
1 parent 5d6a2e8 commit 0ee275a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 0 additions & 1 deletion model/adjuster/clockskew.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func (a *clockSkewAdjuster) buildNodesMap() {
func (a *clockSkewAdjuster) buildSubGraphs() {
a.roots = make(map[model.SpanID]*node)
for _, n := range a.spans {
// TODO handle FOLLOWS_FROM references
if n.span.ParentSpanID() == 0 {
a.roots[n.span.SpanID] = n
continue
Expand Down
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 {
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
5 changes: 5 additions & 0 deletions model/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ func TestParentSpanID(t *testing.T) {
span := makeSpan(model.String("k", "v"))
assert.Equal(t, model.NewSpanID(123), span.ParentSpanID())

span.References = []model.SpanRef{
model.NewFollowsFromRef(span.TraceID, model.NewSpanID(777)),
}
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)),
Expand Down

0 comments on commit 0ee275a

Please sign in to comment.