Skip to content

Commit

Permalink
Fix ParentReference to avoid moving a parent reference to the second …
Browse files Browse the repository at this point in the history
…place

Signed-off-by: Sherwood Wang <sherwoodwang@users.noreply.github.com>
  • Loading branch information
sherwoodwang committed Jan 19, 2024
1 parent 88efe47 commit 3d420a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions model/adjuster/parent_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func ParentReference() Adjuster {
for _, span := range trace.Spans {
firstChildOfRef := -1
firstOtherRef := -1
for i := 1; i < len(span.References); i++ {
for i := 0; i < len(span.References); i++ {
if span.References[i].TraceID == span.TraceID {
if span.References[i].RefType == model.SpanRefType_CHILD_OF {
firstChildOfRef = i
Expand All @@ -40,7 +40,7 @@ func ParentReference() Adjuster {
if swap == -1 {
swap = firstOtherRef
}
if swap != -1 {
if swap != 0 && swap != -1 {
span.References[swap], span.References[0] = span.References[0], span.References[swap]
}
}
Expand Down
5 changes: 5 additions & 0 deletions model/adjuster/parent_reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func TestParentReference(t *testing.T) {
incoming: []model.SpanRef{childOf(b)},
expected: []model.SpanRef{childOf(b)},
},
{
name: "local, local follows - keep order",
incoming: []model.SpanRef{childOf(a), followsFrom(b)},
expected: []model.SpanRef{childOf(a), followsFrom(b)},
},
{
name: "local and remote child in order",
incoming: []model.SpanRef{childOf(a), childOf(b)},
Expand Down

0 comments on commit 3d420a9

Please sign in to comment.