use crate::service::{Layer, Service};
use crate::util::spans::{self, HttpSpanFuture};
use conjure_error::Error;
use http::{Request, Response};
use std::future::Future;
pub struct RootSpanLayer;
impl<S> Layer<S> for RootSpanLayer {
type Service = RootSpanService<S>;
fn layer(self, inner: S) -> Self::Service {
RootSpanService { inner }
}
}
pub struct RootSpanService<S> {
inner: S,
}
impl<S, B1, B2> Service<Request<B1>> for RootSpanService<S>
where
S: Service<Request<B1>, Response = Response<B2>, Error = Error>,
{
type Response = S::Response;
type Error = S::Error;
fn call(&self, req: Request<B1>) -> impl Future<Output = Result<Self::Response, Self::Error>> {
let mut span = zipkin::next_span()
.with_name("conjure-runtime: request")
.detach();
spans::add_request_tags(&mut span, &req);
HttpSpanFuture::new(self.inner.call(req), span)
}
}