Class TraceIdRatioBasedSampler
- java.lang.Object
-
- io.opentelemetry.sdk.trace.samplers.TraceIdRatioBasedSampler
-
- All Implemented Interfaces:
Sampler
@Immutable final class TraceIdRatioBasedSampler extends java.lang.Object implements 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
Fields Modifier and Type Field Description private java.lang.Stringdescriptionprivate longidUpperBoundprivate static SamplingResultNEGATIVE_SAMPLING_RESULTprivate static SamplingResultPOSITIVE_SAMPLING_RESULT
-
Constructor Summary
Constructors Constructor Description TraceIdRatioBasedSampler(double ratio, long idUpperBound)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static TraceIdRatioBasedSamplercreate(double ratio)private static java.lang.StringdecimalFormat(double value)booleanequals(java.lang.Object obj)java.lang.StringgetDescription()Returns the description of thisSampler.(package private) longgetIdUpperBound()private static longgetTraceIdRandomPart(java.lang.String traceId)inthashCode()SamplingResultshouldSample(Context parentContext, java.lang.String traceId, java.lang.String name, SpanKind spanKind, Attributes attributes, java.util.List<LinkData> parentLinks)Called duringSpancreation to make a sampling samplingResult.java.lang.StringtoString()
-
-
-
Field Detail
-
POSITIVE_SAMPLING_RESULT
private static final SamplingResult POSITIVE_SAMPLING_RESULT
-
NEGATIVE_SAMPLING_RESULT
private static final SamplingResult NEGATIVE_SAMPLING_RESULT
-
idUpperBound
private final long idUpperBound
-
description
private final java.lang.String description
-
-
Method Detail
-
create
static TraceIdRatioBasedSampler create(double ratio)
-
shouldSample
public SamplingResult shouldSample(Context parentContext, java.lang.String traceId, java.lang.String name, SpanKind spanKind, Attributes attributes, java.util.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
public java.lang.String 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
public boolean equals(@Nullable java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getIdUpperBound
long getIdUpperBound()
-
getTraceIdRandomPart
private static long getTraceIdRandomPart(java.lang.String traceId)
-
decimalFormat
private static java.lang.String decimalFormat(double value)
-
-