-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[opentelemetry-otlp] adds an example HTTP exporter backed by a Hyper …
…0.14 Client Resolves #1659
- Loading branch information
1 parent
b933bdd
commit 5816ba9
Showing
5 changed files
with
79 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use async_trait::async_trait; | ||
use bytes::Bytes; | ||
use http::{Request, Response}; | ||
use hyper::{ | ||
client::{connect::Connect, HttpConnector}, | ||
Body, Client, | ||
}; | ||
use opentelemetry_http::{HttpClient, HttpError, ResponseExt}; | ||
|
||
pub struct HyperClient<C> { | ||
inner: hyper::Client<C>, | ||
} | ||
|
||
impl Default for HyperClient<HttpConnector> { | ||
fn default() -> Self { | ||
Self { | ||
inner: Client::new(), | ||
} | ||
} | ||
} | ||
|
||
impl<C> std::fmt::Debug for HyperClient<C> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("HyperClient") | ||
.field("inner", &self.inner) | ||
.finish() | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<C: Connect + Clone + Send + Sync + 'static> HttpClient for HyperClient<C> { | ||
async fn send(&self, request: Request<Vec<u8>>) -> Result<Response<Bytes>, HttpError> { | ||
let request = request.map(Body::from); | ||
|
||
let (parts, body) = self | ||
.inner | ||
.request(request) | ||
.await? | ||
.error_for_status()? | ||
.into_parts(); | ||
let body = hyper::body::to_bytes(body).await?; | ||
|
||
Ok(Response::from_parts(parts, body)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters