Skip to content

Instantly share code, notes, and snippets.

@jkuipers
Created March 14, 2023 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkuipers/d86cb8de4c3c05bdb7f19f0b4ee18826 to your computer and use it in GitHub Desktop.
Save jkuipers/d86cb8de4c3c05bdb7f19f0b4ee18826 to your computer and use it in GitHub Desktop.
Spring bean definition that ensures that client.name tags are included in HTTP client metrics again
/**
* Starting with Boot 3, the {@code client.name} tag is no longer included by default
* in the {@code http.client.requests} metrics. Restore it by overriding
* {@link DefaultClientRequestObservationConvention#getLowCardinalityKeyValues(ClientRequestObservationContext)}.
*
* @return {@link ClientRequestObservationConvention} that adds the {@code client.name} to the low cardinality key-values.
*/
@Bean
ClientRequestObservationConvention clientNameAddingObservationConvention() {
return new DefaultClientRequestObservationConvention() {
@Override
public KeyValues getLowCardinalityKeyValues(ClientRequestObservationContext context) {
return super.getLowCardinalityKeyValues(context).and(this.clientName(context));
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment