Align server contextual names with OTel conventions
This commit ensures that the matching path pattern for the request being
observed is used in the conytextual name, as advised in the OTel HTTP
server semantic conventions.
If the path pattern is not available, no additional value is provided
and the "http {method}" baseline is being used.
Fixes gh-29424
This commit is contained in:
parent
db79d1d2b9
commit
a94b0e51e2
|
|
@ -76,6 +76,10 @@ public class DefaultServerRequestObservationConvention implements ServerRequestO
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getContextualName(ServerRequestObservationContext context) {
|
public String getContextualName(ServerRequestObservationContext context) {
|
||||||
|
if (context.getPathPattern() != null) {
|
||||||
|
return String.format("http %s %s", context.getCarrier().getMethod().toLowerCase(),
|
||||||
|
context.getPathPattern());
|
||||||
|
}
|
||||||
return "http " + context.getCarrier().getMethod().toLowerCase();
|
return "http " + context.getCarrier().getMethod().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,10 @@ public class DefaultServerRequestObservationConvention implements ServerRequestO
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getContextualName(ServerRequestObservationContext context) {
|
public String getContextualName(ServerRequestObservationContext context) {
|
||||||
|
if (context.getPathPattern() != null) {
|
||||||
|
return String.format("http %s %s", context.getCarrier().getMethod().name().toLowerCase(),
|
||||||
|
context.getPathPattern().toString());
|
||||||
|
}
|
||||||
return "http " + context.getCarrier().getMethod().name().toLowerCase();
|
return "http " + context.getCarrier().getMethod().name().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,12 @@ class DefaultServerRequestObservationConventionTests {
|
||||||
assertThat(convention.getContextualName(this.context)).isEqualTo("http get");
|
assertThat(convention.getContextualName(this.context)).isEqualTo("http get");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextualNameShouldUsePathPatternWhenAvailable() {
|
||||||
|
this.context.setPathPattern("/test/{name}");
|
||||||
|
assertThat(convention.getContextualName(this.context)).isEqualTo("http get /test/{name}");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void supportsOnlyHttpRequestsObservationContext() {
|
void supportsOnlyHttpRequestsObservationContext() {
|
||||||
assertThat(this.convention.supportsContext(this.context)).isTrue();
|
assertThat(this.convention.supportsContext(this.context)).isTrue();
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,14 @@ class DefaultServerRequestObservationConventionTests {
|
||||||
assertThat(convention.getContextualName(context)).isEqualTo("http get");
|
assertThat(convention.getContextualName(context)).isEqualTo("http get");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextualNameShouldUsePathPatternWhenAvailable() {
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/test/resource"));
|
||||||
|
ServerRequestObservationContext context = new ServerRequestObservationContext(exchange);
|
||||||
|
context.setPathPattern(PathPatternParser.defaultInstance.parse("/test/{name}"));
|
||||||
|
assertThat(convention.getContextualName(context)).isEqualTo("http get /test/{name}");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void supportsOnlyHttpRequestsObservationContext() {
|
void supportsOnlyHttpRequestsObservationContext() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/test/resource"));
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/test/resource"));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue