diff --git a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-restclient-test/pom.xml b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-restclient-test/pom.xml new file mode 100644 index 0000000000..6d68b4a8c5 --- /dev/null +++ b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-restclient-test/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + + co.elastic.apm + apm-spring-resttemplate + 1.44.1-SNAPSHOT + + + apm-spring-restclient-test + ${project.groupId}:${project.artifactId} + + + ${project.basedir}/../../.. + + + + + + org.springframework.boot + spring-boot-dependencies + 3.2.0 + pom + import + + + + + + + org.springframework + spring-webmvc + test + + + ${project.groupId} + apm-spring-resttemplate-plugin + ${project.version} + test + + + ${project.groupId} + apm-spring-resttemplate-plugin + ${project.version} + test-jar + test + + + ${project.groupId} + apm-httpclient-core + ${project.version} + test-jar + test + + + diff --git a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-restclient-test/src/test/java/co/elastic/apm/agent/restclient/SpringRestClientInstrumentationTest.java b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-restclient-test/src/test/java/co/elastic/apm/agent/restclient/SpringRestClientInstrumentationTest.java new file mode 100644 index 0000000000..78790f7e5f --- /dev/null +++ b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-restclient-test/src/test/java/co/elastic/apm/agent/restclient/SpringRestClientInstrumentationTest.java @@ -0,0 +1,83 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you 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. + */ +package co.elastic.apm.agent.restclient; + +import co.elastic.apm.agent.common.JvmRuntimeInfo; +import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.springframework.web.client.RestClient; +import org.springframework.web.client.RestTemplate; + +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@RunWith(Parameterized.class) +public class SpringRestClientInstrumentationTest extends AbstractHttpClientInstrumentationTest { + + // Cannot directly reference RestTemplate here because it is compiled with Java 17 + private final Object restClient; + private final Boolean isRedirectFollowingSupported; + + public SpringRestClientInstrumentationTest(Supplier supplier, + Boolean isRedirectFollowingSupported) { + this.restClient = supplier.get(); + this.isRedirectFollowingSupported = isRedirectFollowingSupported; + } + + @Parameterized.Parameters() + public static Iterable data() { + if (JvmRuntimeInfo.ofCurrentVM().getMajorVersion() >= 17) { + return SpringRestClientInstrumentationTest.Java17Code.getRestClient(); + } else { + return List.of(); + } + } + + @Override + protected void performGet(String path) { + Java17Code.performGet(restClient, path); + } + + @Override + protected boolean isRedirectFollowingSupported() { + return isRedirectFollowingSupported; + } + + /** + * The code is compiled with java 17 but potentially run with java 11. + * JUnit will inspect the test class, therefore it must not contain any references to java 17 code. + */ + private static class Java17Code { + public static void performGet(Object restClient, String path) { + ((RestClient) restClient).get().uri(path).retrieve().body(String.class); + } + + public static Iterable getRestClient() { + Supplier defaultRestClient = () -> RestClient.create(); + Supplier restTemplateBasedRestClient = () -> RestClient.create(new RestTemplate()); + return Stream.of( + new Object[][]{{defaultRestClient, false}, + {restTemplateBasedRestClient, true}}) + .collect(Collectors.toList()); + } + } +} diff --git a/apm-agent-plugins/apm-spring-resttemplate/pom.xml b/apm-agent-plugins/apm-spring-resttemplate/pom.xml index de02f4fb50..e9647f7593 100644 --- a/apm-agent-plugins/apm-spring-resttemplate/pom.xml +++ b/apm-agent-plugins/apm-spring-resttemplate/pom.xml @@ -19,6 +19,7 @@ apm-spring-resttemplate-plugin apm-spring-resttemplate-test + apm-spring-restclient-test diff --git a/docs/supported-technologies.asciidoc b/docs/supported-technologies.asciidoc index ee0732dd28..c5adbdf713 100644 --- a/docs/supported-technologies.asciidoc +++ b/docs/supported-technologies.asciidoc @@ -386,6 +386,11 @@ The spans are named after the schema ` `, for example `GET elastic | | | 1.36.0 + +|Spring RestClient +|6.1.0+ +| +|1.45.0 |===