Skip to content

Update WebClient metrics auto-configuration to the new Observation instrumentation #32518

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

Closed
bclozel opened this issue Sep 27, 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 27, 2022

Since spring-projects/spring-framework#28341, Spring Framework now instruments directly WebClient, removing the need for a custom ExchangeFunction.

With this issue, we should update the auto-configuration to only rely on the new ObservationRegistry and configure the instrumentation available on WebClient. 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
Copy link
Member Author

bclozel commented Sep 30, 2022

As part of this change, we've deprecated DefaultWebClientExchangeTagsProvider, WebClientExchangeTagsProvider and WebClientExchangeTags.

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 DefaultWebClientExchangeTagsProvider, we can here extend the DefaultClientObservationConvention and override the methods we want.

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

public class CustomClientObservationConvention extends DefaultClientObservationConvention
		implements GlobalObservationConvention<ClientObservationContext> {

	@Override
	public KeyValues getLowCardinalityKeyValues(ClientObservationContext context) {
		KeyValues keyValues = super.getLowCardinalityKeyValues(context);
		ClientRequest request = context.getCarrier();
		return keyValues.and("httpMethod", request.method().name());
	}

}

bclozel added a commit that referenced this issue Sep 30, 2022
bclozel added a commit that referenced this issue Sep 30, 2022
bclozel added a commit that referenced this issue Sep 30, 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