Skip to content

Commit 9b82a61

Browse files
committed
Fix hyper example
1 parent a4ea7c6 commit 9b82a61

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ publish = false
88
[features]
99
default = ["reqwest"]
1010
reqwest = ["opentelemetry-otlp/reqwest-client"]
11-
hyper = ["dep:async-trait", "dep:http", "dep:hyper", "dep:opentelemetry-http", "dep:bytes"]
11+
hyper = ["dep:async-trait", "dep:http", "dep:http-body-util", "dep:hyper", "dep:hyper-util", "dep:opentelemetry-http", "dep:bytes"]
1212

1313

1414
[dependencies]
@@ -23,7 +23,9 @@ opentelemetry-semantic-conventions = { path = "../../../opentelemetry-semantic-c
2323
async-trait = { workspace = true, optional = true }
2424
bytes = { workspace = true, optional = true }
2525
http = { workspace = true, optional = true }
26+
http-body-util = { workspace = true, optional = true }
2627
hyper = { workspace = true, features = ["client"], optional = true }
28+
hyper-util = { workspace = true, features = ["client-legacy"], optional = true }
2729
tokio = { workspace = true, features = ["full"] }
2830
tracing = { workspace = true, features = ["std"]}
2931
tracing-core = { workspace = true }

opentelemetry-otlp/examples/basic-otlp-http/src/hyper.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
use async_trait::async_trait;
22
use bytes::Bytes;
33
use http::{Request, Response};
4-
use hyper::{
5-
client::{connect::Connect, HttpConnector},
6-
Body, Client,
4+
use http_body_util::{BodyExt, Full};
5+
use hyper_util::{
6+
client::legacy::{
7+
connect::{Connect, HttpConnector},
8+
Client,
9+
},
10+
rt::TokioExecutor,
711
};
812
use opentelemetry_http::{HttpClient, HttpError, ResponseExt};
913

1014
pub struct HyperClient<C> {
11-
inner: hyper::Client<C>,
15+
inner: hyper_util::client::legacy::Client<C, Full<Bytes>>,
1216
}
1317

1418
impl Default for HyperClient<HttpConnector> {
1519
fn default() -> Self {
1620
Self {
17-
inner: Client::new(),
21+
inner: Client::builder(TokioExecutor::new()).build_http(),
1822
}
1923
}
2024
}
@@ -30,15 +34,15 @@ impl<C> std::fmt::Debug for HyperClient<C> {
3034
#[async_trait]
3135
impl<C: Connect + Clone + Send + Sync + 'static> HttpClient for HyperClient<C> {
3236
async fn send(&self, request: Request<Vec<u8>>) -> Result<Response<Bytes>, HttpError> {
33-
let request = request.map(Body::from);
37+
let request = request.map(|body| Full::new(Bytes::from(body)));
3438

3539
let (parts, body) = self
3640
.inner
3741
.request(request)
3842
.await?
3943
.error_for_status()?
4044
.into_parts();
41-
let body = hyper::body::to_bytes(body).await?;
45+
let body = body.collect().await?.to_bytes();
4246

4347
Ok(Response::from_parts(parts, body))
4448
}

0 commit comments

Comments
 (0)