From dacdddb1b439479f0323fadc4bf8b66bbd98b410 Mon Sep 17 00:00:00 2001 From: hutaishi Date: Mon, 20 Jun 2022 22:02:03 +0800 Subject: [PATCH] shenyu plugin fix IgnoredTracerContext traceId NPE (#215) --- CHANGES.md | 2 +- .../shenyu/v24x/GlobalPluginExecuteMethodInterceptor.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3c15f9a39..bef8de241 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ Release Notes. 8.12.0 ------------------ - +* Fix `Shenyu plugin`'s NPE in reading read trace ID when IgnoredTracerContext is used in the context. #### 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 5c65d9fe2..b259608f0 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 @@ -22,6 +22,7 @@ import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.ids.DistributedTraceId; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.tag.Tags.HTTP; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; @@ -75,7 +76,8 @@ public class GlobalPluginExecuteMethodInterceptor implements InstanceMethodsArou HTTP.METHOD.set(span, exchange.getRequest().getMethodValue()); ContextSnapshot snapshot = ContextManager.capture(); - exchange.getAttributes().put(SHENYU_AGENT_TRACE_ID, snapshot.getTraceId().getId()); + exchange.getAttributes().put(SHENYU_AGENT_TRACE_ID, + Optional.ofNullable(snapshot.getTraceId()).map(DistributedTraceId::getId).orElse("")); EnhancedInstance instance = getInstance(allArguments[0]); instance.setSkyWalkingDynamicField(snapshot); span.prepareForAsync();