Do not overwrite attributes in ClientObservationConventionAdapter

Prior to this commit, the `ClientObservationConventionAdapter` would
overwrite a request builder attribute. This would happen when the
request is not fully built when the observation starts. At that point,
the tags are built for long task timers, but not for the actual metric.
This effectively overrides the correct value of the URI template in the
builder.

This commit removes this builder update which was invalid in the first
place.

Fixes gh-40330
This commit is contained in:
Brian Clozel 2024-04-12 16:31:02 +02:00
parent 12e004f131
commit 24f80154d4
2 changed files with 4 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -57,7 +57,7 @@ class ClientObservationConventionAdapter implements ClientRequestObservationConv
public KeyValues getLowCardinalityKeyValues(ClientRequestObservationContext context) {
ClientRequest request = context.getRequest();
if (request == null) {
request = context.getCarrier().attribute(URI_TEMPLATE_ATTRIBUTE, context.getUriTemplate()).build();
request = context.getCarrier().build();
}
Iterable<Tag> tags = this.tagsProvider.tags(request, context.getResponse(), context.getError());
return KeyValues.of(tags, Tag::getKey, Tag::getValue);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -83,6 +83,7 @@ class ClientObservationConventionAdapterTests {
@Test
void doesNotFailWithEmptyRequest() {
this.context.setUriTemplate(null);
assertThat(this.convention.getLowCardinalityKeyValues(this.context)).contains(KeyValue.of("status", "200"),
KeyValue.of("outcome", "SUCCESS"), KeyValue.of("uri", "/resource/{name}"),
KeyValue.of("method", "GET"));