Skip to content

Commit cd81124

Browse files
Thea HeinenTheJokr
authored andcommitted
Re-export Hyper types used in public API
Foundations uses Hyper types in it's public API for `TelemetryServerRoute` which means any users will need to add an explicit dependency on the same version of hyper and ensure it stays matching. Re-exporting the types will allow users to explicitly use the same types as foundations is using. For simplicity, we re-export the entire `hyper` crate under a new `foundations::telemetry::reexports` module.
1 parent ccbdef2 commit cd81124

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

foundations/src/telemetry/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,15 @@ pub use self::memory_profiler::MemoryProfiler;
132132

133133
#[cfg(feature = "telemetry-server")]
134134
pub use self::server::{
135-
BoxError, TelemetryRouteHandler, TelemetryRouteHandlerFuture, TelemetryServerRoute,
135+
TelemetryRouteBody, TelemetryRouteHandler, TelemetryRouteHandlerFuture, TelemetryServerRoute,
136136
};
137137

138+
#[cfg(feature = "telemetry-server")]
139+
/// Re-exported crates which are used in public `telemetry` APIs.
140+
pub mod reexports {
141+
pub use hyper;
142+
}
143+
138144
pub use self::telemetry_context::{
139145
TelemetryContext, WithTelemetryContext, WithTelemetryContextLocal,
140146
};

foundations/src/telemetry/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl TelemetryListener {
131131
}
132132

133133
pub use router::{
134-
BoxError, TelemetryRouteHandler, TelemetryRouteHandlerFuture, TelemetryServerRoute,
134+
TelemetryRouteBody, TelemetryRouteHandler, TelemetryRouteHandlerFuture, TelemetryServerRoute,
135135
};
136136

137137
pub(super) struct TelemetryServerFuture {

foundations/src/telemetry/server/router.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ use std::collections::HashMap;
1616
use std::convert::Infallible;
1717
use std::sync::Arc;
1818

19+
/// Body type used in [`TelemetryServerRoute`] responses.
20+
pub type TelemetryRouteBody = BoxBody<Bytes, crate::Error>;
21+
1922
/// Future returned by [`TelemetryServerRoute::handler`].
2023
pub type TelemetryRouteHandlerFuture =
21-
BoxFuture<'static, std::result::Result<Response<BoxBody<Bytes, BoxError>>, Infallible>>;
22-
23-
/// Error type returned by [`TelemetryRouteHandlerFuture`].
24-
pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
24+
BoxFuture<'static, Result<Response<TelemetryRouteBody>, Infallible>>;
2525

2626
/// Telemetry route handler.
2727
pub type TelemetryRouteHandler = Box<
@@ -156,7 +156,7 @@ impl Router {
156156
}
157157
}
158158

159-
async fn handle_request(&self, req: Request<Incoming>) -> Response<BoxBody<Bytes, BoxError>> {
159+
async fn handle_request(&self, req: Request<Incoming>) -> Response<TelemetryRouteBody> {
160160
let res = Response::builder();
161161

162162
let Ok(path) = percent_decode_str(req.uri().path()).decode_utf8() else {
@@ -188,7 +188,7 @@ impl Router {
188188
}
189189

190190
impl Service<Request<Incoming>> for Router {
191-
type Response = Response<BoxBody<Bytes, BoxError>>;
191+
type Response = Response<TelemetryRouteBody>;
192192
type Error = Infallible;
193193
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
194194

@@ -202,7 +202,7 @@ impl Service<Request<Incoming>> for Router {
202202
fn into_response(
203203
content_type: &str,
204204
res: crate::Result<impl Into<Full<Bytes>>>,
205-
) -> std::result::Result<Response<BoxBody<Bytes, BoxError>>, Infallible> {
205+
) -> Result<Response<TelemetryRouteBody>, Infallible> {
206206
Ok(match res {
207207
Ok(data) => Response::builder()
208208
.header(header::CONTENT_TYPE, content_type)

foundations/tests/telemetry_server.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use foundations::telemetry::settings::{
22
LivenessTrackingSettings, TelemetryServerSettings, TelemetrySettings, TracingSettings,
33
};
4-
use foundations::telemetry::{TelemetryConfig, TelemetryContext, TelemetryServerRoute};
4+
use foundations::telemetry::{
5+
reexports::hyper::{Method, Response},
6+
TelemetryConfig, TelemetryContext, TelemetryRouteBody, TelemetryServerRoute,
7+
};
58
use futures_util::FutureExt;
6-
use http_body_util::combinators::BoxBody;
79
use http_body_util::{BodyExt, Full};
8-
use hyper::{Method, Response};
910
use std::future::IntoFuture;
1011
use std::net::{Ipv4Addr, SocketAddr};
1112

@@ -56,7 +57,7 @@ async fn telemetry_server() {
5657
methods: vec![Method::GET],
5758
handler: Box::new(|_, _| {
5859
async {
59-
Ok(Response::new(BoxBody::new(
60+
Ok(Response::new(TelemetryRouteBody::new(
6061
Full::from("Hello").map_err(Into::into),
6162
)))
6263
}

0 commit comments

Comments
 (0)