From 20c8b98cd9a37ae8a0dce3f45927a947d93361de Mon Sep 17 00:00:00 2001 From: Chenfx-git <68135758+Chenfx-git@users.noreply.github.com> Date: Thu, 23 Feb 2023 15:35:59 +0800 Subject: [PATCH] Fix servicecomb plugin trace break in cse case (#460) --- CHANGES.md | 1 + .../v2/ProducerOperationHandlerInterceptor.java | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 23f4db54d..da8a191f2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Release Notes. * Refactor kotlin coroutine plugin with CoroutineContext. * Fix OracleURLParser ignoring actual port when :SID is absent. * Change gRPC instrumentation point to fix plugin not working for server side. +* Fix servicecomb plugin trace break. #### Documentation * Update docs of Tracing APIs, reorganize the API docs into six parts. diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v2/ProducerOperationHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v2/ProducerOperationHandlerInterceptor.java index bbd620f40..4fe3d6f2c 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v2/ProducerOperationHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v2/ProducerOperationHandlerInterceptor.java @@ -42,7 +42,14 @@ public class ProducerOperationHandlerInterceptor implements InstanceMethodsAroun CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); - next.setHeadValue(invocation.getContext().get(next.getHeadKey())); + String headKey = next.getHeadKey(); + if (invocation.getContext().containsKey(headKey)) { + // cse invoke scenario + next.setHeadValue(invocation.getContext().get(headKey)); + } else { + // not cse invoke scenario + next.setHeadValue(invocation.getRequestEx().getHeader(headKey)); + } } String operationName = invocation.getMicroserviceQualifiedName(); AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier);