Deployment Integrations
On-premise Integrations
Platform Integrations

Sampling

You can reduce the amount of data that Java agent sends to Thundra Web Console by enabling sampling. You can add built-in sampling rules or provide a custom sampler (implement the sampling logic by yourself) for sampling Trace, Metric and/or Log data by Sampling API .

Sampling API

Sampler

Interface for implementations which decide whether or not sampling should be done. You can implement your own custom sampler by implementing io.thundra.agent.core.sample.Sampler interface where is the data (such as trace, metric or log but it can be any other data also depending on where sampler is using) to be used while making sampling decision.

Sampler
public interface Sampler<A> {
/**
* Checks whether or not sampling should be done.
*
* @param arg to be used for sampling decision
* @return <code>true</code> if sampling should be done,
* <code>false</code> otherwise
*/
boolean isSampled(A arg);
}

CountAwareSampler

Count based Sampler implementation which allows sampling for every specified count period.

Default count frequency is 100 and it can be configured by thundra_agent_sampler_countAware_countFreq environment variable.

For example, if the count frequency is 500, data will be sampled with every 500 Lambda invocation. Here is the configuration:

CountAwareSampler
import io.thundra.agent.core.sample.impl.CountAwareSampler;
...
// Sample for every 500 call
CountAwareSampler countAwareSampler = new CountAwareSampler(500);

TimeAwareSampler

Time based Sampler implementation which allows sampling for every specified time period.

Default time frequency is 300000 milliseconds (5 minutes) and it can be configured by thundra_agent_sampler_timeAware_timeFreq environment variable.

For example, if the time frequency is 60000, data will be sampled with every 60 seconds (10 minutes) within consecutive Lambda invocations. Here is the configuration:

TimeAwareSampler
import io.thundra.agent.core.sample.impl.TimeAwareSampler;
...
// Sample for every 60000 milliseconds (60 seconds = 1 minute)
TimeAwareSampler timeAwareSampler = new TimeAwareSampler(60000);

CompositeSampler

Sampler implementation which composes multiple Samplers by specified composition operation (AND or OR).

CompositeSampler
import io.thundra.agent.core.sample.impl.CountAwareSampler;
import io.thundra.agent.core.sample.impl.TimeAwareSampler;
import io.thundra.agent.core.sample.impl.CompositeSampler;
import static io.thundra.agent.core.sample.impl.CompositeSampler.SamplerCompositionOperator.OR;
...
CountAwareSampler countAwareSampler = new CountAwareSampler(500);
TimeAwareSampler timeAwareSampler = new TimeAwareSampler(1000);
// Sample at every 500 call or 60000 milliseconds (10 minutes), whichever comes first
CompositeSampler compositeSampler = new CompositeSampler(OR, countAwareSampler, timeAwareSampler);

Trace Sampling

Samplers can be set over setTraceSampler static method of io.thundra.agent.trace.TraceSupport class to be used for sampling of traces (spans).

Sampling Target

For tracing, sampling is only applied to the root span (not the other internal) of the invocation which represents the actual Lambda invocation. According to decision, if root span is sampled, all of the spans in the invocation are sampled.

DurationAwareThundraSpanSampler

Sampler implementation which samples Thundra spans if their durations in milliseconds are in the allowed side (greater than or not) according to given duration in milliseconds. For example, you want to send trace data only if the duration of the Lambda invocation is longer than 1 second (1000 milliseconds). Here is the configuration:

DurationAwareThundraSpanSampler
import io.thundra.agent.trace.sample.impl.DurationAwareThundraSpanSampler;
import io.thundra.agent.trace.TraceSupport;
...
// Sample only if the duration of the invocation (root span) is longer than 1 seconds
DurationAwareThundraSpanSampler durationAwareSampler =
new DurationAwareThundraSpanSampler(1000);
// Set sampler to be used for tracing
TraceSupport.setSampler(durationAwareSampler);

ErrorAwareThundraSpanSampler

Sampler implementation which samples Thundra spans if they are erroneous (tagged by error). For example, you want to send trace data only if Lambda execution fails with an error.

ErrorAwareThundraSpanSampler
import io.thundra.agent.trace.sample.impl.ErrorAwareThundraSpanSampler;
import io.thundra.agent.trace.TraceSupport;
...
// Sample only if the invocation (root span) fails with an error
ErrorAwareThundraSpanSampler errornAwareSampler =
new ErrorAwareThundraSpanSampler();
// Set sampler to be used for tracing
TraceSupport.setSampler(errornAwareSampler);

Metric Sampling

Samplers can be set over setMetricSampler static method of io.thundra.agent.metric.MetricSupport class to be used for sampling of metrics (stats).

Default Metric Sampling

By default, metrics are sampled every 100 invocation or 5 minutes whichever comes first. Default invocation count and time frequencies can be configured through thundra_agent_sampler_countAware_countFreq and thundra_agent_sampler_timeAware_timeFreq environment variables. Or you can set your custom sampler over MetricSampler as mentioned above.

Log Sampling

Samplers can be set over setLogSampler static method of io.thundra.agent.log.LogSupport class to be used for sampling of logs.