Add incubator ComposableRuleBasedSampler#7787
Conversation
| this.rules = rules.toArray(new SamplingRule[0]); | ||
|
|
||
| StringBuilder description = new StringBuilder("ComposableRuleBasedSampler{["); | ||
| if (this.rules.length > 0) { |
There was a problem hiding this comment.
I considered whether empty should be an error, but I could conceive of cases that update the rules dynamically in a sort of "default-to-deny-all, sometimes accept something" type of situation. If making empty an error, that's still implementable though with an explicit catch-all and drop rule, so open to thoughts.
There was a problem hiding this comment.
Will go with it for now but realized that this is probably something to just confirm on the spec
| import java.util.List; | ||
|
|
||
| /** A builder for a composable rule-based sampler. */ | ||
| public final class ComposableRuleBasedSamplerBuilder { |
There was a problem hiding this comment.
This is just an initial implementation. Presumably this should have at least a few helpers on it, addAttributePattern for example
| * Returns a description of the {@link SamplingPredicate}. This may be displayed on debug pages or | ||
| * in the logs. | ||
| */ | ||
| String getDescription(); |
There was a problem hiding this comment.
Thought long on whether this should be a FunctionalInterface, but I felt just like Sampler, this is too important to not require
There was a problem hiding this comment.
What are you thoughts on Sampler#getDescription() and this? I've always seen Sampler#getDescription() and thought it unnecessary because:
- Its not used anywhere in the SDK
- Its just like Object#toString(), but you're forced to implement it
Maybe the point you're making is that its important to have a human readable description of the sampler for things like OpenTelemetrySdk#toString(), and so its good to force sampler to print a description?
If so, I don't necessarily disagree, but then I would have liked to have getDescription() on all SDK plugin interfaces (i.e. SpanExporter, SpanProcessor, etc).
There was a problem hiding this comment.
Yeah it's a good point that with discipline, it's enough to implement toString sensibly at least in the SDK implementations, that was generally the case in zipkin. I can imagine a world without Sampler#getDescription() working out fine. But that isn't the world - for this, it feels to me we can't implement Sampler#getDescription() properly without ensuring predicates do the same. We could still suggest strongly to implement toString for use there if it seems better though.
There was a problem hiding this comment.
Yeah I've definitely run into that problem with OpenTelemetrySdk#toString() having sub-optimal results unless every sub-component follows the convention of a useful toString() implementation. In retrospect I wish we would have had getDescription be required on all SDK extension plugin interfaces.
I don't have a strong opinion here. I lean slightly towards relying on toString() because we missed the boat on getDescription() elsewhere, but don't feel strongly. Requiring getDescription will improve the string output for this narrow part of the codebase, which is worth something.
There was a problem hiding this comment.
Sounds good, I removed getDescription - always good to err on the side of less API. I added a javadoc strongly recommending toString instead.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7787 +/- ##
=========================================
Coverage 90.17% 90.17%
- Complexity 7189 7216 +27
=========================================
Files 814 819 +5
Lines 21730 21767 +37
Branches 2129 2133 +4
=========================================
+ Hits 19594 19629 +35
- Misses 1467 1468 +1
- Partials 669 670 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Best way for these to be usable in the agent is to drive the declarative configuration implementation of this, which includes:
At that point, users would be able to define complex composable samplers in YAML and use them in the agent without an agent extension. |
|
Thanks @jack-berg - agree that it sounds like a good idea to get new samplers into configuration. I raised some PR/issues there to see if we can move forward. At the same time, I guess we can get this in to have the SDK side moving as well. |
jack-berg
left a comment
There was a problem hiding this comment.
Couple minor comments but looks good overall. Thanks!
| import java.util.List; | ||
|
|
||
| /** A predicate for a composable sampler, indicating whether a set of sampling arguments matches. */ | ||
| public interface SamplingPredicate { |
There was a problem hiding this comment.
The spec seems incomplete in that it lists a rule as a predicate, ComposableSampler pair, but fails to describe what parameters the predicate can operate on. I think including all the parameters of ComposableSampler#getSamplingINtent is the natural choice.
| * Returns a description of the {@link SamplingPredicate}. This may be displayed on debug pages or | ||
| * in the logs. | ||
| */ | ||
| String getDescription(); |
There was a problem hiding this comment.
What are you thoughts on Sampler#getDescription() and this? I've always seen Sampler#getDescription() and thought it unnecessary because:
- Its not used anywhere in the SDK
- Its just like Object#toString(), but you're forced to implement it
Maybe the point you're making is that its important to have a human readable description of the sampler for things like OpenTelemetrySdk#toString(), and so its good to force sampler to print a description?
If so, I don't necessarily disagree, but then I would have liked to have getDescription() on all SDK plugin interfaces (i.e. SpanExporter, SpanProcessor, etc).
anuraaga
left a comment
There was a problem hiding this comment.
Thanks @jack-berg sorry for the delay
| * Returns a description of the {@link SamplingPredicate}. This may be displayed on debug pages or | ||
| * in the logs. | ||
| */ | ||
| String getDescription(); |
There was a problem hiding this comment.
Yeah it's a good point that with discipline, it's enough to implement toString sensibly at least in the SDK implementations, that was generally the case in zipkin. I can imagine a world without Sampler#getDescription() working out fine. But that isn't the world - for this, it feels to me we can't implement Sampler#getDescription() properly without ensuring predicates do the same. We could still suggest strongly to implement toString for use there if it seems better though.
| this.rules = rules.toArray(new SamplingRule[0]); | ||
|
|
||
| StringBuilder description = new StringBuilder("ComposableRuleBasedSampler{["); | ||
| if (this.rules.length > 0) { |
There was a problem hiding this comment.
Will go with it for now but realized that this is probably something to just confirm on the spec
jack-berg
left a comment
There was a problem hiding this comment.
Let me know where you land on getDescription(). I'm happy to merge either way.
Thanks!
Previous PRs have focused on the composable versions of existing samplers. This adds one of the new ones,
ComposableRuleBased.https://opentelemetry.io/docs/specs/otel/trace/sdk/#composablerulebased
Though technically a similar one has been in contrib for a while - IIUC, the agent uses it now adays so would be good to confirm the general usability from a javaagent perspective too /cc @jaydeluca