-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
115 additions
and
59 deletions.
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
43 changes: 0 additions & 43 deletions
43
...aagent/instrumentation/kotlinxcoroutines/reactor/KotlinCoroutinesMonoInstrumentation.java
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
...strumentation/kotlinxcoroutines/reactor/KotlinCoroutinesReactorInstrumentationModule.java
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.kotlinxcoroutines.reactor; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
import com.google.auto.service.AutoService; | ||
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import java.util.List; | ||
|
||
@AutoService(InstrumentationModule.class) | ||
public class KotlinCoroutinesReactorInstrumentationModule extends InstrumentationModule { | ||
|
||
public KotlinCoroutinesReactorInstrumentationModule() { | ||
super("kotlinx-coroutines", "kotlinx-coroutines-reactor"); | ||
} | ||
|
||
@Override | ||
public boolean isHelperClass(String className) { | ||
return className.startsWith("io.opentelemetry.extension.kotlin."); | ||
} | ||
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return asList( | ||
new KotlinMonoCoroutineInstrumentation(), new KotlinPublisherCoroutineInstrumentation()); | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
...nt/instrumentation/kotlinxcoroutines/reactor/KotlinPublisherCoroutineInstrumentation.java
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.kotlinxcoroutines.reactor; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.reactor.ContextPropagationOperator; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; | ||
import io.opentelemetry.javaagent.instrumentation.kotlinxcoroutines.KotlinCoroutinesInstrumentationHelper; | ||
import kotlin.coroutines.CoroutineContext; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import org.reactivestreams.Subscriber; | ||
import reactor.core.CoreSubscriber; | ||
|
||
public class KotlinPublisherCoroutineInstrumentation implements TypeInstrumentation { | ||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return namedOneOf("kotlinx.coroutines.reactive.PublisherCoroutine"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isConstructor() | ||
.and( | ||
takesArgument(0, named("kotlin.coroutines.CoroutineContext")) | ||
.and(takesArgument(1, named("org.reactivestreams.Subscriber")))), | ||
this.getClass().getName() + "$PublisherCoroutineAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class PublisherCoroutineAdvice { | ||
|
||
@Advice.OnMethodEnter | ||
public static void enter( | ||
@Advice.Argument(value = 0, readOnly = false) CoroutineContext coroutineContext, | ||
@Advice.Argument(1) Subscriber<?> subscriber) { | ||
if (subscriber instanceof CoreSubscriber) { | ||
CoreSubscriber<?> coreSubscriber = (CoreSubscriber) subscriber; | ||
Context context = | ||
ContextPropagationOperator.getOpenTelemetryContext( | ||
coreSubscriber.currentContext(), Java8BytecodeBridge.currentContext()); | ||
coroutineContext = | ||
KotlinCoroutinesInstrumentationHelper.addOpenTelemetryContext(coroutineContext); | ||
} | ||
} | ||
} | ||
} |