diff --git a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/SpanFactory.java b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/SpanFactory.java index 4bd32292..e3980874 100644 --- a/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/SpanFactory.java +++ b/com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/invokechain/span/SpanFactory.java @@ -49,6 +49,7 @@ private static class TraceIDGen { private volatile AtomicLong count = new AtomicLong(0); public TraceIDGen() { + ip = NetworkHelper.getLocalIP(); } @@ -103,6 +104,8 @@ protected Map initialValue() { } }; + public static final TransmittableThreadLocal mainThreadLocalTracker = new TransmittableThreadLocal(); + /** * 通过一个父span来,创建一个span * @@ -215,6 +218,10 @@ public Map getSpansFromContext() { */ public Span getSpanFromContext(String key) { + if (key.equals("main")) { + return mainThreadLocalTracker.get(); + } + Map spanMap = threadLocalTracker.get(); return spanMap.get(key); @@ -228,6 +235,12 @@ public Span getSpanFromContext(String key) { */ public Span getRemoveSpanFromContext(String key) { + if (key.equals("main")) { + Span span = mainThreadLocalTracker.get(); + mainThreadLocalTracker.remove(); + return span; + } + Map spanMap = threadLocalTracker.get(); return spanMap.remove(key); @@ -240,6 +253,10 @@ public Span getRemoveSpanFromContext(String key) { */ public void setSpanToContext(String key, Span span) { + if (key.equals("main")) { + mainThreadLocalTracker.set(span); + return; + } Map spanMap = threadLocalTracker.get(); spanMap.put(key, span); @@ -250,7 +267,8 @@ public void setSpanToContext(String key, Span span) { */ public void removeCurrentThreadValue() { + mainThreadLocalTracker.removeCurrent(); threadLocalTracker.removeCurrent(); } -} +} \ No newline at end of file