Class ExemplarSampler
There are two types of Exemplars: Regular exemplars are sampled implicitly if a supported tracing library is detected. Custom exemplars are provided explicitly in code, for example if a developer wants to make sure an Exemplar is created for a specific code path.
Spans will be marked as being an Exemplar by calling SpanContext.markCurrentSpanAsExemplar(). The tracer implementation should set a Span attribute
to mark the current Span as an Exemplar. This attribute can be used by a trace sampling algorithm
to make sure traces with Exemplars are sampled.
The ExemplarSample is rate-limited, so only a small fraction of Spans will be marked as Exemplars in an application with a large number of requests.
See ExemplarSamplerConfig for configuration options.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBooleanprivate final AtomicBooleanprivate final ExemplarSamplerConfigprivate final Exemplar[]private final Exemplar[]private final SpanContext -
Constructor Summary
ConstructorsConstructorDescriptionExemplarSampler(ExemplarSamplerConfig config) ExemplarSampler(ExemplarSamplerConfig config, SpanContext spanContext) Constructor with an additional {code spanContext} argument. -
Method Summary
Modifier and TypeMethodDescriptioncollect()private longdoObserve(double value) private longdoObserveSingleExemplar(double value) private longdoObserveSingleExemplar(double amount, Labels labels) private longdoObserveWithExemplar(double amount, Labels labels) private longdoObserveWithExemplarWithoutUpperBounds(double amount, Labels labels) private longdoObserveWithExemplarWithUpperBounds(double value, Labels labels, double[] classicUpperBounds) private longdoObserveWithoutUpperBounds(double value) private longdoObserveWithUpperBounds(double value, double[] classicUpperBounds) private Labelsprivate longdurationUntilNextExemplarExpires(long now) private static SpanContextvoidobserve(double value) voidobserveWithExemplar(double value, Labels labels) private voidrateLimitedObserve(AtomicBoolean accepting, double value, LongSupplier observeFunc) Observing requires a system call toSystem.currentTimeMillis(), and it requires iterating over the existing exemplars to check if one of the existing exemplars can be replaced.voidreset()private longupdateCustomExemplar(int index, double value, Labels labels, long now) private longupdateExemplar(int index, double value, long now)
-
Field Details
-
config
-
exemplars
-
customExemplars
-
acceptingNewExemplars
-
acceptingNewCustomExemplars
-
spanContext
-
-
Constructor Details
-
ExemplarSampler
-
ExemplarSampler
Constructor with an additional {code spanContext} argument. This is useful for testing, but may also be useful in some production scenarios. IfspanContext != nullthat spanContext is used andSpanContextSupplieris not used. IfspanContext == nullSpanContextSupplier.getSpanContext()is called to find a span context.
-
-
Method Details
-
collect
-
reset
public void reset() -
observe
public void observe(double value) -
observeWithExemplar
-
doObserve
private long doObserve(double value) -
doObserveSingleExemplar
private long doObserveSingleExemplar(double value) -
doObserveSingleExemplar
-
doObserveWithUpperBounds
private long doObserveWithUpperBounds(double value, double[] classicUpperBounds) -
doObserveWithoutUpperBounds
private long doObserveWithoutUpperBounds(double value) -
doObserveWithExemplar
-
doObserveWithExemplarWithUpperBounds
private long doObserveWithExemplarWithUpperBounds(double value, Labels labels, double[] classicUpperBounds) -
doObserveWithExemplarWithoutUpperBounds
-
rateLimitedObserve
Observing requires a system call toSystem.currentTimeMillis(), and it requires iterating over the existing exemplars to check if one of the existing exemplars can be replaced.To avoid performance issues, we rate limit observing exemplars to
ExemplarSamplerConfig.getSampleIntervalMillis()milliseconds. -
durationUntilNextExemplarExpires
private long durationUntilNextExemplarExpires(long now) -
updateCustomExemplar
-
updateExemplar
private long updateExemplar(int index, double value, long now) -
doSampleExemplar
-
getSpanContextFromInitializer
-