From 70591178fefa448baa0f7e2bac6dffb5c8ab963a Mon Sep 17 00:00:00 2001 From: vianney Date: Wed, 24 Jun 2026 18:32:03 +0200 Subject: [PATCH] feat(trace_exporter): enable telemetry in stats exporter --- libdd-data-pipeline/src/telemetry/mod.rs | 5 +++++ libdd-data-pipeline/src/trace_exporter/builder.rs | 7 +++---- libdd-data-pipeline/src/trace_exporter/mod.rs | 9 ++++++--- libdd-data-pipeline/src/trace_exporter/stats.rs | 9 +++++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/libdd-data-pipeline/src/telemetry/mod.rs b/libdd-data-pipeline/src/telemetry/mod.rs index 10649f87ab..abf2cea494 100644 --- a/libdd-data-pipeline/src/telemetry/mod.rs +++ b/libdd-data-pipeline/src/telemetry/mod.rs @@ -325,6 +325,11 @@ impl TelemetryClient { .send_msg(TelemetryActions::Lifecycle(LifecycleAction::Start)) .await; } + + /// Clone the telemetry handle + pub fn clone_handle(&self) -> TelemetryWorkerHandle { + self.worker.clone() + } } #[cfg(test)] diff --git a/libdd-data-pipeline/src/trace_exporter/builder.rs b/libdd-data-pipeline/src/trace_exporter/builder.rs index 7f5f871d34..9ee7e337e7 100644 --- a/libdd-data-pipeline/src/trace_exporter/builder.rs +++ b/libdd-data-pipeline/src/trace_exporter/builder.rs @@ -478,10 +478,9 @@ impl TraceExporterBuilder { })?), }; - let dogstatsd = self.dogstatsd_url.and_then(|u| { - new(Endpoint::from_slice(&u)).ok() // If we couldn't set the endpoint return - // None - }); + let dogstatsd = self + .dogstatsd_url + .and_then(|u| new(Endpoint::from_slice(&u)).ok().map(Arc::new)); let base_url = self.url.as_deref().unwrap_or(DEFAULT_AGENT_URL); diff --git a/libdd-data-pipeline/src/trace_exporter/mod.rs b/libdd-data-pipeline/src/trace_exporter/mod.rs index a3a19aed78..a1f8454ee8 100644 --- a/libdd-data-pipeline/src/trace_exporter/mod.rs +++ b/libdd-data-pipeline/src/trace_exporter/mod.rs @@ -205,7 +205,7 @@ pub struct TraceExporter< serializer: TraceSerializer, shared_runtime: Arc, /// None if dogstatsd is disabled - dogstatsd: Option, + dogstatsd: Option>, common_stats_tags: Vec, client_computed_top_level: bool, client_side_stats: StatsComputationConfig, @@ -407,6 +407,9 @@ impl>) { if self.health_metrics_enabled { - let emitter = MetricsEmitter::new(self.dogstatsd.as_ref(), &self.common_stats_tags); + let emitter = MetricsEmitter::new(self.dogstatsd.as_deref(), &self.common_stats_tags); emitter.emit(metric, custom_tags); } } @@ -505,7 +508,7 @@ impl { pub metadata: &'a TracerMetadata, pub endpoint_url: &'a http::Uri, pub shared_runtime: &'a R, + /// Optional DogStatsD client forwarded to the [`StatsExporter`]. + pub dogstatsd: Option>, + /// Optional telemetry handle forwarded to the [`StatsExporter`]. + #[cfg(feature = "telemetry")] + pub telemetry: Option, } #[derive(Debug)] @@ -167,8 +172,8 @@ fn create_and_start_stats_worker< #[cfg(feature = "stats-obfuscation")] SUPPORTED_OBFUSCATION_VERSION_STR, #[cfg(feature = "telemetry")] - None, - None, + ctx.telemetry.clone(), + ctx.dogstatsd.clone(), ); let worker_handle = ctx .shared_runtime