Skip to content

Commit c60a937

Browse files
committed
TODO for custom connector and executor
1 parent c7b97a6 commit c60a937

File tree

2 files changed

+26
-7
lines changed
  • opentelemetry-http/src
  • opentelemetry-otlp/src/exporter/http

2 files changed

+26
-7
lines changed

opentelemetry-http/src/lib.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,34 @@ pub mod hyper {
108108
use http::HeaderValue;
109109
use http_body_util::{BodyExt, Full};
110110
use hyper::body::{Body as HttpBody, Frame};
111-
use hyper_util::client::legacy::{connect::HttpConnector, Client};
111+
use hyper_util::client::legacy::{
112+
connect::{Connect, HttpConnector},
113+
Client,
114+
};
112115
use std::fmt::Debug;
113116
use std::pin::Pin;
114117
use std::task::{self, Poll};
115118
use std::time::Duration;
116119
use tokio::time;
117120

118121
#[derive(Debug, Clone)]
119-
pub struct HyperClient {
120-
inner: Client<HttpConnector, Body>,
122+
pub struct HyperClient<C = HttpConnector>
123+
where
124+
C: Connect + Clone + Send + Sync + 'static,
125+
{
126+
inner: Client<C, Body>,
121127
timeout: Duration,
122128
authorization: Option<HeaderValue>,
123129
}
124130

125-
impl HyperClient {
131+
impl<C> HyperClient<C>
132+
where
133+
C: Connect + Clone + Send + Sync + 'static,
134+
{
126135
/// Creates a new `HyperClient` with default `HttpConnector` and `TokioExecutor`.
127-
pub fn new(timeout: Duration, authorization: Option<HeaderValue>) -> Self {
128-
let connector = HttpConnector::new();
136+
pub fn new(connector: C, timeout: Duration, authorization: Option<HeaderValue>) -> Self {
137+
// TODO - support custom executor
129138
let inner = Client::builder(hyper_util::rt::TokioExecutor::new()).build(connector);
130-
131139
Self {
132140
inner,
133141
timeout,
@@ -136,6 +144,16 @@ pub mod hyper {
136144
}
137145
}
138146

147+
impl HyperClient<HttpConnector> {
148+
/// Creates a new `HyperClient` with a default `HttpConnector`.
149+
pub fn with_default_connector(
150+
timeout: Duration,
151+
authorization: Option<HeaderValue>,
152+
) -> Self {
153+
Self::new(HttpConnector::new(), timeout, authorization)
154+
}
155+
}
156+
139157
#[async_trait]
140158
impl HttpClient for HyperClient {
141159
async fn send(&self, request: Request<Vec<u8>>) -> Result<Response<Bytes>, HttpError> {

opentelemetry-otlp/src/exporter/http/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl Default for HttpConfig {
7171
not(feature = "reqwest-blocking-client"),
7272
feature = "hyper-client"
7373
))]
74+
// TODO - support configuring custom connector and executor
7475
let default_client = Some(Arc::new(HyperClient::with_default_connector(
7576
Duration::from_secs(10),
7677
None,

0 commit comments

Comments
 (0)