Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RestTemplate metrics auto-configuration to the new Observation instrumentation #32484

Closed
bclozel opened this issue Sep 23, 2022 · 1 comment
Assignees
Labels
theme: observability Issues related to observability type: enhancement A general enhancement
Milestone

Comments

@bclozel
Copy link
Member

bclozel commented Sep 23, 2022

Since spring-projects/spring-framework#28341, Spring Framework now instruments directly RestTemplate, removing the need for a custom request interceptor (with well known limitations).

With this issue, we should update the auto-configuration to only rely on the new ObservationRegistry and configure the instrumentation available on RestTemplate. We need to provide a smooth upgrade experience: deprecate the tags providers and adapt them to the new infrastructure until it's completely removed.

@bclozel bclozel added type: enhancement A general enhancement theme: observability Issues related to observability labels Sep 23, 2022
@bclozel bclozel added this to the 3.0.0-RC1 milestone Sep 23, 2022
@bclozel bclozel self-assigned this Sep 23, 2022
@bclozel
Copy link
Member Author

bclozel commented Sep 27, 2022

As part of this change, we've deprecated DefaultRestTemplateExchangeTagsProvider, RestTemplateExchangeTagsProvider and RestTemplateExchangeTags.

If an application needs to change the KeyValues (formerly Tags) for this observation, you can contribute a bean of type GlobalObservationConvention for the observation context we're considering.
Instead of inheriting from DefaultRestTemplateExchangeTagsProvider, we can here extend the DefaultClientHttpObservationConvention and override the methods we want.

Here, let's add a "httpMethod" keyvalue by extracting the value from the request:

public class CustomClientHttpObservationConvention extends DefaultClientHttpObservationConvention
		implements GlobalObservationConvention<ClientHttpObservationContext> {

	@Override
	public KeyValues getLowCardinalityKeyValues(ClientHttpObservationContext context) {
		KeyValues keyValues = super.getLowCardinalityKeyValues(context);
		ClientHttpRequest request = context.getCarrier();
		return keyValues.and("httpMethod", request.getMethod().name());
	}

}

bclozel added a commit that referenced this issue Sep 27, 2022
izeye added a commit to izeye/spring-boot that referenced this issue Oct 7, 2022
bclozel pushed a commit that referenced this issue Oct 7, 2022
bclozel added a commit that referenced this issue Oct 19, 2022
This commit moves the observation auto-configuration from the metrics
package to the observation package for consistency.

See gh-32484
See gh-32518
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: observability Issues related to observability type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant