From 8a25d40ef1553a7742c82db912506028a97ba891 Mon Sep 17 00:00:00 2001 From: smiletech092-code Date: Mon, 29 Jun 2026 21:07:08 +0000 Subject: [PATCH] Fix(tracing): use TelemetryConfig in init_tracer to match AppConfig --- src/telemetry/tracer.rs | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/telemetry/tracer.rs b/src/telemetry/tracer.rs index d69e6261..b8327ba9 100644 --- a/src/telemetry/tracer.rs +++ b/src/telemetry/tracer.rs @@ -8,36 +8,7 @@ use opentelemetry_sdk::{ }; use tracing_opentelemetry::OpenTelemetryLayer; use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer}; - -/// Configuration for the OpenTelemetry tracer loaded from environment variables. -#[derive(Debug, Clone)] -pub struct TracingConfig { - /// Human-readable service name emitted in every span. - pub service_name: String, - /// Deployment environment (e.g. "development", "staging", "production"). - pub environment: String, - /// Fraction of traces to sample (0.0 – 1.0). Error traces are always sampled. - pub sampling_rate: f64, - /// OTLP collector endpoint (e.g. "http://localhost:4317"). - pub otlp_endpoint: String, -} - -impl TracingConfig { - /// Build configuration from environment variables with sensible defaults. - pub fn from_env() -> Self { - Self { - service_name: std::env::var("OTEL_SERVICE_NAME") - .unwrap_or_else(|_| "aframp-backend".into()), - environment: std::env::var("APP_ENV").unwrap_or_else(|_| "development".into()), - sampling_rate: std::env::var("OTEL_SAMPLING_RATE") - .ok() - .and_then(|v| v.parse().ok()) - .unwrap_or(1.0), - otlp_endpoint: std::env::var("OTEL_EXPORTER_OTLP_ENDPOINT") - .unwrap_or_else(|_| "http://localhost:4317".into()), - } - } -} +use crate::config::TelemetryConfig; /// Initialise the global OpenTelemetry tracer provider and the `tracing` subscriber. /// @@ -53,7 +24,7 @@ impl TracingConfig { /// downstream processor / collector can apply tail-based sampling if desired. /// Within the SDK we default to `AlwaysOn` when sampling_rate == 1.0 and fall /// back to a `TraceIdRatioBased` sampler wrapped in `ParentBased` otherwise. -pub fn init_tracer(config: &TracingConfig) -> anyhow::Result<()> { +pub fn init_tracer(config: &TelemetryConfig) -> anyhow::Result<()> { // Register W3C propagator globally so extract/inject helpers work. global::set_text_map_propagator(TraceContextPropagator::new());