opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

[incubator] ComposableProbabilitySampler does not validate ratio range

Open dashpole opened this issue 1 week ago • 2 comments

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).

dashpole avatar Nov 20 '26 20:11 dashpole

Hello @dashpole, could I get this issue assigned to me? Thanks.

eminfikret avatar Nov 21 '26 15:11 eminfikret

Hello @dashpole, could I get this issue assigned to me? Thanks.

done

jkwatson avatar Nov 22 '26 04:11 jkwatson