Skip to content

Commit e599c98

Browse files
committed
Pass policy name to NewEvaluator
It can be useful for an instance of an evaluator to know the name of the policy for debugging or reporting purposes. Since a single type can be used multiple times with different configuration.
1 parent c49c5ab commit e599c98

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

processor/tailsamplingprocessor/pkg/samplingpolicy/samplingpolicy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ type Evaluator interface {
6363
}
6464

6565
type Extension interface {
66-
NewEvaluator(cfg map[string]any) (Evaluator, error)
66+
NewEvaluator(policyName string, cfg map[string]any) (Evaluator, error)
6767
}

processor/tailsamplingprocessor/processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func getSharedPolicyEvaluator(settings component.TelemetrySettings, cfg *sharedP
276276
t := string(cfg.Type)
277277
extension, ok := policyExtensions[t]
278278
if ok {
279-
evaluator, err := extension.NewEvaluator(cfg.ExtensionCfg[t])
279+
evaluator, err := extension.NewEvaluator(cfg.Name, cfg.ExtensionCfg[t])
280280
if err != nil {
281281
return nil, fmt.Errorf("unable to load extension %s: %w", t, err)
282282
}

processor/tailsamplingprocessor/processor_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ func TestExtension(t *testing.T) {
10681068

10691069
tsp := p.(*tailSamplingSpanProcessor)
10701070
assert.Len(t, tsp.policies, 1)
1071+
assert.Equal(t, "extension", host.extension.policyName)
10711072
assert.Equal(t, map[string]any{"foo": "bar"}, host.extension.cfg)
10721073
}
10731074

@@ -1085,13 +1086,15 @@ func (h *extensionHost) GetExtensions() map[component.ID]component.Component {
10851086
}
10861087

10871088
type extension struct {
1088-
cfg map[string]any
1089+
policyName string
1090+
cfg map[string]any
10891091
}
10901092

10911093
var _ samplingpolicy.Extension = &extension{}
10921094

10931095
// NewEvaluator implements samplingpolicy.Extension.
1094-
func (e *extension) NewEvaluator(cfg map[string]any) (samplingpolicy.Evaluator, error) {
1096+
func (e *extension) NewEvaluator(policyName string, cfg map[string]any) (samplingpolicy.Evaluator, error) {
1097+
e.policyName = policyName
10951098
e.cfg = cfg
10961099
return nil, nil
10971100
}

0 commit comments

Comments
 (0)