Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
package datadog.trace.instrumentation.kotlin.coroutines;

import static datadog.trace.agent.tooling.bytebuddy.matcher.HierarchyMatchers.extendsClass;
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments;

import datadog.trace.agent.tooling.Instrumenter;
import kotlinx.coroutines.AbstractCoroutine;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

/** Captures the Datadog context when lazy coroutines start. */
public class LazyCoroutineInstrumentation
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice {
implements Instrumenter.ForTypeHierarchy, Instrumenter.HasMethodAdvice {

@Override
public String instrumentedType() {
return "kotlinx.coroutines.LazyDeferredCoroutine";
public String hierarchyMarkerType() {
return "kotlinx.coroutines.AbstractCoroutine";
}

@Override
public ElementMatcher<TypeDescription> hierarchyMatcher() {
return extendsClass(named(hierarchyMarkerType()));
}

@Override
public void methodAdvice(MethodTransformer transformer) {
transformer.applyAdvice(
isMethod().and(named("onStart")),
isMethod().and(named("onStart")).and(takesNoArguments()),
LazyCoroutineInstrumentation.class.getName() + "$OnStartAdvice");
}

Expand Down
Loading