Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow follows-from reference as a parent span id #4382

Merged
merged 3 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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