Interface Sampler
-
- All Known Implementing Classes:
ParentBasedSampler
@ThreadSafe public interface Sampler
Sampler is used to make decisions onSpan
sampling.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static Sampler
alwaysOff()
static Sampler
alwaysOn()
String
getDescription()
Returns the description of thisSampler
.static Sampler
parentBased(Sampler root)
Returns aSampler
that always makes the same decision as the parentSpan
to whether or not to sample.static ParentBasedSampler.Builder
parentBasedBuilder(Sampler root)
Returns aParentBasedSampler.Builder
that follows the parent's sampling decision if one exists, otherwise following the root sampler and other optional sampler's decision.SamplingResult
shouldSample(io.opentelemetry.context.Context parentContext, String traceId, String name, io.opentelemetry.api.trace.Span.Kind spanKind, io.opentelemetry.api.common.Attributes attributes, List<SpanData.Link> parentLinks)
Called duringSpan
creation to make a sampling samplingResult.static Sampler
traceIdRatioBased(double ratio)
Returns a new TraceIdRatioBasedSampler
.
-
-
-
Method Detail
-
alwaysOn
static Sampler alwaysOn()
- Returns:
- a
Sampler
that always makes a "yes"SamplingResult
forSpan
sampling.
-
alwaysOff
static Sampler alwaysOff()
- Returns:
- a
Sampler
that always makes a "no"SamplingResult
forSpan
sampling.
-
parentBased
static Sampler parentBased(Sampler root)
Returns aSampler
that always makes the same decision as the parentSpan
to whether or not to sample. If there is no parent, the Sampler uses the provided Sampler delegate to determine the sampling decision.- Parameters:
root
- theSampler
which is used to make the sampling decisions if the parent does not exist.- Returns:
- a
Sampler
that follows the parent's sampling decision if one exists, otherwise following the root sampler's decision.
-
parentBasedBuilder
static ParentBasedSampler.Builder parentBasedBuilder(Sampler root)
Returns aParentBasedSampler.Builder
that follows the parent's sampling decision if one exists, otherwise following the root sampler and other optional sampler's decision.- Parameters:
root
- the requiredSampler
which is used to make the sampling decisions if the parent does not exist.- Returns:
- a
ParentBased.Builder
-
traceIdRatioBased
static Sampler traceIdRatioBased(double ratio)
Returns a new TraceIdRatioBasedSampler
. The ratio of sampling a trace is equal to that of the specified ratio.- Parameters:
ratio
- The desired ratio of sampling. Must be within [0.0, 1.0].- Returns:
- a new TraceIdRatioBased
Sampler
. - Throws:
IllegalArgumentException
- ifratio
is out of range
-
shouldSample
SamplingResult shouldSample(io.opentelemetry.context.Context parentContext, String traceId, String name, io.opentelemetry.api.trace.Span.Kind spanKind, io.opentelemetry.api.common.Attributes attributes, List<SpanData.Link> parentLinks)
Called duringSpan
creation to make a sampling samplingResult.- Parameters:
parentContext
- the parent span'sSpanContext
. This can beSpanContext.INVALID
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.name
- the name of the newSpan
.spanKind
- theSpan.Kind
of theSpan
.attributes
-Attributes
associated with the span.parentLinks
- the parentLinks associated with the newSpan
.- Returns:
- sampling samplingResult whether span should be sampled or not.
-
getDescription
String getDescription()
Returns the description of thisSampler
. This may be displayed on debug pages or in the logs.Example: "TraceIdRatioBased{0.000100}"
- Returns:
- the description of this
Sampler
.
-
-