Skip to content

Commit c941a32

Browse files
committed
ExecutionContextWrapper
1 parent b3a9372 commit c941a32

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 scala.concurrent.ExecutionContext;
9+
10+
import io.opentelemetry.context.Context;
11+
12+
public class ExecutionContextWrapper implements ExecutionContext {
13+
private final ExecutionContext executionContext;
14+
private final Context otelContext;
15+
16+
public ExecutionContextWrapper(ExecutionContext executionContext, Context otelContext) {
17+
this.executionContext = executionContext;
18+
this.otelContext = otelContext;
19+
}
20+
21+
@Override
22+
public void execute(Runnable runnable) {
23+
executionContext.execute(otelContext.wrap(runnable));
24+
}
25+
26+
@Override
27+
public void reportFailure(Throwable cause) {
28+
executionContext.reportFailure(cause);
29+
}
30+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import net.bytebuddy.description.type.TypeDescription;
1717
import net.bytebuddy.matcher.ElementMatcher;
1818

19+
import scala.concurrent.ExecutionContext;
20+
1921
public class PekkoScheduleInstrumentation implements TypeInstrumentation {
2022

2123
@Override
@@ -39,9 +41,9 @@ public static class ScheduleAdvice {
3941

4042
@Advice.OnMethodEnter(suppress = Throwable.class)
4143
public static void enterSchedule(
42-
@Advice.Argument(value = 2, readOnly = false) Runnable runnable) {
44+
@Advice.Argument(value = 3, readOnly = false) ExecutionContext executionContext) {
4345
Context context = Java8BytecodeBridge.currentContext();
44-
runnable = context.wrap(runnable);
46+
executionContext = new ExecutionContextWrapper(executionContext, context);
4547
}
4648
}
4749
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import net.bytebuddy.description.type.TypeDescription;
1717
import net.bytebuddy.matcher.ElementMatcher;
1818

19+
import scala.concurrent.ExecutionContext;
20+
1921
public class PekkoScheduleOnceInstrumentation implements TypeInstrumentation {
2022

2123
@Override
@@ -38,9 +40,9 @@ public static class ScheduleOnceAdvice {
3840

3941
@Advice.OnMethodEnter(suppress = Throwable.class)
4042
public static void enterScheduleOnce(
41-
@Advice.Argument(value = 1, readOnly = false) Runnable runnable) {
43+
@Advice.Argument(value = 2, readOnly = false) ExecutionContext executionContext) {
4244
Context context = Java8BytecodeBridge.currentContext();
43-
runnable = context.wrap(runnable);
45+
executionContext = new ExecutionContextWrapper(executionContext, context);
4446
}
4547
}
4648
}

0 commit comments

Comments
 (0)