zifeihan commented on issue #6456:
URL: https://github.com/apache/skywalking/issues/6456#issuecomment-786747586
@yaojingguo thanks for report this issue, I may not have noticed that
org.apache.kafka.clients.producer.KafkaProducer.InterceptorCallback wraps the
callback of the doSend method. Therefore, Lambda callback caused the problem, I
suggest modifying CallbackAdapterInterceptor to implement EnhancedInstance, and
return callbackCache.getSnapshot() in getSkyWalkingDynamicField. like this,
```
/**
* implements Callback and EnhancedInstance, for kafka callback in lambda
expression
*/
public class CallbackAdapterInterceptor implements Callback,
EnhancedInstance {
/**
* user Callback object
*/
private CallbackCache callbackCache;
public CallbackAdapterInterceptor(CallbackCache callbackCache) {
this.callbackCache = callbackCache;
}
@Override
public void onCompletion(RecordMetadata metadata, Exception exception) {
ContextSnapshot snapshot = callbackCache.getSnapshot();
AbstractSpan activeSpan =
ContextManager.createLocalSpan("Kafka/Producer/Callback");
SpanLayer.asMQ(activeSpan);
activeSpan.setComponent(ComponentsDefine.KAFKA_PRODUCER);
if (metadata != null) {
Tags.MQ_TOPIC.set(activeSpan, metadata.topic());
}
ContextManager.continued(snapshot);
try {
callbackCache.getCallback().onCompletion(metadata, exception);
} catch (Throwable t) {
ContextManager.activeSpan().log(t);
throw t;
} finally {
if (exception != null) {
ContextManager.activeSpan().log(exception);
}
ContextManager.stopSpan();
}
}
@Override
public Object getSkyWalkingDynamicField() {
return callbackCache.getSnapshot();
}
@Override
public void setSkyWalkingDynamicField(final Object value) {
}
```
welcome to submit pr for fix this bug, if you don’t have time, I will fix
this bug later, @wu-sheng Suggestions are welcome
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]