Feign: Expose uri template information in a RequestInterceptor

Created on 10 Jan 2019  ·  10Comments  ·  Source: OpenFeign/feign

Hi there,

I'm looking for a way to access the request pattern url called in a logging interceptor.

Precisely, I need to get the raw url filled in @RequestLine annotation on the client class...

Is that possible ?
Best regards

feign-11 proposal waiting for votes

Most helpful comment

@pilak do you think this change would help?
https://github.com/OpenFeign/feign/pull/1091/files

All 10 comments

Are you looking for the uri template used or the resolved value?

I have a question like this. Is there some way to access uri template from RequestTemplate? Do you have any suggestions for me?

@kdavisk6 The raw template uri (before resolved).

We also want to record requestTemplate.url() as a tag in a micrometer's Timer.

Currently, we have to do in the following way:

  1. wireup a interceptor to put the url into headers:
    template -> template.header(ORIGINAL_URI_HEADER, template.url())

  2. wireup a client to access the value and then remove it from headers:

String originalUrl = null;
Map<String, Collection<String>> headers = request.headers();
if (headers.containsKey(ORIGINAL_URI_HEADER)) {
    Collection<String> originalUrlHeaders = headers.get(ORIGINAL_URI_HEADER);
    if (!originalUrlHeaders.isEmpty()) {
        originalUrl = originalUrlHeaders.iterator().next();
        // recreate request because of immutable headers
        val newHeaders = new HashMap<String, Collection<String>>(headers);
        newHeaders.remove(ORIGINAL_URI_HEADER);
        request = Request.create(request.method(), request.url(), newHeaders, request.body(), request.charset());
    }
}

Any suggestions? Thanks!

@flisky

By the time the RequestTemplate makes it to the interceptor, it resolved. I'm unclear what value the unresolved uri template brings. Can you give me context?

Quoted from @whiskeysierra

Feign doesn't expose the URI template which significantly reduces the usefulness of the Micrometer and OpenTracing integration since both use the URI template as tags

The request would be aggregated by the unresolved uri template. And a time-series database could be exploded due to a high-cardinality tag.

@flisky

Thank you for that clarification. Is there another issue where that quote is from? I'd like to review it further to get a better understanding of what the desired outcome is.

It's from zalando/riptide#618.

By the way, I'm hoping there's something like context or request#attributes to hook up the uri template, rather than passing it over headers (the request headers are immutable, you know, a little bit hacky).

Regarding to #937, I think it's a better way to passing extra information through fragment, and fragment will be stripped off by http client automatically.

However, after a deeper investigating, the RequestTemplate is resolved before intercepting, and it means we actually cannot access the raw url template :(

Any suggestion, @kdavisk6?

@flisky

Up until this point, there has been no real need to expose the uri template. I've updated this issue to reflect that we may want to consider exposing the uri template on the RequestTemplate.

For this proposal to move forward, we will need the following:

  • Votes. Simply 👍 the original comment.
  • A proposed solution. Please add a comment outlining how we could achieve this.

With those in place, the maintainers and I will work with you to narrow down the scope and agree on an approach. Once agreed, we will open this issue up for PR.

@pilak do you think this change would help?
https://github.com/OpenFeign/feign/pull/1091/files

Was this page helpful?
0 / 5 - 0 ratings