Add context propagation debug info in ContextPropagatingRunnable (#9339)

This commit is contained in:
Lauri Tulmin 2023-08-31 06:20:30 +03:00 committed by GitHub
parent b2fcb76a66
commit 57e957d7a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -56,6 +56,15 @@ public final class ContextPropagationDebug {
return THREAD_PROPAGATION_DEBUGGER;
}
public static Context addDebugInfo(Context context, Object carrier) {
if (ContextPropagationDebug.isThreadPropagationDebuggerEnabled()) {
context =
ContextPropagationDebug.appendLocations(
context, new Exception().getStackTrace(), carrier);
}
return context;
}
public static Context appendLocations(
Context context, StackTraceElement[] locations, Object carrier) {
ContextPropagationDebug propagationDebug = ContextPropagationDebug.getPropagations(context);

View File

@ -7,6 +7,7 @@ package io.opentelemetry.javaagent.bootstrap.executors;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.internal.ContextPropagationDebug;
public final class ContextPropagatingRunnable implements Runnable {
@ -27,7 +28,7 @@ public final class ContextPropagatingRunnable implements Runnable {
private ContextPropagatingRunnable(Runnable delegate, Context context) {
this.delegate = delegate;
this.context = context;
this.context = ContextPropagationDebug.addDebugInfo(context, delegate);
}
@Override

View File

@ -62,10 +62,7 @@ public final class ExecutorAdviceHelper {
}
}
if (ContextPropagationDebug.isThreadPropagationDebuggerEnabled()) {
context =
ContextPropagationDebug.appendLocations(context, new Exception().getStackTrace(), task);
}
context = ContextPropagationDebug.addDebugInfo(context, task);
propagatedContext.setContext(context);
return propagatedContext;
}