Skip to content

Commit 7b127ba

Browse files
authored
Add framework info for Spring Webflux (#3936)
* Add framework info for Spring Webflux transactions * Update changelog * Fix failing Spring 6 tests
1 parent d888d5a commit 7b127ba

File tree

8 files changed

+45
-5
lines changed

8 files changed

+45
-5
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
3636
* Prevent NPE in OpenTelemetry metrics bridge in case of asynchronous agent start - {pull}3880[#3880]
3737
* Fix random Weblogic ClassNotFoundException related to thread context classloader - {pull}3870[#3870]
3838
* Skips using NOFOLLOW_LINKS file open option when running on OS/400 as it's unsupported there - {pull}3905[#3905]
39+
* Add framework name and version for Spring Webflux transactions - {pull}3936[#3936]
3940
4041
[[release-notes-1.x]]
4142
=== Java Agent version 1.x

apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package co.elastic.apm.agent.springwebflux;
2020

2121
import co.elastic.apm.agent.testutils.Java17OnlyTest;
22+
import org.junit.jupiter.api.BeforeEach;
2223

2324
public class Spring6ServerAnnotatedInstrumentationTest extends Java17OnlyTest {
2425

@@ -27,5 +28,10 @@ public Spring6ServerAnnotatedInstrumentationTest() {
2728
}
2829

2930
public static class Impl extends ServerAnnotatedInstrumentationTest {
31+
32+
@BeforeEach
33+
void setUp() {
34+
expectedFrameworkVersion = "6.2.0";
35+
}
3036
}
3137
}

apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerFunctionalInstrumentationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package co.elastic.apm.agent.springwebflux;
2020

2121
import co.elastic.apm.agent.testutils.Java17OnlyTest;
22+
import org.junit.jupiter.api.BeforeEach;
2223

2324
public class Spring6ServerFunctionalInstrumentationTest extends Java17OnlyTest {
2425

@@ -27,5 +28,9 @@ public Spring6ServerFunctionalInstrumentationTest() {
2728
}
2829

2930
public static class Impl extends ServerFunctionalInstrumentationTest {
31+
@BeforeEach
32+
void setUp() {
33+
expectedFrameworkVersion = "6.2.0";
34+
}
3035
}
3136
}

apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServletContainerTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818
*/
1919
package co.elastic.apm.agent.springwebflux;
2020

21+
import org.junit.jupiter.api.BeforeEach;
2122
import org.junit.jupiter.api.condition.EnabledForJreRange;
2223
import org.junit.jupiter.api.condition.JRE;
2324

2425
@EnabledForJreRange(min = JRE.JAVA_17)
2526
public class Spring6ServletContainerTest extends ServletContainerTest {
27+
28+
@BeforeEach
29+
void setUp() {
30+
expectedFrameworkVersion = "6.2.0";
31+
}
2632
}

apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/main/java/co/elastic/apm/agent/springwebflux/TransactionAwareSubscriber.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void onError(Throwable t) {
145145
Transaction<?> transaction = getTransaction();
146146
doEnter("onError", transaction);
147147
try {
148-
148+
WebfluxHelper.setFrameworkInfo(transaction);
149149
// We have to capture the transaction name just before it's actually ended to prevent
150150
// concurrency issues as the transaction is accessed from multiple threads when created by a servlet.
151151
WebfluxHelper.setTransactionName(transaction, exchange);
@@ -167,7 +167,7 @@ public void onComplete() {
167167
Transaction<?> transaction = getTransaction();
168168
doEnter("onComplete", transaction);
169169
try {
170-
170+
WebfluxHelper.setFrameworkInfo(transaction);
171171
// We have to capture the transaction name just before it's actually ended to prevent
172172
// concurrency issues as the transaction is accessed from multiple threads when created by a servlet.
173173
WebfluxHelper.setTransactionName(transaction, exchange);
@@ -209,7 +209,7 @@ private void cancelTransaction() {
209209
if (transaction == null) {
210210
return;
211211
}
212-
212+
WebfluxHelper.setFrameworkInfo(transaction);
213213
WebfluxHelper.setTransactionName(transaction, exchange);
214214
WebfluxHelper.endTransaction(null, transaction, exchange);
215215

apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package co.elastic.apm.agent.springwebflux;
2020

2121
import co.elastic.apm.agent.httpserver.HttpServerHelper;
22+
import co.elastic.apm.agent.sdk.internal.util.VersionUtils;
2223
import co.elastic.apm.agent.tracer.GlobalTracer;
2324
import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap;
2425
import co.elastic.apm.agent.tracer.util.ResultUtil;
@@ -65,6 +66,8 @@
6566

6667
public class WebfluxHelper {
6768

69+
private static final String FRAMEWORK_NAME = "Spring Webflux";
70+
6871
private static final Logger log = LoggerFactory.getLogger(WebfluxHelper.class);
6972
private static final Logger oneTimeResponseCodeErrorLogger = LoggerUtils.logOnce(log);
7073

@@ -182,6 +185,13 @@ public static void endTransaction(@Nullable Throwable thrown, @Nullable Transact
182185
}
183186
}
184187

188+
public static void setFrameworkInfo(@Nullable Transaction<?> transaction) {
189+
if (transaction != null) {
190+
transaction.setFrameworkName(FRAMEWORK_NAME);
191+
transaction.setFrameworkVersion(VersionUtils.getVersion(HandlerMethod.class, "org.springframework", "webflux"));
192+
}
193+
}
194+
185195
public static void setTransactionName(@Nullable Transaction<?> transaction, ServerWebExchange exchange) {
186196
if (transaction == null) {
187197
return;

apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/AbstractServerInstrumentationTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public abstract class AbstractServerInstrumentationTest extends AbstractInstrume
5858
private static final String BASIC_AUTH_HEADER_VALUE = "Basic ZWxhc3RpYzpjaGFuZ2VtZQ==";
5959

6060
protected static WebFluxApplication.App app;
61+
protected String expectedFrameworkVersion = "5.3.30";
6162
protected GreetingWebClient client;
6263

6364
@BeforeAll
@@ -451,7 +452,11 @@ protected ErrorCaptureImpl getFirstError() {
451452
return reporter.getFirstError(200);
452453
}
453454

454-
static TransactionImpl checkTransaction(TransactionImpl transaction, String expectedName, String expectedMethod, int expectedStatus) {
455+
TransactionImpl checkTransaction(TransactionImpl transaction, String expectedName, String expectedMethod, int expectedStatus) {
456+
return checkTransaction(transaction, expectedName, expectedMethod, expectedStatus, expectedFrameworkVersion);
457+
}
458+
459+
static TransactionImpl checkTransaction(TransactionImpl transaction, String expectedName, String expectedMethod, int expectedStatus, String expectedFrameworkVersion) {
455460
assertThat(transaction.getType()).isEqualTo("request");
456461
assertThat(transaction.getNameAsString()).isEqualTo(expectedName);
457462

@@ -464,6 +469,12 @@ static TransactionImpl checkTransaction(TransactionImpl transaction, String expe
464469
assertThat(transaction.getResult())
465470
.isEqualTo(String.format("HTTP %dxx", expectedStatus / 100));
466471

472+
assertThat(transaction.getFrameworkName())
473+
.isEqualTo("Spring Webflux");
474+
475+
assertThat(transaction.getFrameworkVersion())
476+
.isEqualTo(expectedFrameworkVersion);
477+
467478
return transaction;
468479
}
469480

apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/ServletContainerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class ServletContainerTest extends AbstractInstrumentationTest {
3434

3535
protected static WebFluxApplication.App app;
3636
protected static GreetingWebClient client;
37+
protected String expectedFrameworkVersion = "5.3.30";
3738

3839
@BeforeAll
3940
static void startApp() {
@@ -74,7 +75,7 @@ void shouldOnlyCreateOneTransaction() throws InterruptedException {
7475
TransactionImpl transaction = reporter.getFirstTransaction(200);
7576

7677
// transaction naming should be set by webflux instrumentation
77-
AbstractServerInstrumentationTest.checkTransaction(transaction, "GET /functional/with-parameters/{id}", "GET", 200);
78+
AbstractServerInstrumentationTest.checkTransaction(transaction, "GET /functional/with-parameters/{id}", "GET", 200, expectedFrameworkVersion);
7879

7980
// transaction HTTP part should be provided by servlet instrumentation
8081
AbstractServerInstrumentationTest.checkUrl(client, transaction, "/with-parameters/42");

0 commit comments

Comments
 (0)