Fix regression in spring-scheduling span name (#5436)

This commit is contained in:
Trask Stalnaker 2022-02-24 12:27:43 -08:00 committed by GitHub
parent 12e1134f57
commit 02a4fd41c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 2 deletions

View File

@ -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();
}

View File

@ -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"
}
}
}
}
}
}

View File

@ -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;
}
}