Skip to content

apache httpclient 5 - http calls done in interceptors not instrumented #10383

Open

Description

@kroonprins

Tracer Version(s)

1.57.0

Java Version(s)

25

JVM Vendor

Eclipse Adoptium / Temurin

Bug Report

When using apache httpclient v5, it is possible to do http requests from with exec interceptors (type org.apache.hc.client5.http.classic.ExecChainHandler) added on a http client. This is e.g. useful for fetching a token to add it as a header on a requests. The requests done in such an interceptor are not instrumented because of this if. Would it be possible to fix this, so that traces do not miss http calls?

Expected Behavior

All http calls are recorded in the trace, even when they are executed from within an interceptor.

Reproduction Code

        try(CloseableHttpClient httpClient = HttpClientBuilder.create()
                .addExecInterceptorLast("interceptor", (request, scope, chain) -> {
                    CloseableHttpClient tokenHttpClient = HttpClientBuilder.create().build();
                    String token = tokenHttpClient.execute(new HttpGet("..."), resp -> {
                        // ...
                        return fetchedToken;
                    });
                    request.addHeader("x-token", token);
                    return chain.proceed(request, scope);
                })
                .build()) {
            httpClient.execute(new HttpGet("..."), response -> {
                // ...
                return null;
            });
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions