feat(router_env): add sampling_rate for traces (#335)

This commit is contained in:
Sampras Lopes
2023-01-11 16:02:57 +05:30
committed by GitHub
parent 182e51f1e1
commit d4c4a09d14
3 changed files with 10 additions and 0 deletions

View File

@ -63,6 +63,11 @@ log_format = "default" # Log format. "default" or "json"
# defaults to "WARN" # defaults to "WARN"
level = "DEBUG" level = "DEBUG"
# Telemetry configuration for traces
[log.telemetry]
enabled = false # boolean [true or false]
sampling_rate = 0.1 # decimal rate between 0.0 - 1.0
# This section provides configuration details for using AWS KMS to encrypt # This section provides configuration details for using AWS KMS to encrypt
# data like payment method details being sent over a network. # data like payment method details being sent over a network.
[keys] [keys]

View File

@ -90,6 +90,8 @@ pub struct LogConsole {
pub struct LogTelemetry { pub struct LogTelemetry {
/// Whether tracing/telemetry is enabled. /// Whether tracing/telemetry is enabled.
pub enabled: bool, pub enabled: bool,
/// Sampling rate for traces
pub sampling_rate: Option<f64>,
} }
/// Telemetry / tracing. /// Telemetry / tracing.

View File

@ -42,6 +42,9 @@ pub fn setup<Str: AsRef<str>>(
let telemetry = if conf.telemetry.enabled { let telemetry = if conf.telemetry.enabled {
let trace_config = trace::config() let trace_config = trace::config()
.with_sampler(trace::Sampler::TraceIdRatioBased(
conf.telemetry.sampling_rate.unwrap_or(1.0),
))
.with_resource(Resource::new(vec![KeyValue::new("service.name", "router")])); .with_resource(Resource::new(vec![KeyValue::new("service.name", "router")]));
let tracer = opentelemetry_otlp::new_pipeline() let tracer = opentelemetry_otlp::new_pipeline()
.tracing() .tracing()