How to time Actix middlewares with Tracing

We are running Actix 4.0 beta at my workplace and believe we are encountering an issue in one of our custom middlewares. I decided I wanted to add some trace spans from the tracing library into the middleware in an attempt to get a better idea of what is going on, specifically regarding timing. However, I'm not sure the best way to do this.

Some options I have thought of:

1.) I could add a new span which covers the entirety of the Service::call function we have implemented, which would extend to any futures awaited. This is super simple, but it also means that the span's timing would include the timing of the rest of the request inside of the middleware "onion", and so the timing doesn't really tell us about how much the specific middleware itself took. If the "inner" middleware is also traced then one could see the difference in the span timings, so if we took this option we would need to add more tracing elsewhere to see this difference.

2.) Add explicit "before" and "after" spans inside the middleware. IOW, create one span which lasts from the start of the function until the inner service's call function is made, and then open another span for anything that occurs after the call function's future has resolved. This gets us more of what we want (measurements about how long our middleware is actually taking).

3.) Something else? Does actix have some functionality to help with debugging middleware timing already? Does tracing have features to only concentrate to "pause" a span and continue later?

Hi, I'm a tracing contributor. Before I fully answer your questions, I want to make sure: is the Middleware you're referring to is an implementation of actix_service::Service or something else? I apologize, I'm not fully familiar with Actix.

@endsofthreads Thanks for the response. Sorry, I was mistaken in my original thread, and have corrected it. The middleware I wish to instrument does indeed implement actix_web::dev::Service, which I believe is just a reexport of actix_service::Service.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.