diff --git a/libdd-trace-utils/src/stats_utils.rs b/libdd-trace-utils/src/stats_utils.rs index 4bd951e36..405077d52 100644 --- a/libdd-trace-utils/src/stats_utils.rs +++ b/libdd-trace-utils/src/stats_utils.rs @@ -9,7 +9,9 @@ mod mini_agent { use http_body_util::BodyExt; use hyper::{body::Buf, Method, Request, StatusCode}; use libdd_common::hyper_migration; + use libdd_common::Connect; use libdd_common::Endpoint; + use libdd_common::GenericHttpClient; use libdd_trace_protobuf::pb; use std::io::Write; use tracing::debug; @@ -58,6 +60,18 @@ mod mini_agent { data: Vec, target: &Endpoint, api_key: &str, + ) -> anyhow::Result<()> { + send_stats_payload_with_client::( + data, target, api_key, None, + ) + .await + } + + pub async fn send_stats_payload_with_client( + data: Vec, + target: &Endpoint, + api_key: &str, + client: Option<&GenericHttpClient>, ) -> anyhow::Result<()> { let req = Request::builder() .method(Method::POST) @@ -67,8 +81,14 @@ mod mini_agent { .header("DD-API-KEY", api_key) .body(hyper_migration::Body::from(data.clone()))?; - let client = hyper_migration::new_default_client(); - match client.request(req).await { + let response = if let Some(client) = client { + client.request(req).await + } else { + let default_client = hyper_migration::new_default_client(); + default_client.request(req).await + }; + + match response { Ok(response) => { if response.status() != StatusCode::ACCEPTED { let body_bytes = response.into_body().collect().await?.to_bytes();