Closed jeqo closed 6 years ago
CC @timurgen
@jeqo we might try to use somethings like getStackTrace for current thread to determine caller of interceptor and add its class name to configs. Not sure if it will work well with streams as they use KafkaProducer/KafkaConsumer internally. I can do that and make pull request.
Would be an option to just have 2 classes, one for consumer and other for the producer (as Zipkin module) and then map it independently on client configuration?
@jeqo we can do it as well.
This code snippet can extract client kind from execution stack
private void resolveAppKind(final Map<String, ?> configs) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
String interceptorCaller = "Unknown type";
for (int i = stackTrace.length - 1; i > 0; i--) {
String callerClassName = stackTrace[i].getClassName();
if (Arrays.asList(
KafkaProducer.class.getName(), KafkaConsumer.class.getName(), KafkaStreams.class.getName())
.contains(callerClassName)) {
interceptorCaller = callerClassName;
break;
}
}
this.addField(configs, ConfigHarvesterInterceptorConfig.APP_KIND, interceptorCaller);
}
Using KafkaProducer could not be a good idea, as the Producer
interface. The same for Consumer
.
If we could then use a wrapper client
structure for configs: "{ type: PRODUCER, configs:
Then, we also avoid the complexity of dealing with the Stack trace.
Currently, config interceptor is only collecting Configurations, but it is not possible to recognize if it is a Producer or Consumer.