From 3f88d735ba2bfd1196aff946502447d4b14450c8 Mon Sep 17 00:00:00 2001 From: Lisandro Date: Thu, 15 Sep 2022 08:02:25 +0800 Subject: [PATCH] [Bug #9598] Apache ShenYu agent Tid is null (#309) --- CHANGES.md | 1 + .../shenyu/v24x/GlobalPluginExecuteMethodInterceptor.java | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bcd3a46f2..830f16edd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Release Notes. * Support to set the value of Map/List field to an empty map/list. * Add plugin to support [Impala JDBC](https://www.cloudera.com/downloads/connectors/impala/jdbc/2-6-29.html) 2.6.x. * Update guava-cache, jedis, memcached, ehcache plugins to adopt uniform tags. +* Fix `Apache ShenYu` plugin traceId empty string value. #### Documentation diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/GlobalPluginExecuteMethodInterceptor.java b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/GlobalPluginExecuteMethodInterceptor.java index b259608f0..45004bb04 100644 --- a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/GlobalPluginExecuteMethodInterceptor.java +++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/GlobalPluginExecuteMethodInterceptor.java @@ -77,7 +77,7 @@ public class GlobalPluginExecuteMethodInterceptor implements InstanceMethodsArou ContextSnapshot snapshot = ContextManager.capture(); exchange.getAttributes().put(SHENYU_AGENT_TRACE_ID, - Optional.ofNullable(snapshot.getTraceId()).map(DistributedTraceId::getId).orElse("")); + Optional.ofNullable(snapshot.getTraceId()).map(DistributedTraceId::getId).orElse(ContextManager.getGlobalTraceId())); EnhancedInstance instance = getInstance(allArguments[0]); instance.setSkyWalkingDynamicField(snapshot); span.prepareForAsync(); @@ -98,7 +98,8 @@ public class GlobalPluginExecuteMethodInterceptor implements InstanceMethodsArou } Mono monoReturn = (Mono) ret; - // add skywalking context snapshot to reactor context. webclient plugin need to use SKYWALKING_CONTEXT_SNAPSHOT + // add skywalking context snapshot to reactor context. + // webclient plugin need to use SKYWALKING_CONTEXT_SNAPSHOT EnhancedInstance instance = getInstance(allArguments[0]); if (instance != null && instance.getSkyWalkingDynamicField() != null) { monoReturn = monoReturn.subscriberContext(