Skip to content

feat(tracing): add advanced sampling strategies #10

@CalvinAllen

Description

@CalvinAllen

Summary

Add more sophisticated sampling strategies beyond the current simple ratio-based sampling. This enables cost-effective telemetry while ensuring important data is captured.

Proposed Sampling Strategies

1. Error-Biased Sampling

Always capture errors at 100%, sample successes at a lower rate.

config.Sampling = new ErrorBiasedSampler(
    errorSampleRate: 1.0,      // 100% of errors
    successSampleRate: 0.1     // 10% of successes
);

2. Adaptive Sampling

Automatically adjust rate based on volume to stay within a target throughput.

config.Sampling = new AdaptiveSampler(
    targetSpansPerMinute: 1000,
    minSampleRate: 0.01,
    maxSampleRate: 1.0
);

3. Per-Operation Sampling

Different rates for different operation types.

config.Sampling = new PerOperationSampler(new Dictionary<string, double>
{
    ["CommandExecution"] = 1.0,    // Always capture commands
    ["DocumentChange"] = 0.01,     // Rare for noisy events
    ["*"] = 0.1                    // Default for others
});

4. Parent-Based Sampling

Respect parent span's sampling decision for distributed traces.

config.Sampling = new ParentBasedSampler(
    rootSampler: new RatioSampler(0.1)
);

Implementation Notes

  • Implement Sampler base class with ShouldSample() method
  • Integrate with OpenTelemetry's sampler pipeline
  • Add sampling decision to span attributes for debugging

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions