Skip to content

Commit

Permalink
Fix regression in spring-scheduling span name (#5436)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Feb 24, 2022
1 parent 12e1134 commit 02a4fd4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -54,7 +55,6 @@ class SpringSchedulingTest extends AgentInstrumentationSpecification {
}
}
}

}

def "schedule lambda test"() {
Expand All @@ -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"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 02a4fd4

Please sign in to comment.