Closed yaojingguo closed 3 years ago
@zifeihan Please confirm the case.
thanks for report this bug, by looking at the source code of different versions, it was found that their processing logic did have a certain change, which may caused the problem. other words, our kafka-scenario
test not covered this.
It is recommended to use another way to fix it, judge whether callback is empty in CallbackConstructorInterceptor
, like this
public class CallbackConstructorInterceptor implements InstanceConstructorInterceptor {
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
Callback callback = (Callback) allArguments[0];
if (null == callback) {
CallbackCache cache;
if (null != objInst.getSkyWalkingDynamicField()) {
cache = (CallbackCache) objInst.getSkyWalkingDynamicField();
} else {
cache = new CallbackCache();
}
cache.setCallback(callback);
objInst.setSkyWalkingDynamicField(cache);
}
}
}
I noticed that a similar judgment was made in kafka-client, like
private static class InterceptorCallback<K, V> implements Callback {
private final Callback userCallback;
private final ProducerInterceptors<K, V> interceptors;
private final TopicPartition tp;
private InterceptorCallback(Callback userCallback, ProducerInterceptors<K, V> interceptors, TopicPartition tp) {
this.userCallback = userCallback;
this.interceptors = interceptors;
this.tp = tp;
}
public void onCompletion(RecordMetadata metadata, Exception exception) {
metadata = metadata != null ? metadata : new RecordMetadata(this.tp, -1L, -1L, -1L, -1L, -1, -1);
this.interceptors.onAcknowledgement(metadata, exception);
if (this.userCallback != null) {
this.userCallback.onCompletion(metadata, exception);
}
}
}
Is it convenient for you to improve the test content in kafka-scenario
? If not, I will improve kafka-scenario
after you fix this bug.
Is it convenient for you to improve the test content in kafka-scenario?
I will have a try to improve kafka-scenario after I fix this bug.
I think that you mean null != callback
by writing null == callback
:
public class CallbackConstructorInterceptor implements InstanceConstructorInterceptor {
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
Callback callback = (Callback) allArguments[0];
if (null == callback) {
CallbackCache cache;
if (null != objInst.getSkyWalkingDynamicField()) {
cache = (CallbackCache) objInst.getSkyWalkingDynamicField();
} else {
cache = new CallbackCache();
}
cache.setCallback(callback);
objInst.setSkyWalkingDynamicField(cache);
}
}
}
And I think that we should add a null check for ContextManager.activeSpan()
in CallbackInterceptor.handleMethodException
:
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
ContextManager.activeSpan().log(t);
}
@zifeihan
And I think that we should add a null check for
ContextManager.activeSpan()
inCallbackInterceptor.handleMethodException
:
Sorry this is my hand error.
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { ContextManager.activeSpan().log(t); }
How about using this judgment,
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
CallbackCache cache = (CallbackCache) objInst.getSkyWalkingDynamicField();
if (null != cache) {
ContextManager.activeSpan().log(t);
}
}
Please answer these questions before submitting your issue.
Bug
spring-kafka:2.2.6.RELEASE
which depends onkafka-clients:2.6.0
After running the above code, I found the following exception in
agent/logs/skywalking-api.log
:Requirement or improvement
If
KafkaProducer.send(record)
is used, there is no callback. SoallArguments[0]
isnull
inCallbackConstructorInterceptor.onConstruct
. WhenCallbackInterceptor.getSnapshot
executes,cache.getCallback()
returnsnull
.My first throught is to add null check for
cache.getCallback()
inCallbackInterceptor
sbeforeMethod
andafterMethod
methods. Ifcache.getCallback()
isnull
, do nothing.