Class ProbabilitySampler
java.lang.Object
io.opencensus.trace.Sampler
io.opencensus.trace.samplers.ProbabilitySampler
- Direct Known Subclasses:
AutoValue_ProbabilitySampler
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static ProbabilitySamplercreate(double probability) Returns a newProbabilitySampler.final StringReturns the description of thisSampler.(package private) abstract long(package private) abstract doublefinal booleanshouldSample(SpanContext parentContext, Boolean hasRemoteParent, TraceId traceId, SpanId spanId, String name, List<Span> parentLinks) Called duringSpancreation to make a sampling decision.
-
Constructor Details
-
ProbabilitySampler
ProbabilitySampler()
-
-
Method Details
-
getProbability
abstract double getProbability() -
getIdUpperBound
abstract long getIdUpperBound() -
create
Returns a newProbabilitySampler. The probability of sampling a trace is equal to that of the specified probability.- Parameters:
probability- The desired probability of sampling. Must be within [0.0, 1.0].- Returns:
- a new
ProbabilitySampler. - Throws:
IllegalArgumentException- ifprobabilityis out of range
-
shouldSample
public final boolean shouldSample(@Nullable SpanContext parentContext, @Nullable Boolean hasRemoteParent, TraceId traceId, SpanId spanId, String name, @Nullable List<Span> parentLinks) Description copied from class:SamplerCalled duringSpancreation to make a sampling decision.- Specified by:
shouldSamplein classSampler- Parameters:
parentContext- the parent span'sSpanContext.nullif this is a root span.hasRemoteParent-trueif the parentSpanis remote.nullif this is a root span.traceId- theTraceIdfor the newSpan. This will be identical to that in the parentContext, unless this is a root span.spanId- theSpanIdfor the newSpan.name- the name of the newSpan.parentLinks- the parentLinks associated with the newSpan.- Returns:
trueif theSpanis sampled.
-
getDescription
Description copied from class:SamplerReturns the description of thisSampler. This may be displayed on debug pages or in the logs.Example: "ProbabilitySampler{0.000100}"
- Specified by:
getDescriptionin classSampler- Returns:
- the description of this
Sampler.
-