Skip to content

Commit fecf3fa

Browse files
authored
Disable coroutine WithSpan by default in v3 preview (#18919)
1 parent 2d3f000 commit fecf3fa

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,15 @@ kotlin {
5353
javaParameters = true
5454
}
5555
}
56+
57+
tasks {
58+
val testV3Preview by registering(Test::class) {
59+
testClassesDirs = sourceSets.test.get().output.classesDirs
60+
classpath = sourceSets.test.get().runtimeClasspath
61+
jvmArgs("-Dotel.instrumentation.common.v3-preview=true")
62+
}
63+
64+
check {
65+
dependsOn(testV3Preview)
66+
}
67+
}

instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/v1_0/instrumentationannotations/AnnotationInstrumentationModule.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static java.util.Collections.singletonList;
1010

1111
import com.google.auto.service.AutoService;
12+
import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig;
1213
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1314
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1415
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
@@ -34,6 +35,11 @@ public int order() {
3435
return 1000;
3536
}
3637

38+
@Override
39+
public boolean defaultEnabled() {
40+
return super.defaultEnabled() && !AgentCommonConfig.get().isV3Preview();
41+
}
42+
3743
@Override
3844
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
3945
return hasClassesNamed(

instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/v1_0/KotlinCoroutinesInstrumentationTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class KotlinCoroutinesInstrumentationTest {
8080

8181
val tracer = testing.openTelemetry.getTracer("test")
8282

83+
private fun v3Preview(): Boolean = java.lang.Boolean.getBoolean("otel.instrumentation.common.v3-preview")
84+
8385
@ParameterizedTest
8486
@MethodSource("dispatchersSourceArguments")
8587
fun `cancellation prevents trace`(dispatcher: DispatcherWrapper) {
@@ -377,6 +379,11 @@ class KotlinCoroutinesInstrumentationTest {
377379
annotated1()
378380
}
379381

382+
if (v3Preview()) {
383+
assertThat(testing.spans()).isEmpty()
384+
return
385+
}
386+
380387
val assertions = codeFunctionAssertions(this.javaClass, "annotated2")
381388
assertions.add(equalTo(AttributeKey.longKey("byteValue"), 1))
382389
assertions.add(equalTo(AttributeKey.longKey("intValue"), 4))
@@ -439,6 +446,11 @@ class KotlinCoroutinesInstrumentationTest {
439446
classDefaultConstructorArguments.sayHello()
440447
}
441448

449+
if (v3Preview()) {
450+
assertThat(testing.spans()).isEmpty()
451+
return
452+
}
453+
442454
testing.waitAndAssertTraces(
443455
{ trace ->
444456
trace.hasSpansSatisfyingExactly(

instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
description: >
22
This instrumentation enables context propagation for Kotlin coroutines and adds support for
3-
@WithSpan annotations on Kotlin suspend functions.
3+
@WithSpan annotations on Kotlin suspend functions by default unless v3 preview mode is enabled.
44
display_name: Kotlin Coroutines
55
features:
66
- CONTEXT_PROPAGATION

0 commit comments

Comments
 (0)