Ensure RuleBasedRoutingSampler can use number valued attributes - #3073
Open
rmannibucau wants to merge 2 commits into
Open
Ensure RuleBasedRoutingSampler can use number valued attributes#3073rmannibucau wants to merge 2 commits into
rmannibucau wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR updates RuleBasedRoutingSampler to support routing rules based on non-string attribute values (e.g., numeric attributes like server port / HTTP status code) by stringifying the attribute value before applying the regex.
Changes:
- Broadened rule builder APIs to accept
AttributeKey<?>instead of onlyAttributeKey<String>. - Updated sampling evaluation to convert matched attribute values to
StringviaString.valueOf(...)before regex matching. - Added unit tests validating drop / record-and-sample behavior for
longattributes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| samplers/src/main/java/io/opentelemetry/contrib/sampler/SamplingRule.java | Stores generalized attribute keys (AttributeKey<?>) for rules. |
| samplers/src/main/java/io/opentelemetry/contrib/sampler/RuleBasedRoutingSamplerBuilder.java | Broadens builder methods to accept non-string attribute keys. |
| samplers/src/main/java/io/opentelemetry/contrib/sampler/RuleBasedRoutingSampler.java | Stringifies attribute values prior to regex matching. |
| samplers/src/test/java/io/opentelemetry/contrib/sampler/RuleBasedRoutingSamplerTest.java | Adds coverage for long-valued attributes in routing rules. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
69
to
74
| if (samplingRule.attributeKey.getKey().equals(THREAD_NAME.getKey())) { | ||
| attributeValue = Thread.currentThread().getName(); | ||
| } else { | ||
| attributeValue = attributes.get(samplingRule.attributeKey); | ||
| Object value = attributes.get(samplingRule.attributeKey); | ||
| attributeValue = value == null ? null : String.valueOf(value); | ||
| } |
| */ | ||
| @CanIgnoreReturnValue | ||
| public RuleBasedRoutingSamplerBuilder drop(AttributeKey<String> attributeKey, String pattern) { | ||
| public RuleBasedRoutingSamplerBuilder drop(AttributeKey<?> attributeKey, String pattern) { |
| @CanIgnoreReturnValue | ||
| public RuleBasedRoutingSamplerBuilder customize( | ||
| AttributeKey<String> attributeKey, String pattern, Sampler sampler) { | ||
| AttributeKey<?> attributeKey, String pattern, Sampler sampler) { |
| @CanIgnoreReturnValue | ||
| public RuleBasedRoutingSamplerBuilder recordAndSample( | ||
| AttributeKey<String> attributeKey, String pattern) { | ||
| AttributeKey<?> attributeKey, String pattern) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
Trying to use declarative configuration to remove spans on spring boot management server using port filtering it fails cause value is not a string.
Existing Issue(s):
Testing:
mainly unit tests