Kafka supports the property METRIC_REPORTER_CLASSES_CONFIG as being either a String - comma separated list of class names, or a List of String class names, or a List of Class objects.
If it's a list then initialisation will fail as open telementry will just treat it like a string. E.g.
props.put("metric.reporters", Lists.of(MyClass.class));
Open telemetry will change that to the string [class com.example.MyClass], io.opentelemetry.javaagent.shaded.instrumentation.kafka.internal.OpenTelemetryMetricsReporter, which means kafka tries to load a class with the invalid name of [class com.example.MyClass].
The current code in KafkaSingletons.java acknowledges it might not be a String, but doesn't deal with the other case.
It might be worth converting other formats into the expected format first:
(class1, class2) -> {
// class1 can be List<String>, List<Class<?>> or String
if (class1 instanceof List<?>) {
class1 = ((List<?>)class1).stream().map(klass -> {
if (klass instanceof Class<?>) return klass.getName();
else return String.valueOf(klass);
}).collect(Collectors.joining(","));
}
if (class1 instanceof String) {
String className1 = (String) class1;
if (className1.isEmpty()) {
return class2;
}
if (METRIC_REPORTER_PRESENT_PATTERN.matcher(className1).find()) {
return class1;
}
}
return class1 + "," + class2; // <- implicit toString() on class1 which can be a List
Or handling each case separately, and adding the metrics class without changing the types.
Kafka supports the property METRIC_REPORTER_CLASSES_CONFIG as being either a
String- comma separated list of class names, or a List of String class names, or a List of Class objects.If it's a list then initialisation will fail as open telementry will just treat it like a string. E.g.
Open telemetry will change that to the string
[class com.example.MyClass], io.opentelemetry.javaagent.shaded.instrumentation.kafka.internal.OpenTelemetryMetricsReporter, which means kafka tries to load a class with the invalid name of[class com.example.MyClass].The current code in KafkaSingletons.java acknowledges it might not be a String, but doesn't deal with the other case.
It might be worth converting other formats into the expected format first:
Or handling each case separately, and adding the metrics class without changing the types.