Skip to content
Merged
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
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions datadog-sidecar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ anyhow = { version = "1.0" }
arrayref = "0.3.7"
priority-queue = "2.1.1"
libdd-common = { path = "../libdd-common" }
libdd-capabilities = { path = "../libdd-capabilities", version = "0.1.0" }
datadog-sidecar-macros = { path = "../datadog-sidecar-macros" }

libdd-telemetry = { path = "../libdd-telemetry", features = ["tracing"] }
Expand Down
2 changes: 1 addition & 1 deletion datadog-sidecar/src/service/agent_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use datadog_ipc::platform::NamedShmHandle;
use futures::future::Shared;
use futures::FutureExt;
use http::uri::PathAndQuery;
use libdd_common::DefaultHttpClient;
use libdd_capabilities_impl::DefaultHttpClient;
use libdd_common::{Endpoint, MutexExt};
use libdd_data_pipeline::agent_info::schema::AgentInfoStruct;
use libdd_data_pipeline::agent_info::{fetch_info_with_state, FetchInfoStatus};
Expand Down
5 changes: 3 additions & 2 deletions datadog-sidecar/src/service/tracing/trace_flusher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use super::TraceSendData;
use crate::agent_remote_config::AgentRemoteConfigWriter;
use datadog_ipc::platform::NamedShmHandle;
use futures::future::join_all;
use libdd_common::capabilities::HttpClientTrait;
use libdd_common::{DefaultHttpClient, Endpoint, MutexExt};
use libdd_capabilities::HttpClientTrait;
use libdd_capabilities_impl::DefaultHttpClient;
use libdd_common::{Endpoint, MutexExt};
use libdd_trace_utils::trace_utils;
use libdd_trace_utils::trace_utils::SendData;
use libdd_trace_utils::trace_utils::SendDataResult;
Expand Down
3 changes: 3 additions & 0 deletions libdd-capabilities-impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ http = "1"
libdd-capabilities = { path = "../libdd-capabilities", version = "0.1.0" }
libdd-common = { path = "../libdd-common", version = "3.0.2", default-features = false }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
http-body-util = "0.1"

[features]
default = ["https"]
https = ["libdd-common/https"]
Expand Down
59 changes: 56 additions & 3 deletions libdd-capabilities-impl/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,60 @@
// Copyright 2026-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

//! Re-exports `DefaultHttpClient` from `libdd-common`, where it lives alongside
//! the hyper infrastructure it wraps.
//! Native HTTP client implementation backed by hyper.

pub use libdd_common::DefaultHttpClient;
mod native {
use libdd_capabilities::http::{HttpClientTrait, HttpError};
use libdd_capabilities::maybe_send::MaybeSend;
use libdd_common::connector::Connector;
use libdd_common::http_common::{new_default_client, Body, GenericHttpClient};

use http_body_util::BodyExt;

#[derive(Clone)]
pub struct DefaultHttpClient {
client: GenericHttpClient<Connector>,
}

impl std::fmt::Debug for DefaultHttpClient {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DefaultHttpClient").finish()
}
}

impl HttpClientTrait for DefaultHttpClient {
fn new_client() -> Self {
Self {
client: new_default_client(),
}
}

#[allow(clippy::manual_async_fn)]
fn request(
&self,
req: http::Request<bytes::Bytes>,
) -> impl std::future::Future<Output = Result<http::Response<bytes::Bytes>, HttpError>> + MaybeSend
{
let client = self.client.clone();
async move {
let hyper_req = req.map(Body::from_bytes);

let response = client
.request(hyper_req)
.await
.map_err(|e| HttpError::Network(e.into()))?;

let (parts, body) = response.into_parts();
let collected = body
.collect()
.await
.map_err(|e| HttpError::ResponseBody(e.into()))?
.to_bytes();

Ok(http::Response::from_parts(parts, collected))
}
}
}
}

pub use native::DefaultHttpClient;
73 changes: 43 additions & 30 deletions libdd-capabilities-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,53 @@

mod http;

use core::future::Future;
pub use libdd_capabilities::HttpClientTrait;

#[cfg(not(target_arch = "wasm32"))]
pub use http::DefaultHttpClient;
use libdd_capabilities::http::HttpError;
pub use libdd_capabilities::HttpClientTrait;
use libdd_capabilities::MaybeSend;

/// Bundle struct for native platform capabilities.
///
/// Delegates to [`DefaultHttpClient`] for HTTP. As more capability traits are
/// added (spawn, sleep, etc.), additional fields and impls are added here
/// without changing the type identity — consumers see the same
/// `NativeCapabilities` throughout.
///
/// Individual capability traits keep minimal per-function bounds (e.g.
/// functions that only need HTTP require just `H: HttpClientTrait`, not the
/// full bundle) so that native callers like the sidecar can use
/// `DefaultHttpClient` directly without pulling in this bundle.
#[derive(Clone, Debug)]
pub struct NativeCapabilities {
http: DefaultHttpClient,
}

