Skip to content

Commit

Permalink
fix: Root spans must have a non-empty parent ID field (#1236)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?

Span's with a `parentID` field with an empty value `""` are considered
root spans. This PR updates the logic to determine root spans to check
that both the parentID field exists and is not empty for it to be
considered a root span.

- Fixes #1234 

## Short description of the changes
- Check the parentID field is both present and has a value when checking
if the span is a root span
- Update tests to verify updated behaviour

Co-authored-by: Kent Quirk <kentquirk@honeycomb.io>
  • Loading branch information
MikeGoldsmith and kentquirk authored Jul 18, 2024
1 parent 3af0b4e commit 923c010
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion collect/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func (i *InMemCollector) isRootSpan(sp *types.Span) bool {
// check if the event has a parent id using the configured parent id field names
for _, parentIdFieldName := range i.Config.GetParentIdFieldNames() {
parentId := sp.Data[parentIdFieldName]
if _, ok := parentId.(string); ok {
if _, ok := parentId.(string); ok && parentId != "" {
return false
}
}
Expand Down
4 changes: 2 additions & 2 deletions collect/collect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1384,15 +1384,15 @@ func TestIsRootSpan(t *testing.T) {
expected: true,
},
{
name: "non-root span - empty parent id",
name: "root span - empty parent id",
span: &types.Span{
Event: types.Event{
Data: map[string]interface{}{
"trace.parent_id": "",
},
},
},
expected: false,
expected: true,
},
{
name: "non-root span - parent id",
Expand Down

0 comments on commit 923c010

Please sign in to comment.