Skip to content
Open
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
24 changes: 22 additions & 2 deletions libdd-trace-utils/src/stats_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,6 +60,18 @@ mod mini_agent {
data: Vec<u8>,
target: &Endpoint,
api_key: &str,
) -> anyhow::Result<()> {
send_stats_payload_with_client::<libdd_common::connector::Connector>(
data, target, api_key, None,
)
.await
}

pub async fn send_stats_payload_with_client<C: Connect>(
data: Vec<u8>,
target: &Endpoint,
api_key: &str,
client: Option<&GenericHttpClient<C>>,
) -> anyhow::Result<()> {
let req = Request::builder()
.method(Method::POST)
Expand All @@ -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();
Expand Down
Loading