Adapt to observation changes in Framework

See spring-projects/spring-framework#29388
pull/32994/head
Brian Clozel 2 years ago
parent 05c5b1225c
commit 0acaa0e460

@ -56,16 +56,16 @@ class ClientObservationConventionAdapter implements ClientRequestObservationConv
@Override @Override
public KeyValues getLowCardinalityKeyValues(ClientRequestObservationContext context) { public KeyValues getLowCardinalityKeyValues(ClientRequestObservationContext context) {
mutateClientRequest(context); mutateClientRequest(context);
Iterable<Tag> tags = this.tagsProvider.tags(context.getCarrier(), context.getResponse(), context.getError()); Iterable<Tag> tags = this.tagsProvider.tags(context.getRequest(), context.getResponse(), context.getError());
return KeyValues.of(tags, Tag::getKey, Tag::getValue); return KeyValues.of(tags, Tag::getKey, Tag::getValue);
} }
private void mutateClientRequest(ClientRequestObservationContext context) { private void mutateClientRequest(ClientRequestObservationContext context) {
// WebClientExchangeTagsProvider relies on a request attribute to get the URI // WebClientExchangeTagsProvider relies on a request attribute to get the URI
// template, we need to adapt to that. // template, we need to adapt to that.
ClientRequest clientRequest = ClientRequest.from(context.getCarrier()) ClientRequest clientRequest = ClientRequest.from(context.getRequest())
.attribute(URI_TEMPLATE_ATTRIBUTE, context.getUriTemplate()).build(); .attribute(URI_TEMPLATE_ATTRIBUTE, context.getUriTemplate()).build();
context.setCarrier(clientRequest); context.setRequest(clientRequest);
} }
@Override @Override

@ -45,7 +45,7 @@ class ClientObservationConventionAdapterTests {
private ClientObservationConventionAdapter convention = new ClientObservationConventionAdapter(TEST_METRIC_NAME, private ClientObservationConventionAdapter convention = new ClientObservationConventionAdapter(TEST_METRIC_NAME,
new DefaultWebClientExchangeTagsProvider()); new DefaultWebClientExchangeTagsProvider());
private ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/resource/test")).build(); private ClientRequest.Builder requestBuilder = ClientRequest.create(HttpMethod.GET, URI.create("/resource/test"));
private ClientResponse response = ClientResponse.create(HttpStatus.OK).body("foo").build(); private ClientResponse response = ClientResponse.create(HttpStatus.OK).body("foo").build();
@ -54,7 +54,8 @@ class ClientObservationConventionAdapterTests {
@BeforeEach @BeforeEach
void setup() { void setup() {
this.context = new ClientRequestObservationContext(); this.context = new ClientRequestObservationContext();
this.context.setCarrier(this.request); this.context.setCarrier(this.requestBuilder);
this.context.setRequest(this.requestBuilder.build());
this.context.setResponse(this.response); this.context.setResponse(this.response);
this.context.setUriTemplate("/resource/{name}"); this.context.setUriTemplate("/resource/{name}");
} }

Loading…
Cancel
Save