Class DeclarativeSampler<M>
- Type Parameters:
M- The type that uniquely identifies this method, specifically for tracing. Most often a trace annotation, but could also be aMethodor another declarative reference such asjavax.ws.rs.container.ResourceInfo.
- All Implemented Interfaces:
SamplerFunction<M>
public abstract class DeclarativeSampler<M> extends Object implements SamplerFunction<M>
Example: A user defines an annotation, for example com.myco.Traced, and a lookup
function for its rate (could be simple as reading a field, or even a constant). An interceptor
uses this sampler on each invocation of a potentially annotated target. The result decides
whether a new trace should be started or not.
No runtime parameters are considered here, but that doesn't mean you can't achieve
parameterized sampling using this. If your method is annotated such that it only accepts a
fraction of requests, adding a custom @Traced annotation would apply to that subset. For
example, if you have a JAX-RS method, it is already qualified by method and likely path. A user
can add and inspect their own grouping annotation to override whatever the default rate is.
Under the scenes, a map of samplers by method is maintained. The size of this map should not be a problem when it directly relates to declared methods. For example, this would be invalid if annotations were created at runtime and didn't match.
- Since:
- 4.4
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceDeclarativeSampler.ProbabilityOfMethod<M>static interfaceDeclarativeSampler.RateForMethod<M>Deprecated.since 5.8, useDeclarativeSampler.ProbabilityOfMethodstatic interfaceDeclarativeSampler.RateOfMethod<M> -
Method Summary
Modifier and Type Method Description static <M> DeclarativeSampler<M>create(DeclarativeSampler.RateForMethod<M> rateForMethod)Deprecated.since 5.8, usecreateWithProbability(ProbabilityOfMethod)static <M> DeclarativeSampler<M>createWithProbability(DeclarativeSampler.ProbabilityOfMethod<M> probabilityOfMethod)static <M> DeclarativeSampler<M>createWithRate(DeclarativeSampler.RateOfMethod<M> rateOfMethod)SamplingFlagssample(M method)Deprecated.Since 5.8, usetrySample(Object)SamplertoSampler(M method)Deprecated.Since 5.8, useTracer.startScopedSpan(String, SamplerFunction, Object)SamplertoSampler(M method, Sampler fallback)Deprecated.Since 5.8, useTracer.startScopedSpan(String, SamplerFunction, Object)BooleantrySample(M method)Returns an overriding sampling decision for a new trace.
-
Method Details
-
createWithProbability
public static <M> DeclarativeSampler<M> createWithProbability(DeclarativeSampler.ProbabilityOfMethod<M> probabilityOfMethod) -
createWithRate
public static <M> DeclarativeSampler<M> createWithRate(DeclarativeSampler.RateOfMethod<M> rateOfMethod) -
trySample
Returns an overriding sampling decision for a new trace. Returning null is typically used to defer to thetrace ID sampler.- Specified by:
trySamplein interfaceSamplerFunction<M>- Parameters:
method- parameter to evaluate for a sampling decision. null input results in a null result- Returns:
- true to sample a new trace or false to deny. Null defers the decision.
- Since:
- 5.8
-
create
Deprecated.since 5.8, usecreateWithProbability(ProbabilityOfMethod)- Since:
- 4.4
-
toSampler
Deprecated.Since 5.8, useTracer.startScopedSpan(String, SamplerFunction, Object)- Since:
- 4.4
-
toSampler
Deprecated.Since 5.8, useTracer.startScopedSpan(String, SamplerFunction, Object)- Since:
- 4.19
-
sample
Deprecated.Since 5.8, usetrySample(Object)- Since:
- 4.4
-