LukeMathWalker/tracing-actix-web

Constrain type parameter of `RootSpanBuilder::on_request_end` with `actix_web::body::MessageBody`

rharish101 opened this issue · 3 comments

Is it possible to change the API to change the following in RootSpanBuilder:

fn on_request_end<B>(span: Span, outcome: &Result<ServiceResponse<B>, Error>);

to the following?:

fn on_request_end<B: MessageBody>(span: Span, outcome: &Result<ServiceResponse<B>, Error>);

This will allow using methods defined for MessageBody when creating custom RootSpanBuilders, such as MessageBody::size. The root span is always called on MessageBodys anyway, as seen here:

impl<F, B, RootSpanType> Future for TracingResponse<F, RootSpanType>
where
F: Future<Output = Result<ServiceResponse<B>, Error>>,
B: MessageBody + 'static,
RootSpanType: RootSpanBuilder,
{
type Output = Result<ServiceResponse<StreamSpan<B>>, Error>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
let fut = this.fut;
let span = this.span;
span.in_scope(|| match fut.poll(cx) {
Poll::Pending => Poll::Pending,
Poll::Ready(outcome) => {
RootSpanType::on_request_end(Span::current(), &outcome);

I can create a PR if this is fine.

Yes, a PR would be welcome!

I've created PR #93 to solve this.

Merged and released as 0.7.0 - thanks!