Skip to content

Commit b4aebf8

Browse files
authored
Widen lazy coroutine matcher to cover all definitions of onStart (#8838)
1 parent 0ef8c26 commit b4aebf8

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

dd-java-agent/instrumentation/kotlin-coroutines/src/main/java/datadog/trace/instrumentation/kotlin/coroutines/LazyCoroutineInstrumentation.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
package datadog.trace.instrumentation.kotlin.coroutines;
22

3+
import static datadog.trace.agent.tooling.bytebuddy.matcher.HierarchyMatchers.extendsClass;
34
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
45
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
6+
import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments;
57

68
import datadog.trace.agent.tooling.Instrumenter;
79
import kotlinx.coroutines.AbstractCoroutine;
810
import net.bytebuddy.asm.Advice;
11+
import net.bytebuddy.description.type.TypeDescription;
12+
import net.bytebuddy.matcher.ElementMatcher;
913

1014
/** Captures the Datadog context when lazy coroutines start. */
1115
public class LazyCoroutineInstrumentation
12-
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice {
16+
implements Instrumenter.ForTypeHierarchy, Instrumenter.HasMethodAdvice {
1317

1418
@Override
15-
public String instrumentedType() {
16-
return "kotlinx.coroutines.LazyDeferredCoroutine";
19+
public String hierarchyMarkerType() {
20+
return "kotlinx.coroutines.AbstractCoroutine";
21+
}
22+
23+
@Override
24+
public ElementMatcher<TypeDescription> hierarchyMatcher() {
25+
return extendsClass(named(hierarchyMarkerType()));
1726
}
1827

1928
@Override
2029
public void methodAdvice(MethodTransformer transformer) {
2130
transformer.applyAdvice(
22-
isMethod().and(named("onStart")),
31+
isMethod().and(named("onStart")).and(takesNoArguments()),
2332
LazyCoroutineInstrumentation.class.getName() + "$OnStartAdvice");
2433
}
2534

0 commit comments

Comments
 (0)