Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>co.elastic.apm</groupId>
<artifactId>apm-spring-webflux</artifactId>
<version>1.56.1-SNAPSHOT</version>
</parent>

<artifactId>apm-spring-webflux-plugin-spring7</artifactId>
<name>${project.groupId}:${project.artifactId}</name>

<properties>
<!-- for licence header plugin -->
<apm-agent-parent.base.dir>${project.basedir}/../../..</apm-agent-parent.base.dir>

<animal.sniffer.skip>true</animal.sniffer.skip>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${version.spring-boot-4}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-spring-webflux-spring5</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<!-- through the spring-boot dependency management, the test app will be "updated" to spring boot 4 -->
<groupId>${project.groupId}</groupId>
<artifactId>apm-spring-webflux-testapp-spring7</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>co.elastic.apm</groupId>
<artifactId>apm-spring-webflux-spring5</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>

<!-- required for context-propagation during tests, but only at runtime -->
<dependency>
<groupId>co.elastic.apm</groupId>
<artifactId>apm-reactor-plugin</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>co.elastic.apm</groupId>
<artifactId>apm-reactor-plugin</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>org.apache.ivy</groupId>
<artifactId>ivy</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.springwebflux;

public class Spring7HeaderGetterTest extends Spring7Test {

public Spring7HeaderGetterTest() {
super(Impl.class);
}

public static class Impl extends HeaderGetterTest {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.springwebflux;


public class Spring7ServerAnnotatedInstrumentationTest extends Spring7Test {

public Spring7ServerAnnotatedInstrumentationTest() {
super(Impl.class);
}

public static class Impl extends ServerAnnotatedInstrumentationTest {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.springwebflux;

public class Spring7ServerFunctionalInstrumentationTest extends Spring7Test {

public Spring7ServerFunctionalInstrumentationTest() {
super(Impl.class);
}

public static class Impl extends ServerFunctionalInstrumentationTest {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.springwebflux;

public class Spring7ServletContainerTest extends ServletContainerTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.springwebflux;

import org.junit.jupiter.api.Test;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import org.junit.platform.launcher.listeners.TestExecutionSummary;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;

abstract class Spring7Test {
private Class<?> actualTestClass;

public Spring7Test(Class<?> testClazz) {
this.actualTestClass = testClazz;
}

@Test
public void runTests() {
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(selectClass(actualTestClass))
.build();
Launcher launcher = LauncherFactory.create();
SummaryGeneratingListener listener = new SummaryGeneratingListener();
launcher.registerTestExecutionListeners(listener);
launcher.execute(request);

for (TestExecutionSummary.Failure failure : listener.getSummary().getFailures()) {
System.out.println(failure);
failure.getException().printStackTrace();
}
assertThat(listener.getSummary().getTestsFailedCount())
.describedAs("at least one test failure reported, see stack trace for investigation")
.isZero();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.springwebflux;


public class Spring7WebSocketServerInstrumentationTest extends WebSocketServerInstrumentationTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;

import static co.elastic.apm.agent.tracer.AbstractSpan.PRIORITY_HIGH_LEVEL_FRAMEWORK;
import static co.elastic.apm.agent.tracer.AbstractSpan.PRIORITY_LOW_LEVEL_FRAMEWORK;
Expand Down Expand Up @@ -313,7 +316,13 @@ private static void fillResponse(Transaction<?> transaction, ServerWebExchange e
}

private static void copyHeaders(HttpHeaders source, PotentiallyMultiValuedMap destination) {
for (Map.Entry<String, List<String>> header : source.entrySet()) {
// This ensures we can make a MultiValueMap without having access
// to the api from spring framework 7 that will work across versions 5, 6 and 7
Java7IdentityFunction identityFunction = new Java7IdentityFunction();
MultiValueCollectorFunction multiValueCollectorFunction = new MultiValueCollectorFunction(source);
Map<String, List<String>> multiValueHeaderMap = source.toSingleValueMap().keySet()
.stream().collect(Collectors.toMap(identityFunction, multiValueCollectorFunction));
for (Map.Entry<String, List<String>> header : multiValueHeaderMap.entrySet()) {
for (String value : header.getValue()) {
destination.add(header.getKey(), value);
}
Expand All @@ -328,4 +337,27 @@ private static void copyCookies(MultiValueMap<String, HttpCookie> source, Potent
}
}

// Due to -source 7, lambdas cannot be used for the collector
private static class MultiValueCollectorFunction implements Function<String, List<String>> {
private final HttpHeaders source;

public MultiValueCollectorFunction(HttpHeaders source) {
this.source = source;
}

@Override
public List<String> apply(String key) {
return Objects.requireNonNull(source.getValuesAsList(key));
}
}

// Due to -source 7, static method invocations cannot be used
private static class Java7IdentityFunction implements Function<String, String> {
public Java7IdentityFunction() {}

@Override
public String apply(String key) {
return key;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.core.SpringVersion;
import org.springframework.http.HttpStatus;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Hooks;
import reactor.test.StepVerifier;

import java.lang.reflect.Field;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -140,8 +142,8 @@ private void hello(boolean expectHeaders) {
.describedAs("non-standard request headers should be captured")
.isEqualTo("12345");

assertThat(headers.getFirst("Accept"))
.isEqualTo("text/plain, application/json");
assertThat(headers.getAll("Accept"))
.containsAll(List.of("text/plain" , "application/json"));

assertThat(request.getCookies()
.getFirst("cookie"))
Expand Down Expand Up @@ -209,6 +211,15 @@ private static int getStatusCode(WebClientResponseException exception) {
} catch (Exception | Error e) {
// silently ignored
}
try {
// Due to the many breaking changes in the spring framework API in version 7, we have to access the status code through reflection.
// This will check if it can retrieve the int code via the HttpStatus.value() method, as getRawStatusCode() has been removed in 7
Field statusCode = exception.getClass().getSuperclass().getDeclaredField("statusCode");
statusCode.setAccessible(true);
return ((HttpStatus)statusCode.get(exception)).value();
} catch (Exception | Error e) {
// silently ignored
}
try {
return exception.getRawStatusCode();
} catch (Exception | Error e) {
Expand Down
Loading
Loading