question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to get `ClientRequestContext` without using a decorator.

See original GitHub issue

Currently, a user has to insert a decorator to access the ClientRqeustContext or its RequestLog. For example:

HttpClient client = new HttpClientBuilder(...)
    .decorator((delegate, ctx, req) -> {
        // Access ctx and ctx.log()
    })
    .build();

It would be pretty convenient if a user can do this:

HttpClient client = HttpClient.of(...);
HttpResponse res = client.get("/");
ClientRequestContext ctx = ClientRequestContext.get(res);

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
minwooxcommented, Jul 5, 2019

Had a chat with @trustin and we have to consider RpcResponse as well. Also, there’s a chance that the client is wrapped by another layer, so I think this is a very difficult issue to solve. 😢 We need to think about it a little bit more. 😅

0reactions
minwooxcommented, Dec 18, 2019

Because any implementations of an HttpResponse can be returned using a decorator, I think there are two ways to solve this:

  • Let the HttpResponse have the ClientRequestContext if it’s in the thread-local when the response is created (I think this is not a good choice)
  • Wrap the returned HttpResponse somewhere (perhaps in UserClient?) if it does not have the ClientRequestContext
    // Do not have to wrap this.
    class DecodedHttpResponse extends ... implements RequestContextHolder {...}
    // Other cases.
    class HttpResponseWithClientRequestContext implements HttpResponse, RequestContextHolder {...}
    
    // And getter
    
    public interface ClientRequestContext {
        @Nullable
        ClientRequestContext get(HttpResponse res) {
            if (res instance of RequestContextHolder) {...}
            ...
        }
    }
    

What do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there an elegant way to exit ClientRequestFilter?
I don't use webTarget . I use @RegisterRestClient . And getClient() didn't give me the right thing. There is a method clientRequestContext.
Read more >
ClientRequestContext (RESTEasy JAX-RS 3.0-beta-4 API)
Client request filter context. A mutable class that provides request-specific information for the filter, such as request URI, message headers, ...
Read more >
javax.ws.rs.client.ClientRequestContext.getProperty java code ...
Get the request URI. getMethod. Get the request method. setProperty. Binds an object to a given property name in the current request/response exchange...
Read more >
Add `ClientRequestContext` customizer using `ClientBuilder`
Clients.builder() .addContextCustomizer(ctx -> { // This method is called in a caller thread which invokes a request, // so `Tracing.current().
Read more >
How to associate background threads with request - Scala
I also had to make an implementation of com.newrelic.api.agent.Response which pointed back to the servlet response. All this code was not ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found