Skip to content

Commit 10f235b

Browse files
committed
pekko: propagate context for schedule/scheduleOnce
class names
1 parent 350e03c commit 10f235b

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

instrumentation/pekko/pekko-actor-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkoactor/v1_0/PekkoActorInstrumentationModule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public List<TypeInstrumentation> typeInstrumentations() {
2323
return asList(
2424
new PekkoDispatcherInstrumentation(),
2525
new PekkoActorCellInstrumentation(),
26-
new PekkoDefaultSystemMessageQueueInstrumentation());
26+
new PekkoDefaultSystemMessageQueueInstrumentation(),
27+
new PekkoScheduleInstrumentation(),
28+
new PekkoScheduleOnceInstrumentation());
2729
}
2830
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.pekkoactor.v1_0;
7+
8+
import static net.bytebuddy.matcher.ElementMatchers.named;
9+
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
10+
11+
import io.opentelemetry.context.Context;
12+
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
13+
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
14+
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
15+
import net.bytebuddy.asm.Advice;
16+
import net.bytebuddy.description.type.TypeDescription;
17+
import net.bytebuddy.matcher.ElementMatcher;
18+
19+
public class PekkoScheduleInstrumentation implements TypeInstrumentation {
20+
21+
@Override
22+
public ElementMatcher<TypeDescription> typeMatcher() {
23+
return named("org.apache.pekko.actor.Scheduler");
24+
}
25+
26+
@Override
27+
public void transform(TypeTransformer transformer) {
28+
transformer.applyAdviceToMethod(
29+
named("schedule")
30+
.and(takesArgument(0, named("scala.concurrent.duration.FiniteDuration")))
31+
.and(takesArgument(1, named("scala.concurrent.duration.FiniteDuration")))
32+
.and(takesArgument(2, named("java.lang.Runnable")))
33+
.and(takesArgument(3, named("scala.concurrent.ExecutionContext"))),
34+
PekkoScheduleInstrumentation.class.getName() + "$ScheduleAdvice");
35+
}
36+
37+
@SuppressWarnings("unused")
38+
public static class ScheduleAdvice {
39+
40+
@Advice.OnMethodEnter(suppress = Throwable.class)
41+
public static void enterScheduleOnce(
42+
@Advice.Argument(value = 2, readOnly = false) Runnable runnable) {
43+
Context context = Java8BytecodeBridge.currentContext();
44+
runnable = context.wrap(runnable);
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.pekkoactor.v1_0;
7+
8+
import static net.bytebuddy.matcher.ElementMatchers.named;
9+
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
10+
11+
import io.opentelemetry.context.Context;
12+
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
13+
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
14+
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
15+
import net.bytebuddy.asm.Advice;
16+
import net.bytebuddy.description.type.TypeDescription;
17+
import net.bytebuddy.matcher.ElementMatcher;
18+
19+
public class PekkoScheduleOnceInstrumentation implements TypeInstrumentation {
20+
21+
@Override
22+
public ElementMatcher<TypeDescription> typeMatcher() {
23+
return named("org.apache.pekko.actor.Scheduler");
24+
}
25+
26+
@Override
27+
public void transform(TypeTransformer transformer) {
28+
transformer.applyAdviceToMethod(
29+
named("scheduleOnce")
30+
.and(takesArgument(0, named("scala.concurrent.duration.FiniteDuration")))
31+
.and(takesArgument(1, named("java.lang.Runnable")))
32+
.and(takesArgument(2, named("scala.concurrent.ExecutionContext"))),
33+
PekkoScheduleOnceInstrumentation.class.getName() + "$ScheduleOnceAdvice");
34+
}
35+
36+
@SuppressWarnings("unused")
37+
public static class ScheduleOnceAdvice {
38+
39+
@Advice.OnMethodEnter(suppress = Throwable.class)
40+
public static void enterScheduleOnce(
41+
@Advice.Argument(value = 1, readOnly = false) Runnable runnable) {
42+
Context context = Java8BytecodeBridge.currentContext();
43+
runnable = context.wrap(runnable);
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)