open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
2.9k stars 2.27k forks source link

[processor/tailsampling] numeric attribute invert match evaluation not prioritized #34296

Open hyang023 opened 1 month ago

hyang023 commented 1 month ago

Component(s)

processor/tailsampling

What happened?

Description

as described in the tail sampling processor readme (https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/tailsamplingprocessor),

When there's an "inverted not sample" decision, the trace is not sampled;

this functionality does not work for numeric attribute policies because its Evaluate function only returns Sampled or NotSampled values not InvertNotSampled or InvertSampled even if invertMatch is true

The Evaluate function in https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/tailsamplingprocessor/internal/sampling/numeric_tag_filter.go#L37 needs to be updated so that it can return InvertNotSampled or InvertSampled when appropriate

This would likely require the addition of an invertHasSpanWithCondition in https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/tailsamplingprocessor/internal/sampling/util.go and then calling it from https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/tailsamplingprocessor/internal/sampling/numeric_tag_filter.go if invertMatch is true

Steps to Reproduce

Expected Result

Actual Result

Collector version

v0.105.0 but previous versions would also be affected

Environment information

Environment

this is not environment specific

OpenTelemetry Collector configuration

No response

Log output

No response

Additional context

No response

github-actions[bot] commented 1 month ago

Pinging code owners:

bacherfl commented 1 month ago

I'd be happy to look into this and work on a fix

bacherfl commented 1 month ago

After looking into this, I have two questions related to the policy evaluators:

  1. While the string tag filter checks both the resource and the span attributes (see https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/23de1761434a8d069362cd233cbbbc77725def19/processor/tailsamplingprocessor/internal/sampling/string_tag_filter.go#L102), the numeric filter only considers span attributes, but no resource attributes (see https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/23de1761434a8d069362cd233cbbbc77725def19/processor/tailsamplingprocessor/internal/sampling/numeric_tag_filter.go#L42) - Is this intended, or should the numeric tag filter also take attributes of the resource into account?
  2. Currently, the boolean tag filter seems to not support the inverse_match option at all (see https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/tailsamplingprocessor/internal/sampling/boolean_tag_filter.go) - Should that filter be extended to also suppport this option, or is there a reason to not include this option here? I guess this would need to be addressed in a separate PR as it's not directly related to this issue, but if needed I can also work on this
jpkrohling commented 1 month ago

Is this intended, or should the numeric tag filter also take attributes of the resource into account?

Probably just an oversight/bug.

is there a reason to not include this option here

The invert match was added originally for the string only. In the name of consistency, it would be good to have it for all types though.

bacherfl commented 1 month ago

Is this intended, or should the numeric tag filter also take attributes of the resource into account?

Probably just an oversight/bug.

is there a reason to not include this option here

The invert match was added originally for the string only. In the name of consistency, it would be good to have it for all types though.

Thanks @jpkrohling - In this case I will also consider the resource attributes in the numeric filter and for the boolean filter I would create a separate PR to also support the inverse option there