-
Notifications
You must be signed in to change notification settings - Fork 860
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
Implement @WithSpan support for kotlin coroutines #8870
Conversation
.../java/io/opentelemetry/javaagent/tooling/ignore/AdditionalLibraryIgnoredTypesConfigurer.java
Outdated
Show resolved
Hide resolved
...nt/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java
Show resolved
Hide resolved
...nt/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java
Outdated
Show resolved
Hide resolved
...nt/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java
Outdated
Show resolved
Hide resolved
...nt/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java
Outdated
Show resolved
Hide resolved
...nt/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java
Outdated
Show resolved
Hide resolved
...nt/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java
Outdated
Show resolved
Hide resolved
...nt/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java
Outdated
Show resolved
Hide resolved
|
||
public static Context enterCoroutine( | ||
int label, Continuation<?> continuation, MethodRequest request) { | ||
// label 0 means that coroutine is started, any other label means that coroutine is resumed |
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.
Do you know of any documentation/kotlin design doc that'd explain the label
value? I couldn't find any, unfortunately.
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.
https://www.youtube.com/watch?v=YrrUCSi72E8 was useful if I remember correctly (around 7:30 there is something about labels). Basically it should work so that when coroutine is suspended it returns the label where it should be resumed and on resume it is called with the same label.
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.
Thanks! I'll watch that
...nt/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java
Show resolved
Hide resolved
...telemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutinesInstrumentationTest.kt
Show resolved
Hide resolved
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.
👍
This PR will solve the wrong span duration reported at this issue #6502? |
@@ -10,25 +10,35 @@ muzzle { | |||
group.set("org.jetbrains.kotlinx") | |||
module.set("kotlinx-coroutines-core") | |||
versions.set("[1.0.0,1.3.8)") | |||
extraDependency(project(":instrumentation-annotations")) | |||
extraDependency("io.opentelemetry:opentelemetry-api:1.27.0") |
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.
can we also keep the original muzzle definition and use excludeInstrumentationName
, to make sure the kotlin instrumentation is still applied in the absence of these dependencies on the user classpath?
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.
or possibly extract out into separate module?
.../opentelemetry/javaagent/instrumentation/instrumentationannotations/KotlinCoroutineUtil.java
Show resolved
Hide resolved
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Resolves #8812
With kotlin coroutines current
@WithSpan
handling that starts span on method entry and ends it when method exits doesn't work well because method will be exited when it calls a blocking operation and later called again to resume the coroutine. This creates multiple spans for the same method and messes up context propagation. This pr explores an alternative@WithSpan
implementation for coroutines where span is started when method is first called and ended when it returns a result, calls to resume the continuation will only restore the scope and not start a new span.There is also support for the
@SpanAttribute
annotation, but it supports less types than what is supported for the regular@WithSpan
handling. Support for@AddingSpanAttributes
annotation has not been implemented.