Skip to content

Ensure RuleBasedRoutingSampler can use number valued attributes - #3073

Open
rmannibucau wants to merge 2 commits into
open-telemetry:mainfrom
rmannibucau:fix/RuleBasedRoutingSampler-on-number-attributes
Open

Ensure RuleBasedRoutingSampler can use number valued attributes#3073
rmannibucau wants to merge 2 commits into
open-telemetry:mainfrom
rmannibucau:fix/RuleBasedRoutingSampler-on-number-attributes

Conversation

@rmannibucau

Copy link
Copy Markdown

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

Copilot AI lite review requested due to automatic review settings August 25, 2026 17:14
@rmannibucau
rmannibucau requested a review from a team as a code owner August 25, 2026 17:14
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 25, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 only AttributeKey<String>.
  • Updated sampling evaluation to convert matched attribute values to String via String.valueOf(...) before regex matching.
  • Added unit tests validating drop / record-and-sample behavior for long attributes.

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) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants