Thundra APM
Search…
Deployment Integrations
Powered By GitBook
Sampling in Go SDK
You can reduce the amount of data that the Go agent sends to the Thundra web console by enabling sampling. You can either add built-in sampling rules to the metric and trace plugin or provide a custom sampler and implement the sampling logic by yourself. Do note, however, that you can only sample timed-out invocations.

Count Aware Sampler

The Count Aware Sampler enables you to sample data with a count frequency. For example, if the count frequency is set to 50, metric data will be sampled after every 50 Lambda invocations. The configuration is shown below:
Programmatic Configuration of CountAwareSampler
1
import(
2
"github.com/thundra-io/thundra-lambda-agent-go/samplers"
3
"github.com/thundra-io/thundra-lambda-agent-go/metric"
4
"github.com/thundra-io/thundra-lambda-agent-go/log"
5
"github.com/thundra-io/thundra-lambda-agent-go/trace"
6
)
7
8
cas := NewCountAwareSampler(5) // Sample data every 5th invocation
9
log.SetSampler(cas) // Sample log data
10
metric.SetSampler(cas) // Sample metric data
11
trace.SetSampler(cas) // Sample trace data
Copied!

Time Aware Sampler

The Time Aware Sampler enables you to sample data with a time frequency. For example, if the time frequency is set to 300,000, metric data will be sampled every 300 seconds within consecutive Lambda invocations. The configuration is shown below:
Programmatic Configuration of TimeAwareSampler
1
import(
2
"github.com/thundra-io/thundra-lambda-agent-go/samplers"
3
"github.com/thundra-io/thundra-lambda-agent-go/metric"
4
"github.com/thundra-io/thundra-lambda-agent-go/log"
5
"github.com/thundra-io/thundra-lambda-agent-go/trace"
6
)
7
8
tas := samplers.NewTimeAwareSampler(1000) // Sample for every 1000 milliseconds
9
log.SetSampler(tas) // Sample trace data
10
metric.SetSampler(tas) // Sample trace data
11
trace.SetSampler(tas) // Sample trace data
Copied!

Duration Aware Sampler

The Duration Aware Sampler enables you to sample data according to a given duration. For example, if the duration is set to 1,000, metric data will be sampled when Lambda duration is greater than 1,000 milliseconds. The configuration is shown below:
Programmatic Configuration of DurationAwareSampler
1
import(
2
"github.com/thundra-io/thundra-lambda-agent-go/samplers"
3
"github.com/thundra-io/thundra-lambda-agent-go/metric"
4
"github.com/thundra-io/thundra-lambda-agent-go/log"
5
"github.com/thundra-io/thundra-lambda-agent-go/trace"
6
)
7
8
// Sample if exc duration greather than 1000 milisecond
9
das := samplers.NewDurationAwareSampler(1000, true)
10
log.SetSampler(das)
11
metric.SetSampler(das)
12
trace.SetSampler(das)
Copied!

Error Aware Sampler

The Error Aware Sampler enables you to sample data according to erroneous invocations of a Lambda. For example, you should use this sampler if you want to send metric data only when a Lambda execution results with an error.
Programmatic Configuration of ErrorAwareSampler
1
import(
2
"github.com/thundra-io/thundra-lambda-agent-go/samplers"
3
"github.com/thundra-io/thundra-lambda-agent-go/metric"
4
"github.com/thundra-io/thundra-lambda-agent-go/log"
5
"github.com/thundra-io/thundra-lambda-agent-go/trace"
6
)
7
8
eas := NewErrorAwareSampler() // Sample data when Lambda fails
9
log.SetSampler(eas) // Sample log data
10
metric.SetSampler(eas) // Sample metric data
11
trace.SetSampler(eas) // Sample trace data
Copied!

Composite Sampler

You can combine one or more samplers with the help of the Composite Sampler, and you can also decide which logical operator (and, or) will be used when combining the samplers. Composite Sampler can be used in any plugin. Just give the Composite Sampler to the sampler configuration of one of Thundra’s agents’ plugin configurations. The example below shows how to configure a CompositeSampler, which in this instance combines CountAwareSampler and ErrorAwareSampler with an and operation.
Programmatic Configuration of CompositeSampler
1
import(
2
"github.com/thundra-io/thundra-lambda-agent-go/samplers"
3
"github.com/thundra-io/thundra-lambda-agent-go/metric"
4
"github.com/thundra-io/thundra-lambda-agent-go/log"
5
"github.com/thundra-io/thundra-lambda-agent-go/trace"
6
)
7
8
cas := samplers.NewCountAwareSampler(2) // Sample data every 5th invocation
9
eas := NewErrorAwareSampler() // Sample data when lamda fails
10
11
samplerArr := []samplers.Sampler{cas,eas}
12
cs := samplers.NewCompositeSampler(samplerArr, "and") // Sample data every 5th error
13
14
log.SetSampler(eas) // Sample log data
15
metric.SetSampler(eas) // Sample metric data
16
trace.SetSampler(eas) // sSample trace data
Copied!
Last modified 10mo ago