Sampling
Control log volume in high-throughput applications.
Overview
Sampling allows you to:
- Reduce costs — Send fewer logs to paid services
- Prevent overload — Protect log infrastructure
- Focus on important logs — Always capture errors, sample debug logs
Vestig provides three sampling strategies:
| Strategy | Description | Use Case |
|---|---|---|
| Probability | Random sampling by percentage | General log reduction |
| Rate Limit | Max logs per time window | Protect against log storms |
| Namespace | Different rates per namespace | Fine-grained control |
Quick Start
typescript
Probability Sampling
Sample a percentage of logs:
typescript
Dynamic Rates
Adjust sampling based on conditions:
typescript
Rate Limit Sampling
Cap the number of logs per time window:
typescript
Burst Handling
Allow short bursts while maintaining average rate:
typescript
Namespace Sampling
Different rates for different parts of your app:
typescript
Composite Sampling
Combine multiple samplers:
typescript
Sampling Modes
'all'— Log kept only if ALL samplers agree'any'— Log kept if ANY sampler agrees
Always Sample Certain Logs
Keep important logs regardless of sampling:
typescript
Sampling with Context
Make sampling decisions based on correlation context:
typescript
Sampler API
Create custom samplers:
typescript
Configuration
Full sampling configuration:
typescript
When addSamplingMetadata is true:
json
Next Steps
- Probability Sampling — Detailed probability options
- Rate Limiting — Rate limit configuration
- Namespace Sampling — Per-namespace rates