Chaning the DefaultSpanNamer logic back to original one

this has caused issues in async spans and runnables where the toString didn't come from Object but was a default from classes such as e.g. FutureTask

related issue #2234
This commit is contained in:
Marcin Grzejszczak
2022-12-16 17:17:23 +01:00
parent 6d55869656
commit 29eddf19b1

View File

@@ -41,13 +41,11 @@ import org.springframework.core.annotation.AnnotationUtils;
*/
public class DefaultSpanNamer implements SpanNamer {
private static boolean isDefaultToString(Object delegate) {
try {
return delegate.getClass().getMethod("toString").getDeclaringClass() == Object.class;
}
catch (NoSuchMethodException e) {
throw new RuntimeException(e);
private static boolean isDefaultToString(Object delegate, String spanName) {
if (delegate instanceof Method) {
return delegate.toString().equals(spanName);
}
return (delegate.getClass().getName() + "@" + Integer.toHexString(delegate.hashCode())).equals(spanName);
}
@Override
@@ -55,7 +53,7 @@ public class DefaultSpanNamer implements SpanNamer {
SpanName annotation = annotation(object);
String spanName = annotation != null ? annotation.value() : object.toString();
// If there is no overridden toString method we'll put a constant value
if (annotation == null && isDefaultToString(object)) {
if (isDefaultToString(object, spanName)) {
return defaultValue;
}
return spanName;