impl HttpClientTrait for NativeCapabilities {
fn new_client() -> Self {
Self {
http: DefaultHttpClient::new_client(),
}
#[cfg(not(target_arch = "wasm32"))]
mod native {
use core::future::Future;

use libdd_capabilities::http::HttpError;
use libdd_capabilities::MaybeSend;

use super::DefaultHttpClient;
use super::HttpClientTrait;

/// Bundle struct for native platform capabilities.
///
/// Delegates to [`DefaultHttpClient`] for HTTP. As more capability traits are
/// added (spawn, sleep, etc.), additional fields and impls are added here
/// without changing the type identity — consumers see the same
/// `NativeCapabilities` throughout.
///
/// Individual capability traits keep minimal per-function bounds (e.g.
/// functions that only need HTTP require just `H: HttpClientTrait`, not the
/// full bundle) so that native callers like the sidecar can use
/// `DefaultHttpClient` directly without pulling in this bundle.
#[derive(Clone, Debug)]
pub struct NativeCapabilities {
http: DefaultHttpClient,
}

fn request(
&self,
req: ::http::Request<bytes::Bytes>,
) -> impl Future<Output = Result<::http::Response<bytes::Bytes>, HttpError>> + MaybeSend {
self.http.request(req)
impl HttpClientTrait for NativeCapabilities {
fn new_client() -> Self {
Self {
http: DefaultHttpClient::new_client(),
}
}

fn request(
&self,
req: ::http::Request<bytes::Bytes>,
) -> impl Future<Output = Result<::http::Response<bytes::Bytes>, HttpError>> + MaybeSend
{
self.http.request(req)
}
}
}

#[cfg(not(target_arch = "wasm32"))]
pub use native::NativeCapabilities;
1 change: 0 additions & 1 deletion libdd-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ crate-type = ["lib"]
bench = false

[dependencies]
libdd-capabilities = { path = "../libdd-capabilities", version = "0.1.0" }
anyhow = "1.0"
futures = "0.3"
futures-core = { version = "0.3.0", default-features = false }
Expand Down
6 changes: 0 additions & 6 deletions libdd-common/src/capabilities/mod.rs

This file was deleted.

50 changes: 0 additions & 50 deletions libdd-common/src/http_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,56 +300,6 @@ mod native {
pub fn client_builder() -> hyper_util::client::legacy::Builder {
hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::default())
}

// --- DefaultHttpClient: portable HttpClientTrait backed by hyper ---

use libdd_capabilities::http::{HttpClientTrait, HttpError};
use libdd_capabilities::maybe_send::MaybeSend;

#[derive(Clone)]
pub struct DefaultHttpClient {
client: GenericHttpClient<Connector>,
}

impl std::fmt::Debug for DefaultHttpClient {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DefaultHttpClient").finish()
}
}

impl HttpClientTrait for DefaultHttpClient {
fn new_client() -> Self {
Self {
client: new_default_client(),
}
}

#[allow(clippy::manual_async_fn)]
fn request(
&self,
req: http::Request<bytes::Bytes>,
) -> impl std::future::Future<Output = Result<http::Response<bytes::Bytes>, HttpError>> + MaybeSend
{
let client = self.client.clone();
async move {
let hyper_req = req.map(Body::from_bytes);

let response = client
.request(hyper_req)
.await
.map_err(|e| HttpError::Network(e.into()))?;

let (parts, body) = response.into_parts();
let collected = body
.collect()
.await
.map_err(|e| HttpError::ResponseBody(e.into()))?
.to_bytes();

Ok(http::Response::from_parts(parts, collected))
}
}
}
}

#[cfg(not(target_arch = "wasm32"))]
Expand Down
3 changes: 0 additions & 3 deletions libdd-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::sync::{Mutex, MutexGuard};
use std::{borrow::Cow, ops::Deref, path::PathBuf, str::FromStr};

pub mod azure_app_services;
pub mod capabilities;
#[cfg(not(target_arch = "wasm32"))]
pub mod cc_utils;
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -113,8 +112,6 @@ pub mod header {
HeaderName::from_static("x-datadog-test-session-token");
}

#[cfg(not(target_arch = "wasm32"))]
pub use http_common::DefaultHttpClient;
#[cfg(not(target_arch = "wasm32"))]
pub type HttpClient = http_common::GenericHttpClient<connector::Connector>;
#[cfg(not(target_arch = "wasm32"))]
Expand Down
Loading