Fix regression in spring-scheduling span name (#5436)
This commit is contained in:
parent
12e1134f57
commit
02a4fd41c2
|
@ -14,7 +14,7 @@ public class SpringSchedulingCodeAttributesGetter implements CodeAttributesGette
|
|||
public Class<?> codeClass(Runnable runnable) {
|
||||
if (runnable instanceof ScheduledMethodRunnable) {
|
||||
ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable;
|
||||
return scheduledMethodRunnable.getTarget().getClass();
|
||||
return scheduledMethodRunnable.getMethod().getDeclaringClass();
|
||||
} else {
|
||||
return runnable.getClass();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class SpringSchedulingTest extends AgentInstrumentationSpecification {
|
||||
|
@ -54,7 +55,6 @@ class SpringSchedulingTest extends AgentInstrumentationSpecification {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
def "schedule lambda test"() {
|
||||
|
@ -81,4 +81,28 @@ class SpringSchedulingTest extends AgentInstrumentationSpecification {
|
|||
cleanup:
|
||||
context.close()
|
||||
}
|
||||
|
||||
// by putting the scheduled method directly on the TaskConfig, this verifies the case where the
|
||||
// class is enhanced and so has a different class name, e.g. TaskConfig$$EnhancerByCGLIB$$b910c4a9
|
||||
def "schedule enhanced class test"() {
|
||||
setup:
|
||||
def context = new AnnotationConfigApplicationContext(EnhancedClassTaskConfig)
|
||||
def latch = context.getBean(CountDownLatch)
|
||||
|
||||
latch.await(5, TimeUnit.SECONDS)
|
||||
|
||||
expect:
|
||||
assertTraces(1) {
|
||||
trace(0, 1) {
|
||||
span(0) {
|
||||
name "EnhancedClassTaskConfig.run"
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"code.namespace" "EnhancedClassTaskConfig"
|
||||
"code.function" "run"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
public class EnhancedClassTaskConfig {
|
||||
|
||||
private final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
@Scheduled(fixedRate = 5000)
|
||||
public void run() {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CountDownLatch countDownLatch() {
|
||||
return latch;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue