Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libdd-data-pipeline/src/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
7 changes: 3 additions & 4 deletions libdd-data-pipeline/src/trace_exporter/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,9 @@ impl<R: SharedRuntime> TraceExporterBuilder<R> {
})?),
};

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);

Expand Down
9 changes: 6 additions & 3 deletions libdd-data-pipeline/src/trace_exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub struct TraceExporter<
serializer: TraceSerializer,
shared_runtime: Arc<R>,
/// None if dogstatsd is disabled
dogstatsd: Option<Client>,
dogstatsd: Option<Arc<Client>>,
common_stats_tags: Vec<Tag>,
client_computed_top_level: bool,
client_side_stats: StatsComputationConfig,
Expand Down Expand Up @@ -407,6 +407,9 @@ impl<C: HttpClientCapability + SleepCapability + MaybeSend + Sync + 'static, R:
metadata: &self.metadata,
endpoint_url: &self.endpoint.url,
shared_runtime: &*self.shared_runtime,
dogstatsd: self.dogstatsd.clone(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate stats DogStatsD metrics behind health-metrics opt-in

When stats computation is enabled and the agent supports it, forwarding self.dogstatsd here lets StatsExporter emit datadog.tracer.stats.collapsed_spans whenever spans are collapsed, even if the caller only configured set_dogstatsd_url() and did not call enable_health_metrics(). That bypasses the documented/default-disabled health-metrics guard used by emit_metric and emit_send_result, so users can start seeing DogStatsD health metrics despite leaving the feature disabled; pass None here unless self.health_metrics_enabled is true.

Useful? React with 👍 / 👎.

#[cfg(feature = "telemetry")]
telemetry: self.telemetry.as_ref().map(|t| t.clone_handle()),
};
stats::handle_stats_disabled_by_agent(
&ctx,
Expand Down Expand Up @@ -497,15 +500,15 @@ impl<C: HttpClientCapability + SleepCapability + MaybeSend + Sync + 'static, R:
/// Emit a health metric to dogstatsd
fn emit_metric(&self, metric: HealthMetric, custom_tags: Option<Vec<&Tag>>) {
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);
}
}

/// Emit all health metrics from a SendResult
fn emit_send_result(&self, result: &SendResult) {
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_from_send_result(result);
}
}
Expand Down
9 changes: 7 additions & 2 deletions libdd-data-pipeline/src/trace_exporter/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pub(crate) struct StatsContext<'a, R: SharedRuntime> {
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<std::sync::Arc<libdd_dogstatsd_client::Client>>,
/// Optional telemetry handle forwarded to the [`StatsExporter`].
#[cfg(feature = "telemetry")]
pub telemetry: Option<libdd_telemetry::worker::TelemetryWorkerHandle>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -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
Expand Down
Loading