[incubator] ComposableProbabilitySampler does not validate ratio range

Open Beginner friendly
#9,046 2 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 3 days

@eminfikret is already working on this.

Since Nov 22, 2026.

  • #9056 by @eminfikret — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
observability

Research direction

Start with ComposableSampler.probability(double) and ComposableProbabilitySampler.java in sdk-extensions/incubator, where the threshold is computed from ratio. Follow the value into CompositeSampler.isValidThreshold and OtelTraceState.serializeTh to confirm why out-of-range and NaN inputs silently fall back to always-off. Done means probability rejects ratio < 0.0, ratio > 1.0 and NaN with IllegalArgumentException, mirroring Sampler.traceIdRatioBased, covered by tests in the incubator sampler test sources.

Written by the indexing model from the issue text.

Description

Problem

During a cross-implementation audit against the OpenTelemetry probability sampling specification (open-telemetry/opentelemetry-specification#5440), ComposableProbabilitySampler.java and ComposableSampler.probability(double) do not validate ratio:

  • Passing ratio > 1.0 (for example 2.0) computes MAX_THRESHOLD - Math.round(ratio * MAX_THRESHOLD) < 0, which fails isValidThreshold in CompositeSampler and silently drops all spans (0% sampling) instead of rejecting invalid input or clamping to 1.0.
  • Passing ratio < 0.0 computes a threshold > MAX_THRESHOLD, which silently fails isValidThreshold (dropping all spans) and wraps the high bits in OtelTraceState.serializeTh (producing a misleading threshold=... in getDescription(), e.g., threshold=8 for ratio = -0.5).
  • Passing Double.NaN evaluates Math.round(NaN) == 0, silently producing MAX_THRESHOLD (always off) with no error.
Expected Behavior

Validate ratio in ComposableSampler.probability(double) / ComposableProbabilitySampler (throwing IllegalArgumentException when ratio < 0.0 || ratio > 1.0 || Double.isNaN(ratio), extending Sampler.traceIdRatioBased's [0.0, 1.0] check to also reject NaN).

Dominant language
Java
Stars
2.5k
Forks
1.1k
Avg merge
5d 11h
Merged PRs (30d)
41

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from open-telemetry/opentelemetry-java

All issues in open-telemetry/opentelemetry-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.