Package io.opencensus.trace.samplers
Class ProbabilitySampler
- java.lang.Object
-
- io.opencensus.trace.Sampler
-
- io.opencensus.trace.samplers.ProbabilitySampler
-
- Direct Known Subclasses:
AutoValue_ProbabilitySampler
@Immutable abstract class ProbabilitySampler extends 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.
-
-
Constructor Summary
Constructors Constructor Description ProbabilitySampler()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) static ProbabilitySampler
create(double probability)
Returns a newProbabilitySampler
.java.lang.String
getDescription()
Returns the description of thisSampler
.(package private) abstract long
getIdUpperBound()
(package private) abstract double
getProbability()
boolean
shouldSample(SpanContext parentContext, java.lang.Boolean hasRemoteParent, TraceId traceId, SpanId spanId, java.lang.String name, java.util.List<Span> parentLinks)
Called duringSpan
creation to make a sampling decision.
-
-
-
Method Detail
-
getProbability
abstract double getProbability()
-
getIdUpperBound
abstract long getIdUpperBound()
-
create
static ProbabilitySampler create(double probability)
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:
java.lang.IllegalArgumentException
- ifprobability
is out of range
-
shouldSample
public final boolean shouldSample(@Nullable SpanContext parentContext, @Nullable java.lang.Boolean hasRemoteParent, TraceId traceId, SpanId spanId, java.lang.String name, @Nullable java.util.List<Span> parentLinks)
Description copied from class:Sampler
Called duringSpan
creation to make a sampling decision.- Specified by:
shouldSample
in classSampler
- Parameters:
parentContext
- the parent span'sSpanContext
.null
if this is a root span.hasRemoteParent
-true
if the parentSpan
is remote.null
if this is a root span.traceId
- theTraceId
for the newSpan
. This will be identical to that in the parentContext, unless this is a root span.spanId
- theSpanId
for the newSpan
.name
- the name of the newSpan
.parentLinks
- the parentLinks associated with the newSpan
.- Returns:
true
if theSpan
is sampled.
-
getDescription
public final java.lang.String getDescription()
Description copied from class:Sampler
Returns the description of thisSampler
. This may be displayed on debug pages or in the logs.Example: "ProbabilitySampler{0.000100}"
- Specified by:
getDescription
in classSampler
- Returns:
- the description of this
Sampler
.
-
-