From 642e40de36b7e9d2a56b9509ac041da8f5e683aa Mon Sep 17 00:00:00 2001 From: Jakub Rydz Date: Fri, 14 Apr 2023 01:46:26 +0200 Subject: [PATCH 1/2] handle follows from as parent span id Signed-off-by: Jakub Rydz --- model/adjuster/clockskew.go | 1 - model/span.go | 2 +- model/span_test.go | 4 ++++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/model/adjuster/clockskew.go b/model/adjuster/clockskew.go index 167590d862d..dccc5e8d580 100644 --- a/model/adjuster/clockskew.go +++ b/model/adjuster/clockskew.go @@ -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 diff --git a/model/span.go b/model/span.go index 5136e06b3ea..658025563f6 100644 --- a/model/span.go +++ b/model/span.go @@ -101,7 +101,7 @@ func (s *Span) NormalizeTimestamps() { func (s *Span) ParentSpanID() SpanID { for i := range s.References { ref := &s.References[i] - if ref.TraceID == s.TraceID && ref.RefType == ChildOf { + if ref.TraceID == s.TraceID && (ref.RefType == ChildOf || ref.RefType == FollowsFrom) { return ref.SpanID } } diff --git a/model/span_test.go b/model/span_test.go index 9aa50389365..d7681d990a4 100644 --- a/model/span_test.go +++ b/model/span_test.go @@ -279,6 +279,10 @@ func TestParentSpanID(t *testing.T) { span.References = []model.SpanRef{ model.NewFollowsFromRef(span.TraceID, model.NewSpanID(777)), + } + assert.Equal(t, model.NewSpanID(777), span.ParentSpanID()) + + span.References = []model.SpanRef{ model.NewChildOfRef(span.TraceID, model.NewSpanID(888)), } assert.Equal(t, model.NewSpanID(888), span.ParentSpanID()) From fc92318185c03c2daea41c86dc61a90e6ee0e72f Mon Sep 17 00:00:00 2001 From: Jakub Rydz Date: Fri, 14 Apr 2023 11:43:34 +0200 Subject: [PATCH 2/2] treat child-of ref as priority Signed-off-by: Jakub Rydz --- model/span.go | 14 ++++++++++++-- model/span_test.go | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/model/span.go b/model/span.go index 658025563f6..749f21dbf2a 100644 --- a/model/span.go +++ b/model/span.go @@ -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) } diff --git a/model/span_test.go b/model/span_test.go index d7681d990a4..efd9b5b9c08 100644 --- a/model/span_test.go +++ b/model/span_test.go @@ -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())