Fix thrift trace broken and wrong arg collected. (#5989)

This commit is contained in:
ZS-Oliver 2020-12-21 21:50:52 +08:00 committed by GitHub
parent bf639d3ec6
commit 542691011c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -17,7 +17,8 @@ Release Notes.
* Fix the unexpected RunningContext recreation in the Tomcat plugin.
* Fix the potential NPE when trace_sql_parameters is enabled.
* Update `byte-buddy` to 1.10.19.
* Fix thrift plugin trace link broken when intermediate service does not mount agent
* Fix thrift plugin collects wrong args when the method without parameter.
#### OAP-Backend
* Make meter receiver support MAL.

View File

@ -100,6 +100,7 @@ public class TServiceClientInterceptor implements InstanceConstructorInterceptor
while (true) {
TFieldIdEnum field = base.fieldForId(++idx);
if (field == null) {
idx--;
break;
}
buffer.append(field.getFieldName()).append(", ");

View File

@ -21,6 +21,7 @@ package org.apache.skywalking.apm.plugin.thrift.wrapper;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
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;
@ -45,6 +46,7 @@ public class ServerInProtocolWrapper extends AbstractProtocolWrapper {
private static final ILog LOGGER = LogManager.getLogger(ServerInProtocolWrapper.class);
private static final StringTag TAG_ARGS = new StringTag("args");
private AbstractContext context;
private static final String HAVE_CREATED_SPAN = "HAVE_CREATED_SPAN";
public ServerInProtocolWrapper(final TProtocol protocol) {
super(protocol);
@ -52,6 +54,7 @@ public class ServerInProtocolWrapper extends AbstractProtocolWrapper {
public void initial(AbstractContext context) {
this.context = context;
ContextManager.getRuntimeContext().put(HAVE_CREATED_SPAN, false);
}
@Override
@ -72,6 +75,7 @@ public class ServerInProtocolWrapper extends AbstractProtocolWrapper {
span.tag(TAG_ARGS, context.getArguments());
span.setComponent(ComponentsDefine.THRIFT_SERVER);
SpanLayer.asRPCFramework(span);
ContextManager.getRuntimeContext().put(HAVE_CREATED_SPAN, true);
} catch (Throwable throwable) {
LOGGER.error("Failed to resolve header or create EntrySpan.", throwable);
} finally {
@ -81,6 +85,24 @@ public class ServerInProtocolWrapper extends AbstractProtocolWrapper {
}
return readFieldBegin();
}
if (field.type == TType.STOP) {
Boolean haveCreatedSpan =
(Boolean) ContextManager.getRuntimeContext().get(HAVE_CREATED_SPAN);
if (haveCreatedSpan != null && !haveCreatedSpan) {
try {
AbstractSpan span = ContextManager.createEntrySpan(
context.getOperatorName(), createContextCarrier(null));
span.start(context.startTime);
span.tag(TAG_ARGS, context.getArguments());
span.setComponent(ComponentsDefine.THRIFT_SERVER);
SpanLayer.asRPCFramework(span);
} catch (Throwable throwable) {
LOGGER.error("Failed to create EntrySpan.", throwable);
} finally {
context = null;
}
}
}
return field;
}