Skip to content

Commit 57e957d

Browse files
authored
Add context propagation debug info in ContextPropagatingRunnable (#9339)
1 parent b2fcb76 commit 57e957d

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/ContextPropagationDebug.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public static boolean isThreadPropagationDebuggerEnabled() {
5656
return THREAD_PROPAGATION_DEBUGGER;
5757
}
5858

59+
public static Context addDebugInfo(Context context, Object carrier) {
60+
if (ContextPropagationDebug.isThreadPropagationDebuggerEnabled()) {
61+
context =
62+
ContextPropagationDebug.appendLocations(
63+
context, new Exception().getStackTrace(), carrier);
64+
}
65+
return context;
66+
}
67+
5968
public static Context appendLocations(
6069
Context context, StackTraceElement[] locations, Object carrier) {
6170
ContextPropagationDebug propagationDebug = ContextPropagationDebug.getPropagations(context);

instrumentation/executors/bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/executors/ContextPropagatingRunnable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import io.opentelemetry.context.Context;
99
import io.opentelemetry.context.Scope;
10+
import io.opentelemetry.instrumentation.api.internal.ContextPropagationDebug;
1011

1112
public final class ContextPropagatingRunnable implements Runnable {
1213

@@ -27,7 +28,7 @@ public static Runnable propagateContext(Runnable task, Context context) {
2728

2829
private ContextPropagatingRunnable(Runnable delegate, Context context) {
2930
this.delegate = delegate;
30-
this.context = context;
31+
this.context = ContextPropagationDebug.addDebugInfo(context, delegate);
3132
}
3233

3334
@Override

instrumentation/executors/bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/executors/ExecutorAdviceHelper.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ public static <T> PropagatedContext attachContextToTask(
6262
}
6363
}
6464

65-
if (ContextPropagationDebug.isThreadPropagationDebuggerEnabled()) {
66-
context =
67-
ContextPropagationDebug.appendLocations(context, new Exception().getStackTrace(), task);
68-
}
65+
context = ContextPropagationDebug.addDebugInfo(context, task);
6966
propagatedContext.setContext(context);
7067
return propagatedContext;
7168
}

0 commit comments

Comments
 (0)