Skip to content

Commit

Permalink
feat: support empty selector
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira committed May 5, 2022
1 parent 312cefe commit c18155d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/assertions/selectors/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type ParserSelector struct {
SpanSelectors []parserSpanSelector `( @@* ( "," @@ )*)`
SpanSelectors []parserSpanSelector `( @@* ( "," @@ )*)*`
}

type parserSpanSelector struct {
Expand Down
14 changes: 14 additions & 0 deletions server/assertions/selectors/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type Selector struct {
}

func (s Selector) Filter(trace traces.Trace) []traces.Span {
if len(s.spanSelectors) == 0 {
// empty selector should select everything
return getAllSpans(trace)
}

allFilteredSpans := make([]traces.Span, 0)
for _, spanSelector := range s.spanSelectors {
spans := filterSpans(trace.RootSpan, spanSelector)
Expand All @@ -21,6 +26,15 @@ func (s Selector) Filter(trace traces.Trace) []traces.Span {
return allFilteredSpans
}

func getAllSpans(trace traces.Trace) []traces.Span {
var allSpans = make([]traces.Span, 0)
traverseTree(trace.RootSpan, func(span traces.Span) {
allSpans = append(allSpans, span)
})

return allSpans
}

type spanSelector struct {
Filters []filter
PsedoClass PseudoClass
Expand Down
5 changes: 5 additions & 0 deletions server/assertions/selectors/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func TestSelector(t *testing.T) {
Expression string
ExpectedSpanIds []trace.SpanID
}{
{
Name: "Empty selector should select all spans",
Expression: ``,
ExpectedSpanIds: []trace.SpanID{postImportSpanID, insertPokemonDatabaseSpanID, getPokemonFromExternalAPISpanID, updatePokemonDatabaseSpanID},
},
{
Name: "Selector with span name",
Expression: `span[name="Get pokemon from external API"]`,
Expand Down

0 comments on commit c18155d

Please sign in to comment.