Hi,

At Allegro we have services which create multiple instances of HTTP clients (e.g. RestClient) and would like to have a more distinguishable name in metrics (in cases when default uri.host() can be vague), thus we would like to have client-names per HTTP client in metrics. I would generally do something like this:

@Bean
RestClient example(RestClient.Builder clientBuilder) {
     return  clientBuilder
        .observationConvention(new NamedClientRequestObservationConvention("my-client"));
}

but it then gets overridden by ObservationRestClientCustomizer, which seems to always override a convention with a global instance (either default, or custom provided).

Suggestion for enhancement:

  • either do not override observationConvention in clients if it is already set (not null)
  • or allow to disable ObservationRestClientCustomizer

Comment From: mhalbritter

As a workaround, you can exclude the RestClientObservationAutoConfiguration, which applies the ObservationRestClientCustomizer. Make sure to set ObservationRegistry on the client in your custom logic then.

either do not override observationConvention in clients if it is already set (not null)

That would be my favorite way, however the org.springframework.web.client.RestClient.Builder doesn't let us check if there is already a observationConvention set. Maybe we could change that. @bclozel what do you think?

Comment From: aleksandrserbin

Sorry for the confusion, it appears that the example above actually works 😅 Now I've lost the understanding of why it wasn't, RestClientCustomizers are applied to Builder before the it reaches "userspace" code, so it looks like the issue is not relevant.

Comment From: mhalbritter

Ok, let's close it then. If you happen to find the original case, please let us know and we re-open the issue.