Fix latest dep tests (#12739)
This commit is contained in:
parent
805ce0a3cc
commit
f88e03ed93
|
@ -6,12 +6,49 @@
|
||||||
package io.opentelemetry.javaagent.instrumentation.spring.scheduling.v3_1;
|
package io.opentelemetry.javaagent.instrumentation.spring.scheduling.v3_1;
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesGetter;
|
import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesGetter;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import org.springframework.scheduling.support.ScheduledMethodRunnable;
|
import org.springframework.scheduling.support.ScheduledMethodRunnable;
|
||||||
|
|
||||||
public class SpringSchedulingCodeAttributesGetter implements CodeAttributesGetter<Runnable> {
|
public class SpringSchedulingCodeAttributesGetter implements CodeAttributesGetter<Runnable> {
|
||||||
|
private static final Class<?> outcomeTrackingRunnableClass = getOutcomeTrackingRunnableClass();
|
||||||
|
private static final Field outcomeTrackingRunnableField =
|
||||||
|
getOutcomeTrackingRunnableField(outcomeTrackingRunnableClass);
|
||||||
|
|
||||||
|
private static Class<?> getOutcomeTrackingRunnableClass() {
|
||||||
|
try {
|
||||||
|
return Class.forName("org.springframework.scheduling.config.Task$OutcomeTrackingRunnable");
|
||||||
|
} catch (ClassNotFoundException exception) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Field getOutcomeTrackingRunnableField(Class<?> clazz) {
|
||||||
|
try {
|
||||||
|
Field field = clazz.getDeclaredField("runnable");
|
||||||
|
field.setAccessible(true);
|
||||||
|
return field;
|
||||||
|
} catch (Exception exception) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Runnable unwrap(Runnable runnable) {
|
||||||
|
if (outcomeTrackingRunnableClass != null
|
||||||
|
&& outcomeTrackingRunnableField != null
|
||||||
|
&& outcomeTrackingRunnableClass.isAssignableFrom(runnable.getClass())) {
|
||||||
|
try {
|
||||||
|
// task may be wrapped multiple times so
|
||||||
|
return unwrap((Runnable) outcomeTrackingRunnableField.get(runnable));
|
||||||
|
} catch (IllegalAccessException ignore) {
|
||||||
|
// should not happen because setAccessible was called
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return runnable;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getCodeClass(Runnable runnable) {
|
public Class<?> getCodeClass(Runnable runnable) {
|
||||||
|
runnable = unwrap(runnable);
|
||||||
if (runnable instanceof ScheduledMethodRunnable) {
|
if (runnable instanceof ScheduledMethodRunnable) {
|
||||||
ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable;
|
ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable;
|
||||||
return scheduledMethodRunnable.getMethod().getDeclaringClass();
|
return scheduledMethodRunnable.getMethod().getDeclaringClass();
|
||||||
|
@ -22,6 +59,7 @@ public class SpringSchedulingCodeAttributesGetter implements CodeAttributesGette
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMethodName(Runnable runnable) {
|
public String getMethodName(Runnable runnable) {
|
||||||
|
runnable = unwrap(runnable);
|
||||||
if (runnable instanceof ScheduledMethodRunnable) {
|
if (runnable instanceof ScheduledMethodRunnable) {
|
||||||
ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable;
|
ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable;
|
||||||
return scheduledMethodRunnable.getMethod().getName();
|
return scheduledMethodRunnable.getMethod().getName();
|
||||||
|
|
|
@ -22,6 +22,7 @@ dependencies {
|
||||||
library("io.projectreactor:reactor-core:3.5.0")
|
library("io.projectreactor:reactor-core:3.5.0")
|
||||||
|
|
||||||
testLibrary("org.springframework:spring-test:6.0.0")
|
testLibrary("org.springframework:spring-test:6.0.0")
|
||||||
|
testLibrary("org.springframework:spring-context:6.0.0")
|
||||||
testLibrary("jakarta.servlet:jakarta.servlet-api:6.0.0")
|
testLibrary("jakarta.servlet:jakarta.servlet-api:6.0.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue