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

Store retries count in http::extension::Extensions #152

Open
aimericsr opened this issue May 19, 2024 · 0 comments
Open

Store retries count in http::extension::Extensions #152

aimericsr opened this issue May 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@aimericsr
Copy link

Motivations

I tried to register a new field http.request.resend_count to my Otel trace but I don't have access to this information by implementing ReqwestOtelSpanBackend.

Solution

Register the number of retries in the extension of the current request.

Alternatives

I tried to inspect the logs message of the current Span inside the on_request_end() function to get this data from the
warn event but it's tedious and I don't think it's even possible.

Additional context

Here is my current code

impl ReqwestOtelSpanBackend for OtelTrace {
    fn on_request_start(req: &Request, extension: &mut Extensions) -> Span {
        let otel_span_name = format!("{:#?} {:#?}", req.method(), req.url().path())
            .trim()
            .to_owned();
        reqwest_otel_span!(
            level = Level::INFO,
            name = otel_span_name,
            req,
            url.full = req.url().to_string(),
            http.request.resend_count = tracing::field::Empty,
        )
    }

    fn on_request_end(span: &Span, outcome: &ResultReqwest<Response>, extension: &mut Extensions) {
        // This would be someting like this
        let retries = extension.get::<RequestRetries>().unwrap().count;
        span.record("http.request.resend_count", retries);
        default_on_request_end(span, outcome);
    }
}

I could take the PR if it sounds good for you.

@aimericsr aimericsr added the enhancement New feature or request label May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant