-
Notifications
You must be signed in to change notification settings - Fork 869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add code attributes to spring webflux controller spans and remove spring-webflux.handler.type
#12887
Open
cuichenli
wants to merge
5
commits into
open-telemetry:main
Choose a base branch
from
cuichenli:capture-code-attributes-spring-webflux
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+33
−24
Open
Add code attributes to spring webflux controller spans and remove spring-webflux.handler.type
#12887
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
24b443c
capture code.* resources attributes
cuichenli ee2c31e
remove redundant metric
cuichenli 8e8fbbb
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
cuichenli 33ec295
fix check style error
cuichenli 7043602
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
cuichenli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
|
||
package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server; | ||
|
||
import static io.opentelemetry.api.common.AttributeKey.stringKey; | ||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; | ||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; | ||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; | ||
|
@@ -25,6 +24,8 @@ | |
import static io.opentelemetry.semconv.UrlAttributes.URL_PATH; | ||
import static io.opentelemetry.semconv.UrlAttributes.URL_SCHEME; | ||
import static io.opentelemetry.semconv.UserAgentAttributes.USER_AGENT_ORIGINAL; | ||
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION; | ||
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_NAMESPACE; | ||
import static org.junit.jupiter.api.Named.named; | ||
|
||
import io.opentelemetry.api.trace.SpanKind; | ||
|
@@ -138,11 +139,12 @@ void basicGetTest(Parameter parameter) { | |
span.hasKind(SpanKind.INTERNAL) | ||
.hasParent(trace.getSpan(0)) | ||
.hasAttributesSatisfyingExactly( | ||
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")), | ||
satisfies( | ||
stringKey("spring-webflux.handler.type"), | ||
CODE_NAMESPACE, | ||
parameter.annotatedMethod == null | ||
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX) | ||
: val -> val.isEqualTo(TestController.class.getName()))); | ||
: val -> val.endsWith("HandlerMethod"))); | ||
})); | ||
} | ||
|
||
|
@@ -257,11 +259,12 @@ void getAsyncResponseTest(Parameter parameter) { | |
span.hasKind(SpanKind.INTERNAL) | ||
.hasParent(trace.getSpan(0)) | ||
.hasAttributesSatisfyingExactly( | ||
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")), | ||
satisfies( | ||
stringKey("spring-webflux.handler.type"), | ||
CODE_NAMESPACE, | ||
parameter.annotatedMethod == null | ||
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX) | ||
: val -> val.isEqualTo(TestController.class.getName()))); | ||
: val -> val.endsWith("HandlerMethod"))); | ||
}, | ||
span -> | ||
span.hasName("tracedMethod") | ||
|
@@ -363,11 +366,12 @@ void createSpanDuringHandlerFunctionTest(Parameter parameter) { | |
span.hasKind(SpanKind.INTERNAL) | ||
.hasParent(trace.getSpan(0)) | ||
.hasAttributesSatisfyingExactly( | ||
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")), | ||
satisfies( | ||
stringKey("spring-webflux.handler.type"), | ||
CODE_NAMESPACE, | ||
parameter.annotatedMethod == null | ||
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX) | ||
: val -> val.isEqualTo(TestController.class.getName()))); | ||
: val -> val.endsWith("HandlerMethod"))); | ||
}, | ||
span -> | ||
span.hasName("tracedMethod") | ||
|
@@ -428,8 +432,9 @@ void get404Test() { | |
.hasStatus(StatusData.error()) | ||
.hasEventsSatisfyingExactly(SpringWebfluxTest::resource404Exception) | ||
.hasAttributesSatisfyingExactly( | ||
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")), | ||
equalTo( | ||
stringKey("spring-webflux.handler.type"), | ||
CODE_NAMESPACE, | ||
"org.springframework.web.reactive.resource.ResourceWebHandler")))); | ||
} | ||
|
||
|
@@ -485,9 +490,10 @@ void basicPostTest() { | |
.hasKind(SpanKind.INTERNAL) | ||
.hasParent(trace.getSpan(0)) | ||
.hasAttributesSatisfyingExactly( | ||
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you are testing for exact value use |
||
satisfies( | ||
stringKey("spring-webflux.handler.type"), | ||
val -> val.contains(EchoHandlerFunction.class.getName()))), | ||
CODE_NAMESPACE, | ||
val -> val.isEqualTo("server.EchoHandlerFunction"))), | ||
span -> | ||
span.hasName("echo").hasParent(trace.getSpan(1)).hasTotalAttributeCount(0))); | ||
} | ||
|
@@ -544,11 +550,12 @@ void getToBadEndpointTest(Parameter parameter) { | |
EXCEPTION_STACKTRACE, | ||
val -> val.isInstanceOf(String.class)))) | ||
.hasAttributesSatisfyingExactly( | ||
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")), | ||
satisfies( | ||
stringKey("spring-webflux.handler.type"), | ||
CODE_NAMESPACE, | ||
parameter.annotatedMethod == null | ||
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX) | ||
: val -> val.isEqualTo(TestController.class.getName()))); | ||
: val -> val.endsWith("HandlerMethod"))); | ||
})); | ||
} | ||
|
||
|
@@ -603,8 +610,9 @@ void redirectTest() { | |
.hasKind(SpanKind.INTERNAL) | ||
.hasParent(trace.getSpan(0)) | ||
.hasAttributesSatisfyingExactly( | ||
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")), | ||
satisfies( | ||
stringKey("spring-webflux.handler.type"), | ||
CODE_NAMESPACE, | ||
val -> val.startsWith("server.RedirectComponent$$Lambda")))), | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
|
@@ -631,8 +639,9 @@ void redirectTest() { | |
span.hasKind(SpanKind.INTERNAL) | ||
.hasParent(trace.getSpan(0)) | ||
.hasAttributesSatisfyingExactly( | ||
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")), | ||
satisfies( | ||
stringKey("spring-webflux.handler.type"), | ||
CODE_NAMESPACE, | ||
val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX))); | ||
})); | ||
} | ||
|
@@ -688,11 +697,12 @@ void multipleGetsToDelayingRoute(Parameter parameter) { | |
span.hasKind(SpanKind.INTERNAL) | ||
.hasParent(trace.getSpan(0)) | ||
.hasAttributesSatisfyingExactly( | ||
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")), | ||
satisfies( | ||
stringKey("spring-webflux.handler.type"), | ||
CODE_NAMESPACE, | ||
parameter.annotatedMethod == null | ||
? val -> val.contains(INNER_HANDLER_FUNCTION_CLASS_TAG_PREFIX) | ||
: val -> val.isEqualTo(TestController.class.getName()))); | ||
: val -> val.endsWith("HandlerMethod"))); | ||
}); | ||
|
||
testing.waitAndAssertTraces(Collections.nCopies(requestsCount, traceAssertion)); | ||
|
@@ -760,10 +770,11 @@ void cancelRequestTest() throws Exception { | |
.hasKind(SpanKind.INTERNAL) | ||
.hasParent(trace.getSpan(0)) | ||
.hasAttributesSatisfyingExactly( | ||
satisfies(CODE_FUNCTION, val -> val.isEqualTo("handle")), | ||
satisfies( | ||
stringKey("spring-webflux.handler.type"), | ||
value -> | ||
value.startsWith( | ||
CODE_NAMESPACE, | ||
val -> | ||
val.startsWith( | ||
"server.SpringWebFluxTestApplication$$Lambda"))))); | ||
|
||
SpringWebFluxTestApplication.resumeSlowRequest(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously used
TestController
is more useful thanorg.springframework.web.method.HandlerMethod
that is reported after these changes