Skip to content

Commit 24b443c

Browse files
committed
capture code.* resources attributes
1 parent e002f7a commit 24b443c

File tree

2 files changed

+63
-6
lines changed
  • instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src

2 files changed

+63
-6
lines changed

instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/WebfluxSingletons.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server;
77

88
import io.opentelemetry.api.GlobalOpenTelemetry;
9+
import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesExtractor;
910
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
1011
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
1112
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteGetter;
@@ -32,6 +33,8 @@ public final class WebfluxSingletons {
3233
INSTRUMENTER =
3334
builder
3435
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
36+
.addAttributesExtractor(
37+
CodeAttributesExtractor.create(new HandlerCodeAttributesGetter()))
3538
.buildInstrumenter();
3639
}
3740

instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import static io.opentelemetry.semconv.UrlAttributes.URL_PATH;
2626
import static io.opentelemetry.semconv.UrlAttributes.URL_SCHEME;
2727
import static io.opentelemetry.semconv.UserAgentAttributes.USER_AGENT_ORIGINAL;
28+
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION;
29+
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_NAMESPACE;
2830
import static org.junit.jupiter.api.Named.named;
2931

3032
import io.opentelemetry.api.trace.SpanKind;
@@ -142,7 +144,13 @@ void basicGetTest(Parameter parameter) {
142144
stringKey("spring-webflux.handler.type"),
143145
parameter.annotatedMethod == null
144146
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
145-
: val -> val.isEqualTo(TestController.class.getName())));
147+
: val -> val.isEqualTo(TestController.class.getName())),
148+
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
149+
satisfies(
150+
CODE_NAMESPACE,
151+
parameter.annotatedMethod == null
152+
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
153+
: val -> val.endsWith("HandlerMethod")));
146154
}));
147155
}
148156

@@ -261,7 +269,13 @@ void getAsyncResponseTest(Parameter parameter) {
261269
stringKey("spring-webflux.handler.type"),
262270
parameter.annotatedMethod == null
263271
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
264-
: val -> val.isEqualTo(TestController.class.getName())));
272+
: val -> val.isEqualTo(TestController.class.getName())),
273+
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
274+
satisfies(
275+
CODE_NAMESPACE,
276+
parameter.annotatedMethod == null
277+
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
278+
: val -> val.endsWith("HandlerMethod")));
265279
},
266280
span ->
267281
span.hasName("tracedMethod")
@@ -367,7 +381,13 @@ void createSpanDuringHandlerFunctionTest(Parameter parameter) {
367381
stringKey("spring-webflux.handler.type"),
368382
parameter.annotatedMethod == null
369383
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
370-
: val -> val.isEqualTo(TestController.class.getName())));
384+
: val -> val.isEqualTo(TestController.class.getName())),
385+
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
386+
satisfies(
387+
CODE_NAMESPACE,
388+
parameter.annotatedMethod == null
389+
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
390+
: val -> val.endsWith("HandlerMethod")));
371391
},
372392
span ->
373393
span.hasName("tracedMethod")
@@ -430,6 +450,10 @@ void get404Test() {
430450
.hasAttributesSatisfyingExactly(
431451
equalTo(
432452
stringKey("spring-webflux.handler.type"),
453+
"org.springframework.web.reactive.resource.ResourceWebHandler"),
454+
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
455+
equalTo(
456+
CODE_NAMESPACE,
433457
"org.springframework.web.reactive.resource.ResourceWebHandler"))));
434458
}
435459

@@ -487,7 +511,11 @@ void basicPostTest() {
487511
.hasAttributesSatisfyingExactly(
488512
satisfies(
489513
stringKey("spring-webflux.handler.type"),
490-
val -> val.contains(EchoHandlerFunction.class.getName()))),
514+
val -> val.contains(EchoHandlerFunction.class.getName())),
515+
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
516+
satisfies(
517+
CODE_NAMESPACE,
518+
val -> val.isEqualTo("server.EchoHandlerFunction"))),
491519
span ->
492520
span.hasName("echo").hasParent(trace.getSpan(1)).hasTotalAttributeCount(0)));
493521
}
@@ -548,7 +576,13 @@ void getToBadEndpointTest(Parameter parameter) {
548576
stringKey("spring-webflux.handler.type"),
549577
parameter.annotatedMethod == null
550578
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
551-
: val -> val.isEqualTo(TestController.class.getName())));
579+
: val -> val.isEqualTo(TestController.class.getName())),
580+
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
581+
satisfies(
582+
CODE_NAMESPACE,
583+
parameter.annotatedMethod == null
584+
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
585+
: val -> val.endsWith("HandlerMethod")));
552586
}));
553587
}
554588

@@ -605,6 +639,10 @@ void redirectTest() {
605639
.hasAttributesSatisfyingExactly(
606640
satisfies(
607641
stringKey("spring-webflux.handler.type"),
642+
val -> val.startsWith("server.RedirectComponent$$Lambda")),
643+
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
644+
satisfies(
645+
CODE_NAMESPACE,
608646
val -> val.startsWith("server.RedirectComponent$$Lambda")))),
609647
trace ->
610648
trace.hasSpansSatisfyingExactly(
@@ -633,6 +671,10 @@ void redirectTest() {
633671
.hasAttributesSatisfyingExactly(
634672
satisfies(
635673
stringKey("spring-webflux.handler.type"),
674+
val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)),
675+
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
676+
satisfies(
677+
CODE_NAMESPACE,
636678
val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)));
637679
}));
638680
}
@@ -692,7 +734,13 @@ void multipleGetsToDelayingRoute(Parameter parameter) {
692734
stringKey("spring-webflux.handler.type"),
693735
parameter.annotatedMethod == null
694736
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
695-
: val -> val.isEqualTo(TestController.class.getName())));
737+
: val -> val.isEqualTo(TestController.class.getName())),
738+
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
739+
satisfies(
740+
CODE_NAMESPACE,
741+
parameter.annotatedMethod == null
742+
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
743+
: val -> val.endsWith("HandlerMethod")));
696744
});
697745

698746
testing.waitAndAssertTraces(Collections.nCopies(requestsCount, traceAssertion));
@@ -764,6 +812,12 @@ void cancelRequestTest() throws Exception {
764812
stringKey("spring-webflux.handler.type"),
765813
value ->
766814
value.startsWith(
815+
"server.SpringWebFluxTestApplication$$Lambda")),
816+
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
817+
satisfies(
818+
CODE_NAMESPACE,
819+
val ->
820+
val.startsWith(
767821
"server.SpringWebFluxTestApplication$$Lambda")))));
768822

769823
SpringWebFluxTestApplication.resumeSlowRequest();

0 commit comments

Comments
 (0)