opentelemetry-java
opentelemetry-java copied to clipboard
[incubator] ComposableProbabilitySampler does not validate ratio range
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 example2.0) computesMAX_THRESHOLD - Math.round(ratio * MAX_THRESHOLD)<0, which failsisValidThresholdinCompositeSamplerand silently drops all spans (0%sampling) instead of rejecting invalid input or clamping to1.0. - Passing
ratio < 0.0computes a threshold >MAX_THRESHOLD, which silently failsisValidThreshold(dropping all spans) and wraps the high bits inOtelTraceState.serializeTh(producing a misleadingthreshold=...ingetDescription(), e.g.,threshold=8forratio = -0.5). - Passing
Double.NaNevaluatesMath.round(NaN) == 0, silently producingMAX_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).
Hello @dashpole, could I get this issue assigned to me? Thanks.