Planned features for future releases.
Add support for trace sampling to reduce overhead in high-volume production environments.
Feature: MSGTRACE_TRACE_SAMPLE_RATE
Implementation:
# Environment variable
MSGTRACE_TRACE_SAMPLE_RATE=0.1 # Sample 10% of traces
# In tracer.py, add to _initialize_tracer():
from opentelemetry.sdk.trace.sampling import TraceIdRatioBased
sample_rate = float(os.getenv("MSGTRACE_TRACE_SAMPLE_RATE", "1.0"))
sampler = TraceIdRatioBased(sample_rate)
provider = TracerProvider(resource=resource, sampler=sampler)Use cases:
- Production environments with high traffic (sample 1-10%)
- Development/staging with full sampling (100%)
- Cost optimization by reducing trace volume
- Performance optimization by reducing overhead
Configuration options:
1.0(default) - Capture 100% of traces0.5- Capture 50% of traces0.1- Capture 10% of traces0.0- Disable tracing (alternative to MSGTRACE_TELEMETRY_ENABLED)
Technical details:
- Uses OpenTelemetry's
TraceIdRatioBasedsampler - Deterministic sampling based on trace ID
- Sampling decision propagated to child spans
- No performance impact on non-sampled traces
Fine-tune batch processor settings:
MSGTRACE_BATCH_MAX_QUEUE_SIZEMSGTRACE_BATCH_SCHEDULE_DELAYMSGTRACE_BATCH_MAX_EXPORT_BATCH_SIZE
Support for custom sampling strategies:
- Parent-based sampling
- Rate limiting sampler
- Attribute-based sampling
Add OpenTelemetry metrics alongside traces:
- Token usage metrics
- Cost metrics
- Latency histograms
- Error rates
Automatic correlation between logs and traces:
- Inject trace context into logs
- Link log records to spans