Skip to content

Commit 5e8f536

Browse files
authored
Merge branch 'main' into gradle-config-cache-jflex
2 parents 37d74f7 + 5972f4d commit 5e8f536

File tree

20 files changed

+344
-59
lines changed

20 files changed

+344
-59
lines changed

benchmark-overhead/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ repositories {
1818
dependencies {
1919
implementation(enforcedPlatform("org.junit:junit-bom:5.14.1"))
2020

21-
testImplementation(platform("org.testcontainers:testcontainers-bom:2.0.1"))
22-
testImplementation("org.testcontainers:testcontainers:2.0.1")
21+
testImplementation(platform("org.testcontainers:testcontainers-bom:2.0.2"))
22+
testImplementation("org.testcontainers:testcontainers:2.0.2")
2323
testImplementation("org.testcontainers:testcontainers-postgresql")
2424
testImplementation("org.junit.jupiter:junit-jupiter-api")
2525
testImplementation("org.junit.jupiter:junit-jupiter-params")

dependencyManagement/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ val DEPENDENCY_BOMS = listOf(
3232
"org.apache.groovy:groovy-bom:${groovyVersion}",
3333
"io.opentelemetry:opentelemetry-bom:${otelSdkVersion}",
3434
"io.opentelemetry:opentelemetry-bom-alpha:${otelSdkAlphaVersion}",
35-
"org.testcontainers:testcontainers-bom:2.0.1"
35+
"org.testcontainers:testcontainers-bom:2.0.2"
3636
)
3737

3838
val autoServiceVersion = "1.1.1"

examples/distro/smoke-tests/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ plugins {
33
}
44

55
dependencies {
6-
testImplementation("org.testcontainers:testcontainers:2.0.1")
6+
testImplementation("org.testcontainers:testcontainers:2.0.2")
77
testImplementation("com.fasterxml.jackson.core:jackson-databind:2.20.1")
8-
testImplementation("com.google.protobuf:protobuf-java-util:4.33.0")
8+
testImplementation("com.google.protobuf:protobuf-java-util:4.33.1")
99
testImplementation("com.squareup.okhttp3:okhttp:5.3.0")
1010
testImplementation("io.opentelemetry.proto:opentelemetry-proto:1.8.0-alpha")
1111
testImplementation("io.opentelemetry:opentelemetry-api")

examples/extension/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ dependencies {
9898
implementation 'org.apache.commons:commons-lang3:3.19.0'
9999

100100
//All dependencies below are only for tests
101-
testImplementation("org.testcontainers:testcontainers:2.0.1")
101+
testImplementation("org.testcontainers:testcontainers:2.0.2")
102102
testImplementation("com.fasterxml.jackson.core:jackson-databind:2.20.1")
103-
testImplementation("com.google.protobuf:protobuf-java-util:4.33.0")
103+
testImplementation("com.google.protobuf:protobuf-java-util:4.33.1")
104104
testImplementation("com.squareup.okhttp3:okhttp:5.3.0")
105105
testImplementation("io.opentelemetry:opentelemetry-api")
106106
testImplementation("io.opentelemetry.proto:opentelemetry-proto:1.8.0-alpha")

instrumentation/spring/spring-core-2.0/javaagent/src/test/java/SimpleAsyncTaskExecutorInstrumentationTest.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
7+
68
import io.opentelemetry.api.GlobalOpenTelemetry;
79
import io.opentelemetry.api.trace.SpanKind;
810
import io.opentelemetry.api.trace.Tracer;
911
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
1012
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
13+
import java.lang.reflect.Method;
1114
import java.util.concurrent.Callable;
1215
import java.util.concurrent.CountDownLatch;
1316
import org.junit.jupiter.api.Test;
@@ -22,6 +25,23 @@ class SimpleAsyncTaskExecutorInstrumentationTest {
2225

2326
private static final SimpleAsyncTaskExecutor EXECUTOR = new SimpleAsyncTaskExecutor();
2427

28+
private static final Method submitListenableRunnable;
29+
private static final Method submitListenableCallable;
30+
31+
static {
32+
// removed in spring 7
33+
submitListenableRunnable = findMethod("submitListenable", Runnable.class);
34+
submitListenableCallable = findMethod("submitListenable", Callable.class);
35+
}
36+
37+
private static Method findMethod(String name, Class<?>... parameterTypes) {
38+
try {
39+
return SimpleAsyncTaskExecutor.class.getMethod(name, parameterTypes);
40+
} catch (Exception e) {
41+
return null;
42+
}
43+
}
44+
2545
@Test
2646
void executeRunnable() {
2747
executeTwoTasks(EXECUTOR::execute);
@@ -39,12 +59,14 @@ void submitCallable() {
3959

4060
@Test
4161
void submitListenableRunnable() {
42-
executeTwoTasks(task -> EXECUTOR.submitListenable((Runnable) task));
62+
assumeTrue(submitListenableRunnable != null);
63+
executeTwoTasks(task -> submitListenableRunnable.invoke(EXECUTOR, task));
4364
}
4465

4566
@Test
4667
void submitListenableCallable() {
47-
executeTwoTasks(task -> EXECUTOR.submitListenable((Callable<?>) task));
68+
assumeTrue(submitListenableCallable != null);
69+
executeTwoTasks(task -> submitListenableCallable.invoke(EXECUTOR, task));
4870
}
4971

5072
private static void executeTwoTasks(ThrowingConsumer<AsyncTask> task) {

instrumentation/spring/spring-data/spring-data-3.0/testing/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ dependencies {
2020
testImplementation("org.hsqldb:hsqldb:2.0.0")
2121
testImplementation("com.h2database:h2:1.4.197")
2222
testImplementation("io.r2dbc:r2dbc-h2:1.0.0.RELEASE")
23+
24+
// latest version of spring data is not yet compatible with spring 7 yet
25+
latestDepTestLibrary("org.springframework:spring-test:6.+") // documented limitation
2326
}
2427

2528
otelJava {

instrumentation/spring/spring-security-config-6.0/javaagent/build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ dependencies {
2121
library("org.springframework.security:spring-security-web:6.0.0")
2222
library("io.projectreactor:reactor-core:3.5.0")
2323

24+
// SpringExtension in spring-test 7 requires JUnit 6
25+
testImplementation(platform("org.junit:junit-bom:6.0.1"))
26+
2427
testLibrary("org.springframework:spring-test:6.0.0")
2528
testLibrary("org.springframework:spring-context:6.0.0")
26-
// can't use testLibrary for now because 6.2.0-M1 is latest and its POM referes to a missing
29+
// can't use testLibrary for now because 6.2.0-M1 is latest and its POM refers to a missing
2730
// parent POM, switch back to testLibrary when a new version is released
2831
// testLibrary("jakarta.servlet:jakarta.servlet-api:6.0.0")
2932
testImplementation("jakarta.servlet:jakarta.servlet-api:6.0.0")
3033
latestDepTestLibrary("jakarta.servlet:jakarta.servlet-api:6.1.0") // documented limitation
34+
// remove after 7.0 is released for spring security
35+
// spring-test 7 requires spring-context 7
36+
latestDepTestLibrary("org.springframework:spring-context:latest.release")
37+
latestDepTestLibrary("org.springframework:spring-web:latest.release")
3138
}
3239

3340
otelJava {

instrumentation/spring/spring-security-config-6.0/library/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ dependencies {
1616

1717
implementation(project(":instrumentation:reactor:reactor-3.1:library"))
1818

19+
// SpringExtension in spring-test 7 requires JUnit 6
20+
testImplementation(platform("org.junit:junit-bom:6.0.1"))
21+
1922
testLibrary("org.springframework:spring-test:6.0.0")
23+
// remove after 7.0 is released for spring security
24+
// spring-test 7 requires spring-context 7
25+
latestDepTestLibrary("org.springframework:spring-context:latest.release")
2026
}
2127

2228
otelJava {

instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebHttpAttributesGetter.java

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,25 @@
1313
import java.lang.invoke.MethodType;
1414
import java.util.List;
1515
import javax.annotation.Nullable;
16+
import org.springframework.http.HttpHeaders;
1617
import org.springframework.http.HttpRequest;
1718
import org.springframework.http.client.ClientHttpResponse;
1819

1920
enum SpringWebHttpAttributesGetter
2021
implements HttpClientAttributesGetter<HttpRequest, ClientHttpResponse> {
2122
INSTANCE;
2223

23-
@Override
24-
public String getHttpRequestMethod(HttpRequest httpRequest) {
25-
return httpRequest.getMethod().name();
26-
}
27-
28-
@Override
29-
@Nullable
30-
public String getUrlFull(HttpRequest httpRequest) {
31-
return httpRequest.getURI().toString();
32-
}
33-
34-
@Override
35-
public List<String> getHttpRequestHeader(HttpRequest httpRequest, String name) {
36-
return httpRequest.getHeaders().getOrDefault(name, emptyList());
37-
}
38-
3924
@Nullable private static final MethodHandle GET_STATUS_CODE;
40-
4125
@Nullable private static final MethodHandle STATUS_CODE_VALUE;
26+
@Nullable private static final MethodHandle GET_HEADERS;
4227

4328
static {
29+
MethodHandles.Lookup lookup = MethodHandles.publicLookup();
30+
4431
MethodHandle getStatusCode = null;
4532
MethodHandle statusCodeValue = null;
4633
Class<?> httpStatusCodeClass = null;
4734

48-
MethodHandles.Lookup lookup = MethodHandles.publicLookup();
49-
5035
try {
5136
httpStatusCodeClass = Class.forName("org.springframework.http.HttpStatusCode");
5237
} catch (ClassNotFoundException e) {
@@ -73,6 +58,52 @@ public List<String> getHttpRequestHeader(HttpRequest httpRequest, String name) {
7358

7459
GET_STATUS_CODE = getStatusCode;
7560
STATUS_CODE_VALUE = statusCodeValue;
61+
62+
// since spring web 7.0
63+
MethodHandle methodHandle =
64+
findGetHeadersMethod(MethodType.methodType(List.class, String.class, List.class));
65+
if (methodHandle == null) {
66+
// up to spring web 7.0
67+
methodHandle =
68+
findGetHeadersMethod(MethodType.methodType(Object.class, Object.class, Object.class));
69+
}
70+
GET_HEADERS = methodHandle;
71+
}
72+
73+
private static MethodHandle findGetHeadersMethod(MethodType methodType) {
74+
try {
75+
return MethodHandles.lookup().findVirtual(HttpHeaders.class, "getOrDefault", methodType);
76+
} catch (Throwable t) {
77+
return null;
78+
}
79+
}
80+
81+
@Override
82+
public String getHttpRequestMethod(HttpRequest httpRequest) {
83+
return httpRequest.getMethod().name();
84+
}
85+
86+
@Override
87+
@Nullable
88+
public String getUrlFull(HttpRequest httpRequest) {
89+
return httpRequest.getURI().toString();
90+
}
91+
92+
@Override
93+
public List<String> getHttpRequestHeader(HttpRequest httpRequest, String name) {
94+
return getHeader(httpRequest.getHeaders(), name);
95+
}
96+
97+
@SuppressWarnings("unchecked") // casting MethodHandle.invoke result
98+
private static List<String> getHeader(HttpHeaders headers, String name) {
99+
if (GET_HEADERS != null) {
100+
try {
101+
return (List<String>) GET_HEADERS.invoke(headers, name, emptyList());
102+
} catch (Throwable t) {
103+
// ignore
104+
}
105+
}
106+
return emptyList();
76107
}
77108

78109
@Override
@@ -94,7 +125,7 @@ public Integer getHttpResponseStatusCode(
94125
@Override
95126
public List<String> getHttpResponseHeader(
96127
HttpRequest httpRequest, ClientHttpResponse clientHttpResponse, String name) {
97-
return clientHttpResponse.getHeaders().getOrDefault(name, emptyList());
128+
return getHeader(clientHttpResponse.getHeaders(), name);
98129
}
99130

100131
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.spring.webflux.v5_3;
7+
8+
import static java.util.Collections.emptyList;
9+
10+
import java.lang.invoke.MethodHandle;
11+
import java.lang.invoke.MethodHandles;
12+
import java.lang.invoke.MethodType;
13+
import java.util.List;
14+
import javax.annotation.Nullable;
15+
import org.springframework.http.HttpHeaders;
16+
17+
class HeaderUtil {
18+
@Nullable private static final MethodHandle GET_HEADERS;
19+
20+
static {
21+
// since spring web 7.0
22+
MethodHandle methodHandle =
23+
findGetHeadersMethod(MethodType.methodType(List.class, String.class, List.class));
24+
if (methodHandle == null) {
25+
// up to spring web 7.0
26+
methodHandle =
27+
findGetHeadersMethod(MethodType.methodType(Object.class, Object.class, Object.class));
28+
}
29+
GET_HEADERS = methodHandle;
30+
}
31+
32+
private static MethodHandle findGetHeadersMethod(MethodType methodType) {
33+
try {
34+
return MethodHandles.lookup().findVirtual(HttpHeaders.class, "getOrDefault", methodType);
35+
} catch (Throwable t) {
36+
return null;
37+
}
38+
}
39+
40+
@SuppressWarnings("unchecked") // casting MethodHandle.invoke result
41+
static List<String> getHeader(HttpHeaders headers, String name) {
42+
if (GET_HEADERS != null) {
43+
try {
44+
return (List<String>) GET_HEADERS.invoke(headers, name, emptyList());
45+
} catch (Throwable t) {
46+
// ignore
47+
}
48+
}
49+
return emptyList();
50+
}
51+
52+
private HeaderUtil() {}
53+
}

0 commit comments

Comments
 (0)