Class TraceIdRatioBasedSampler
java.lang.Object
io.opentelemetry.sdk.trace.samplers.TraceIdRatioBasedSampler
- All Implemented Interfaces:
Sampler
We assume the lower 64 bits of the traceId's are randomly distributed around the whole (long)
range. We convert an incoming probability into an upper bound on that value, such that we can
just compare the absolute value of the id and the bound to see if we are within the desired
probability range. Using the low bits of the traceId also ensures that systems that only use 64
bit ID's will also work with this sampler.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stringprivate final longprivate static final SamplingResultprivate static final SamplingResult -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static TraceIdRatioBasedSamplercreate(double ratio) private static StringdecimalFormat(double value) booleanReturns the description of thisSampler.(package private) longprivate static longgetTraceIdRandomPart(String traceId) inthashCode()shouldSample(Context parentContext, String traceId, String name, SpanKind spanKind, Attributes attributes, List<LinkData> parentLinks) Called duringSpancreation to make a sampling samplingResult.toString()
-
Field Details
-
POSITIVE_SAMPLING_RESULT
-
NEGATIVE_SAMPLING_RESULT
-
idUpperBound
private final long idUpperBound -
description
-
-
Constructor Details
-
TraceIdRatioBasedSampler
TraceIdRatioBasedSampler(double ratio, long idUpperBound)
-
-
Method Details
-
create
-
shouldSample
public SamplingResult shouldSample(Context parentContext, String traceId, String name, SpanKind spanKind, Attributes attributes, List<LinkData> parentLinks) Description copied from interface:SamplerCalled duringSpancreation to make a sampling samplingResult.- Specified by:
shouldSamplein interfaceSampler- Parameters:
parentContext- the parent span'sSpanContext. This can beSpanContext.INVALIDif this is a root span.traceId- theTraceIdfor the newSpan. This will be identical to that in the parentContext, unless this is a root span.name- the name of the newSpan.spanKind- theSpanKindof theSpan.attributes-Attributesassociated with the span.parentLinks- the parentLinks associated with the newSpan.- Returns:
- sampling samplingResult whether span should be sampled or not.
-
getDescription
Description copied from interface:SamplerReturns the description of thisSampler. This may be displayed on debug pages or in the logs.Example: "TraceIdRatioBased{0.000100}"
- Specified by:
getDescriptionin interfaceSampler- Returns:
- the description of this
Sampler.
-
equals
-
hashCode
public int hashCode() -
toString
-
getIdUpperBound
long getIdUpperBound() -
getTraceIdRandomPart
-
decimalFormat
-