Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export RequestTracingMiddleware #106

Merged
merged 1 commit into from
Apr 29, 2022
Merged

Export RequestTracingMiddleware #106

merged 1 commit into from
Apr 29, 2022

Conversation

jakelee8
Copy link
Contributor

No description provided.

@jakelee8 jakelee8 marked this pull request as draft April 29, 2022 22:59
@jakelee8 jakelee8 marked this pull request as ready for review April 29, 2022 23:13
@jakelee8
Copy link
Contributor Author

Actix Web doesn't export the LoggerMiddleware so not sure if this is a recommended practice. Idea is to create a common stack of middleware:

#[derive(Debug)]
pub struct BitskiMiddleware {
    logger: Logger,
    request_tracing: RequestTracing,
    request_metrics: RequestMetrics,
}

impl Default for BitskiMiddleware {
    fn default() -> Self {
        Self {
            logger: Default::default(),
            request_tracing: Default::default(),
            request_metrics: RequestMetricsBuilder::new()
                .build(opentelemetry::global::meter("actix_web")),
        }
    }
}

impl<S, B> dev::Transform<S, dev::ServiceRequest> for BitskiMiddleware
where
    S: dev::Service<
        dev::ServiceRequest,
        Response = dev::ServiceResponse<B>,
        Error = actix_web::Error,
    >,
    B: 'static + MessageBody,
{
    type Response = dev::ServiceResponse<B>;
    type Error = actix_web::Error;
    type Transform = RequestMetricsMiddleware<RequestTracingMiddleware<LoggerMiddleware<S>>>;
    type InitError = ();
    type Future = future::Ready<Result<Self::Transform, Self::InitError>>;

    fn new_transform(&self, service: S) -> Self::Future {
        let service = self.logger.new_transform(service).into_inner()?;
        let service = self.request_tracing.new_transform(service).into_inner()?;
        let service = self.request_metrics.new_transform(service).into_inner()?;
        future::ok(service)
    }
}

@jtescher jtescher merged commit 49e5f5c into OutThereLabs:main Apr 29, 2022
@jtescher jtescher deleted the feature/pub-tracing-middleware branch April 29, 2022 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants