Skip to content

Commit e7381bb

Browse files
committed
update
1 parent 7043602 commit e7381bb

File tree

2 files changed

+23
-16
lines changed
  • instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src

2 files changed

+23
-16
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77

88
import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesGetter;
99
import javax.annotation.Nullable;
10+
import org.springframework.web.method.HandlerMethod;
1011

1112
public class HandlerCodeAttributesGetter implements CodeAttributesGetter<Object> {
1213
@Nullable
1314
@Override
1415
public Class<?> getCodeClass(Object handler) {
15-
return handler.getClass();
16+
if (handler instanceof HandlerMethod) {
17+
// Special case for requests mapped with annotations
18+
HandlerMethod handlerMethod = (HandlerMethod) handler;
19+
return handlerMethod.getMethod().getDeclaringClass();
20+
} else {
21+
return handler.getClass();
22+
}
1623
}
1724

1825
@Nullable

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: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ void basicGetTest(Parameter parameter) {
139139
span.hasKind(SpanKind.INTERNAL)
140140
.hasParent(trace.getSpan(0))
141141
.hasAttributesSatisfyingExactly(
142-
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
142+
equalTo(CODE_FUNCTION, "handle"),
143143
satisfies(
144144
CODE_NAMESPACE,
145145
parameter.annotatedMethod == null
146146
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
147-
: val -> val.endsWith("HandlerMethod")));
147+
: val -> val.isEqualTo(TestController.class.getName())));
148148
}));
149149
}
150150

@@ -259,12 +259,12 @@ void getAsyncResponseTest(Parameter parameter) {
259259
span.hasKind(SpanKind.INTERNAL)
260260
.hasParent(trace.getSpan(0))
261261
.hasAttributesSatisfyingExactly(
262-
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
262+
equalTo(CODE_FUNCTION, "handle"),
263263
satisfies(
264264
CODE_NAMESPACE,
265265
parameter.annotatedMethod == null
266266
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
267-
: val -> val.endsWith("HandlerMethod")));
267+
: val -> val.isEqualTo(TestController.class.getName())));
268268
},
269269
span ->
270270
span.hasName("tracedMethod")
@@ -366,12 +366,12 @@ void createSpanDuringHandlerFunctionTest(Parameter parameter) {
366366
span.hasKind(SpanKind.INTERNAL)
367367
.hasParent(trace.getSpan(0))
368368
.hasAttributesSatisfyingExactly(
369-
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
369+
equalTo(CODE_FUNCTION, "handle"),
370370
satisfies(
371371
CODE_NAMESPACE,
372372
parameter.annotatedMethod == null
373373
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
374-
: val -> val.endsWith("HandlerMethod")));
374+
: val -> val.isEqualTo(TestController.class.getName())));
375375
},
376376
span ->
377377
span.hasName("tracedMethod")
@@ -432,7 +432,7 @@ void get404Test() {
432432
.hasStatus(StatusData.error())
433433
.hasEventsSatisfyingExactly(SpringWebfluxTest::resource404Exception)
434434
.hasAttributesSatisfyingExactly(
435-
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
435+
equalTo(CODE_FUNCTION, "handle"),
436436
equalTo(
437437
CODE_NAMESPACE,
438438
"org.springframework.web.reactive.resource.ResourceWebHandler"))));
@@ -490,7 +490,7 @@ void basicPostTest() {
490490
.hasKind(SpanKind.INTERNAL)
491491
.hasParent(trace.getSpan(0))
492492
.hasAttributesSatisfyingExactly(
493-
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
493+
equalTo(CODE_FUNCTION, "handle"),
494494
satisfies(
495495
CODE_NAMESPACE,
496496
val -> val.isEqualTo("server.EchoHandlerFunction"))),
@@ -550,12 +550,12 @@ void getToBadEndpointTest(Parameter parameter) {
550550
EXCEPTION_STACKTRACE,
551551
val -> val.isInstanceOf(String.class))))
552552
.hasAttributesSatisfyingExactly(
553-
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
553+
equalTo(CODE_FUNCTION, "handle"),
554554
satisfies(
555555
CODE_NAMESPACE,
556556
parameter.annotatedMethod == null
557557
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
558-
: val -> val.endsWith("HandlerMethod")));
558+
: val -> val.isEqualTo(TestController.class.getName())));
559559
}));
560560
}
561561

@@ -610,7 +610,7 @@ void redirectTest() {
610610
.hasKind(SpanKind.INTERNAL)
611611
.hasParent(trace.getSpan(0))
612612
.hasAttributesSatisfyingExactly(
613-
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
613+
equalTo(CODE_FUNCTION, "handle"),
614614
satisfies(
615615
CODE_NAMESPACE,
616616
val -> val.startsWith("server.RedirectComponent$$Lambda")))),
@@ -639,7 +639,7 @@ void redirectTest() {
639639
span.hasKind(SpanKind.INTERNAL)
640640
.hasParent(trace.getSpan(0))
641641
.hasAttributesSatisfyingExactly(
642-
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
642+
equalTo(CODE_FUNCTION, "handle"),
643643
satisfies(
644644
CODE_NAMESPACE,
645645
val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)));
@@ -697,12 +697,12 @@ void multipleGetsToDelayingRoute(Parameter parameter) {
697697
span.hasKind(SpanKind.INTERNAL)
698698
.hasParent(trace.getSpan(0))
699699
.hasAttributesSatisfyingExactly(
700-
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
700+
equalTo(CODE_FUNCTION, "handle"),
701701
satisfies(
702702
CODE_NAMESPACE,
703703
parameter.annotatedMethod == null
704704
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX)
705-
: val -> val.endsWith("HandlerMethod")));
705+
: val -> val.isEqualTo(TestController.class.getName())));
706706
});
707707

708708
testing.waitAndAssertTraces(Collections.nCopies(requestsCount, traceAssertion));
@@ -770,7 +770,7 @@ void cancelRequestTest() throws Exception {
770770
.hasKind(SpanKind.INTERNAL)
771771
.hasParent(trace.getSpan(0))
772772
.hasAttributesSatisfyingExactly(
773-
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")),
773+
equalTo(CODE_FUNCTION, "handle"),
774774
satisfies(
775775
CODE_NAMESPACE,
776776
val ->

0 commit comments

Comments
 (0)