Package org.microproxy.otel
Interface Sampler
public interface Sampler
Decides whether a new trace, or the proxy's part of a trace that came with the request, is
sampled: recorded and exported. The samplers are OpenTelemetry's, by the names
OTEL_TRACES_SAMPLER gives them: always_on, always_off, traceidratio
and the parentbased_* ones, which follow a sampled flag that came with the request and
ask their root sampler only for new traces.-
Method Summary
Modifier and TypeMethodDescriptionstatic SamplerReturns a sampler that samples nothing.static SampleralwaysOn()Returns a sampler that samples everything.Returns a description, such asParentBased{root:TraceIdRatioBased{0.25}}.static SamplerThe samplerOTEL_TRACES_SAMPLERandOTEL_TRACES_SAMPLER_ARGname:always_on,always_off,traceidratio,parentbased_always_on(the default),parentbased_always_offorparentbased_traceidratio; the ratio is the argument, 1 when there is none.static SamplerparentBased(Sampler root) A sampler that follows the request's sampled flag when it came with a trace context, and asksroototherwise.booleanshouldSample(SpanContext parent, long traceIdHigh, long traceIdLow) Decides.static SamplertraceIdRatio(double ratio) A sampler that samples a fraction of traces, decided by the trace id alone, so every process of a trace decides the same: the last 8 bytes of the id, as a signed number, are compared withratiotimesLong.MAX_VALUE, as OpenTelemetry's Java SDK does.
-
Method Details
-
shouldSample
Decides.- Parameters:
parent- the context that came with the request, ornullfor a new tracetraceIdHigh- the trace id's first 8 bytestraceIdLow- the trace id's last 8 bytes, whichtraceIdRatio(double)decides by- Returns:
- whether to sample
-
description
String description()Returns a description, such asParentBased{root:TraceIdRatioBased{0.25}}.- Returns:
- a description, such as
ParentBased{root:TraceIdRatioBased{0.25}}
-
alwaysOn
Returns a sampler that samples everything.- Returns:
- a sampler that samples everything
-
alwaysOff
Returns a sampler that samples nothing.- Returns:
- a sampler that samples nothing
-
traceIdRatio
A sampler that samples a fraction of traces, decided by the trace id alone, so every process of a trace decides the same: the last 8 bytes of the id, as a signed number, are compared withratiotimesLong.MAX_VALUE, as OpenTelemetry's Java SDK does.- Parameters:
ratio- the fraction, from 0 to 1- Returns:
- the sampler
- Throws:
IllegalArgumentException- ifratiois not in [0, 1]
-
parentBased
A sampler that follows the request's sampled flag when it came with a trace context, and asksroototherwise.- Parameters:
root- the sampler of new traces- Returns:
- the sampler
-
of
The samplerOTEL_TRACES_SAMPLERandOTEL_TRACES_SAMPLER_ARGname:always_on,always_off,traceidratio,parentbased_always_on(the default),parentbased_always_offorparentbased_traceidratio; the ratio is the argument, 1 when there is none.- Parameters:
name- the sampler's name, ornullfor the defaultarg- the argument, ornull- Returns:
- the sampler
- Throws:
IllegalArgumentException- for an unknown name or a bad ratio
-