opentelemetry-java-contrib
opentelemetry-java-contrib copied to clipboard
Support 'and' in RuleBasedRoutingSampler (.drop)
Component(s)
samplers
Is your feature request related to a problem? Please describe.
Right now this sampler allows dropping based on a single attribute, like so: RuleBasedRoutingSampler.builder(SpanKind.SERVER, fallback) .drop(CODE_FUNCTION, "myAnnoyingMethod") .build());
In some cases, we would want to drop on a combination of attributes. E.g. "code.function" with "code.namespace" (from CodeAttributesExtractor).
As far as I can tell, this isn't possible with the current RuleBasedRoutingSampler.
Describe the solution you'd like
RuleBasedRoutingSampler allows dropping (or other rules/actions), based on a set of attributes.
Hopefully some nice fluent API could be created, but I'd be happy with just a few overloaded (2arg, 4 args, 6 args), so I can do: blabla.drop(CODE_FUNCTION, "myAnnoyingMethod", CODE_NAMESPACE, "myAnnoyingClass")
Describe alternatives you've considered
Writing my own custom Sampler, which gets ugly fast. Matching just one attribute, like code.function, and carefully making sure the same value is not used in another context.
Additional context
No response
hi @void-spark, this feature makes sense to me, if you want to propose a specific yaml syntax and API for it
Oh boy, the pressure :D
@trask I think it's good to keep the original working: RuleBasedRoutingSampler.builder(SpanKind.SERVER, fallback) .drop(CODE_FUNCTION, "myAnnoyingMethod") .build());
So we would want something in this direction: RuleBasedRoutingSampler.builder(SpanKind.SERVER, fallback) ... new stuff .build());
Is there a way to make this work? I guess you'd need a small internal object in the build to keep state, and throw IllegalStateExceptions if you say do a .thenDrop with no .when RuleBasedRoutingSampler.builder(SpanKind.SERVER, fallback) .when(CODE_FUNCTION, "myAnnoyingMethod") .and(CODE_NAMESPACE, "myAnnoyingClass") .thenDrop() .build());
I'm sure there's people far more experienced in this :)
Let's see, yaml... even less of an idea there, currently you have:
rules:
# Drop spans where url.path matches the regex /actuator.* (i.e. spring boot actuator endpoints).
- action: DROP
attribute: url.path
pattern: /actuator.*
I guess it could be something akin:
rules:
- action: DROP
conditions:
- attribute: myattr1
pattern: myvalue1
- attribute: myattr2
pattern: myvalue2
@void-spark The latest release https://github.com/open-telemetry/opentelemetry-java-contrib/releases/tag/v1.51.0 will bring a new CEL-Based sampler which gives you more filter capabilities.
The maven artefact can be found at https://central.sonatype.com/artifact/io.opentelemetry.contrib/opentelemetry-cel-sampler/overview
Could this be an alternative to your proposal?