Skip to content

Commit

Permalink
Add bridge behind feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerHelmuth committed May 23, 2023
1 parent 907b693 commit 94365e4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
28 changes: 27 additions & 1 deletion internal/filter/filterspan/filterspan.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"

"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/pcommon"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"

Expand All @@ -19,11 +20,36 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlspan"
)

var useOTTLBridge = featuregate.GlobalRegistry().MustRegister(
"filter.filterspan.useOTTLBridge",
featuregate.StageAlpha,
featuregate.WithRegisterDescription("When enabled, filterspan will convert filterspan configuration to OTTL and use filterottl evaluation"),
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/18642"),
)

// NewSkipExpr creates a BoolExpr that on evaluation returns true if a span should NOT be processed or kept.
// The logic determining if a span should be processed is based on include and exclude settings.
// Include properties are checked before exclude settings are checked.
func NewSkipExpr(mp *filterconfig.MatchConfig) (expr.BoolExpr[ottlspan.TransformContext], error) {
return filterottl.NewSpanSkipExprBridge(mp)
if useOTTLBridge.IsEnabled() {
return filterottl.NewSpanSkipExprBridge(mp)
}
var matchers []expr.BoolExpr[ottlspan.TransformContext]
inclExpr, err := newExpr(mp.Include)
if err != nil {
return nil, err
}
if inclExpr != nil {
matchers = append(matchers, expr.Not(inclExpr))
}
exclExpr, err := newExpr(mp.Exclude)
if err != nil {
return nil, err
}
if exclExpr != nil {
matchers = append(matchers, exclExpr)
}
return expr.Or(matchers...), nil
}

// propertiesMatcher allows matching a span against various span properties.
Expand Down
11 changes: 10 additions & 1 deletion internal/filter/filterspan/filterspan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
Expand Down Expand Up @@ -333,6 +334,10 @@ func BenchmarkFilterspan_NewSkipExpr(b *testing.B) {
}

for _, tt := range testCases {
origVal := useOTTLBridge.IsEnabled()
err := featuregate.GlobalRegistry().Set("useOTTLBridge", true)
assert.NoError(b, err)

skipExpr, err := NewSkipExpr(tt.mc)
assert.NoError(b, err)

Expand All @@ -355,10 +360,14 @@ func BenchmarkFilterspan_NewSkipExpr(b *testing.B) {

b.Run(tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
skip, err := skipExpr.Eval(context.Background(), tCtx)
var skip bool
skip, err = skipExpr.Eval(context.Background(), tCtx)
assert.NoError(b, err)
assert.Equal(b, tt.skip, skip)
}
})

err = featuregate.GlobalRegistry().Set("useOTTLBridge", origVal)
assert.NoError(b, err)
}
}

0 comments on commit 94365e4

Please sign in to comment.