verify spring-scheduling supports lambdas (DataDog/dd-trace-java#1750)
MODIFY
instrumentation/spring/spring-scheduling-3.1/spring-scheduling-3.1.gradle
instrumentation/spring/spring-scheduling-3.1/spring-scheduling-3.1.gradle
+ext {
+ minJavaVersionForTests = JavaVersion.VERSION_1_8
+}
+
apply from: "$rootDir/gradle/instrumentation.gradle"
muzzle {

MODIFY
instrumentation/spring/spring-scheduling-3.1/src/test/groovy/SpringSchedulingTest.groovy
instrumentation/spring/spring-scheduling-3.1/src/test/groovy/SpringSchedulingTest.groovy
*/
import io.opentelemetry.auto.test.AgentTestRunner
+import java.util.concurrent.TimeUnit
import org.springframework.context.annotation.AnnotationConfigApplicationContext
class SpringSchedulingTest extends AgentTestRunner {
@@ -63,4 +64,28 @@ class SpringSchedulingTest extends AgentTestRunner {
}
}
+
+ def "schedule lambda test"() {
+ setup:
+ def context = new AnnotationConfigApplicationContext(LambdaTaskConfig)
+ def configurer = context.getBean(LambdaTaskConfigurer)
+
+ configurer.singleUseLatch.await(2000, TimeUnit.MILLISECONDS)
+
+ expect:
+ assertTraces(1) {
+ trace(0, 1) {
+ span(0) {
+ operationNameContains "LambdaTaskConfigurer\$\$Lambda\$"
+ parent()
+ errored false
+ attributes {
+ }
+ }
+ }
+ }
+
+ cleanup:
+ context.close()
+ }
}

ADD
instrumentation/spring/spring-scheduling-3.1/src/test/java/LambdaTaskConfig.java
+/*
+ * Copyright The OpenTelemetry Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+@Configuration
+@EnableScheduling
+public class LambdaTaskConfig {
+
+ @Bean
+ LambdaTaskConfigurer lambdaTaskConfigurer() {
+ return new LambdaTaskConfigurer();
+ }
+}

ADD
instrumentation/spring/spring-scheduling-3.1/src/test/java/LambdaTaskConfigurer.java
+/*
+ * Copyright The OpenTelemetry Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.concurrent.CountDownLatch;
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
+import org.springframework.stereotype.Service;
+
+@Service
+public class LambdaTaskConfigurer implements SchedulingConfigurer {
+
+ public final CountDownLatch singleUseLatch = new CountDownLatch(1);
+
+ @Override
+ public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
+ taskRegistrar.addFixedDelayTask(singleUseLatch::countDown, 500);
+ }
+}

verify spring-scheduling supports lambdas (DataDog/dd-trace-java#1750)