Skip to content

Commit 12de0ba

Browse files
authored
Merge branch 'main' into renovate/errorproneversion
2 parents c5a8cdb + 20387ee commit 12de0ba

File tree

19 files changed

+272
-95
lines changed

19 files changed

+272
-95
lines changed

docs/instrumentation-list.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6942,6 +6942,52 @@ libraries:
69426942
type: STRING
69436943
- name: messaging.system
69446944
type: STRING
6945+
- when: otel.instrumentation.kafka.experimental-span-attributes=true
6946+
spans:
6947+
- span_kind: CONSUMER
6948+
attributes:
6949+
- name: kafka.record.queue_time_ms
6950+
type: LONG
6951+
- name: messaging.batch.message_count
6952+
type: LONG
6953+
- name: messaging.client_id
6954+
type: STRING
6955+
- name: messaging.destination.name
6956+
type: STRING
6957+
- name: messaging.destination.partition.id
6958+
type: STRING
6959+
- name: messaging.kafka.consumer.group
6960+
type: STRING
6961+
- name: messaging.kafka.message.key
6962+
type: STRING
6963+
- name: messaging.kafka.message.offset
6964+
type: LONG
6965+
- name: messaging.kafka.message.tombstone
6966+
type: BOOLEAN
6967+
- name: messaging.message.body.size
6968+
type: LONG
6969+
- name: messaging.operation
6970+
type: STRING
6971+
- name: messaging.system
6972+
type: STRING
6973+
- span_kind: PRODUCER
6974+
attributes:
6975+
- name: messaging.client_id
6976+
type: STRING
6977+
- name: messaging.destination.name
6978+
type: STRING
6979+
- name: messaging.destination.partition.id
6980+
type: STRING
6981+
- name: messaging.kafka.message.key
6982+
type: STRING
6983+
- name: messaging.kafka.message.offset
6984+
type: LONG
6985+
- name: messaging.kafka.message.tombstone
6986+
type: BOOLEAN
6987+
- name: messaging.operation
6988+
type: STRING
6989+
- name: messaging.system
6990+
type: STRING
69456991
- name: kafka-clients-2.6
69466992
display_name: Apache Kafka Client
69476993
description: This standalone instrumentation enables messaging spans for Kafka

instrumentation-api-incubator/build.gradle.kts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
plugins {
2-
id("org.xbib.gradle.plugin.jflex")
3-
42
id("otel.java-conventions")
53
id("otel.animalsniffer-conventions")
64
id("otel.jacoco-conventions")
@@ -10,7 +8,11 @@ plugins {
108

119
group = "io.opentelemetry.instrumentation"
1210

11+
val jflex = configurations.create("jflex")
12+
1313
dependencies {
14+
jflex("de.jflex:jflex:1.9.1")
15+
1416
api("io.opentelemetry.semconv:opentelemetry-semconv")
1517
api(project(":instrumentation-api"))
1618
api("io.opentelemetry:opentelemetry-api-incubator")
@@ -24,6 +26,42 @@ dependencies {
2426
testImplementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
2527
}
2628

29+
val jflexSourceDir = layout.projectDirectory.dir("src/main/jflex")
30+
val jflexOutputDir = layout.buildDirectory.dir("generated/sources/jflex")
31+
32+
val generateJflex by tasks.registering(JavaExec::class) {
33+
classpath(jflex)
34+
mainClass.set("jflex.Main")
35+
36+
inputs.dir(jflexSourceDir)
37+
outputs.dir(jflexOutputDir)
38+
39+
val sourceDir = jflexSourceDir
40+
val outputDirProvider = jflexOutputDir
41+
42+
doFirst {
43+
val outputDir = outputDirProvider.get().asFile
44+
outputDir.mkdirs()
45+
val specFile = sourceDir.asFile.resolve("SqlSanitizer.jflex")
46+
args(
47+
"-d",
48+
outputDir.absolutePath,
49+
"--nobak",
50+
specFile.absolutePath,
51+
)
52+
}
53+
}
54+
55+
sourceSets {
56+
main {
57+
java.srcDir(jflexOutputDir)
58+
}
59+
}
60+
61+
tasks.compileJava {
62+
dependsOn(generateJflex)
63+
}
64+
2765
tasks {
2866
// exclude auto-generated code
2967
named<Checkstyle>("checkstyleMain") {
@@ -38,7 +76,11 @@ tasks {
3876
}
3977

4078
sourcesJar {
41-
dependsOn("generateJflex")
79+
dependsOn(generateJflex)
80+
// Avoid configuration cache issue by not capturing task reference
81+
from("src/main/jflex") {
82+
include("**/*.java")
83+
}
4284
}
4385

4486
val testStableSemconv by registering(Test::class) {

instrumentation/spring/spring-data/spring-data-3.0/kotlin-testing/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/KotlinSpringDataTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class KotlinSpringDataTest {
5252
trace.hasSpansSatisfyingExactly({
5353
it.hasName("CustomerRepository.findById").hasNoParent()
5454
}, {
55-
it.hasName("SELECT db.customer").hasParent(trace.getSpan(0))
55+
it.hasName("SELECT db.CUSTOMER").hasParent(trace.getSpan(0))
5656
})
5757
})
5858
}

instrumentation/spring/spring-data/spring-data-3.0/kotlin-testing/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/repository/Customer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import org.springframework.data.annotation.Id
99
import org.springframework.data.relational.core.mapping.Column
1010
import org.springframework.data.relational.core.mapping.Table
1111

12-
@Table("customer")
12+
@Table("CUSTOMER")
1313
data class Customer(
14-
@Id @Column("id") val id: Long,
15-
@Column("name") val name: String,
14+
@Id @Column("ID") val id: Long,
15+
@Column("NAME") val name: String,
1616
)

instrumentation/spring/spring-data/spring-data-3.0/kotlin-testing/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/repository/PersistenceConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class PersistenceConfig {
4242
initializer.setDatabasePopulator(
4343
ResourceDatabasePopulator(
4444
ByteArrayResource(
45-
("CREATE TABLE customer (id INT PRIMARY KEY, name VARCHAR(100) NOT NULL);" +
46-
"INSERT INTO customer (id, name) VALUES ('1', 'Name');")
45+
("CREATE TABLE CUSTOMER (ID INT PRIMARY KEY, NAME VARCHAR(100) NOT NULL);" +
46+
"INSERT INTO CUSTOMER (ID, NAME) VALUES ('1', 'Name');")
4747
.toByteArray(StandardCharsets.UTF_8)
4848
)
4949
)
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.instrumentation.spring.webflux.v5_3;
6+
package io.opentelemetry.instrumentation.spring.web.v3_1;
77

88
import static java.util.Collections.emptyList;
99

1010
import java.lang.invoke.MethodHandle;
1111
import java.lang.invoke.MethodHandles;
1212
import java.lang.invoke.MethodType;
1313
import java.util.List;
14+
import java.util.Map;
1415
import javax.annotation.Nullable;
1516
import org.springframework.http.HttpHeaders;
1617

@@ -19,14 +20,7 @@ class HeaderUtil {
1920

2021
static {
2122
// 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;
23+
GET_HEADERS = findGetHeadersMethod(MethodType.methodType(List.class, String.class, List.class));
3024
}
3125

3226
private static MethodHandle findGetHeadersMethod(MethodType methodType) {
@@ -37,9 +31,16 @@ private static MethodHandle findGetHeadersMethod(MethodType methodType) {
3731
}
3832
}
3933

40-
@SuppressWarnings("unchecked") // casting MethodHandle.invoke result
34+
// before spring web 7.0 HttpHeaders implements Map<String, List<String>>, this triggers
35+
// errorprone BadInstanceof warning since errorpone is not aware that this instanceof check does
36+
// not pass with spring web 7.0+
37+
@SuppressWarnings({"unchecked", "BadInstanceof"})
4138
static List<String> getHeader(HttpHeaders headers, String name) {
42-
if (GET_HEADERS != null) {
39+
if (headers instanceof Map) {
40+
// before spring web 7.0
41+
return ((Map<String, List<String>>) headers).getOrDefault(name, emptyList());
42+
} else if (GET_HEADERS != null) {
43+
// spring web 7.0
4344
try {
4445
return (List<String>) GET_HEADERS.invoke(headers, name, emptyList());
4546
} catch (Throwable t) {

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

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55

66
package io.opentelemetry.instrumentation.spring.web.v3_1;
77

8-
import static java.util.Collections.emptyList;
9-
108
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter;
119
import java.lang.invoke.MethodHandle;
1210
import java.lang.invoke.MethodHandles;
1311
import java.lang.invoke.MethodType;
1412
import java.util.List;
1513
import javax.annotation.Nullable;
16-
import org.springframework.http.HttpHeaders;
1714
import org.springframework.http.HttpRequest;
1815
import org.springframework.http.client.ClientHttpResponse;
1916

@@ -23,7 +20,6 @@ enum SpringWebHttpAttributesGetter
2320

2421
@Nullable private static final MethodHandle GET_STATUS_CODE;
2522
@Nullable private static final MethodHandle STATUS_CODE_VALUE;
26-
@Nullable private static final MethodHandle GET_HEADERS;
2723

2824
static {
2925
MethodHandles.Lookup lookup = MethodHandles.publicLookup();
@@ -58,24 +54,6 @@ enum SpringWebHttpAttributesGetter
5854

5955
GET_STATUS_CODE = getStatusCode;
6056
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-
}
7957
}
8058

8159
@Override
@@ -91,19 +69,7 @@ public String getUrlFull(HttpRequest httpRequest) {
9169

9270
@Override
9371
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();
72+
return HeaderUtil.getHeader(httpRequest.getHeaders(), name);
10773
}
10874

10975
@Override
@@ -125,7 +91,7 @@ public Integer getHttpResponseStatusCode(
12591
@Override
12692
public List<String> getHttpResponseHeader(
12793
HttpRequest httpRequest, ClientHttpResponse clientHttpResponse, String name) {
128-
return getHeader(clientHttpResponse.getHeaders(), name);
94+
return HeaderUtil.getHeader(clientHttpResponse.getHeaders(), name);
12995
}
13096

13197
@Override

instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxServerHttpAttributesGetter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.instrumentation.spring.webflux.v5_3;
77

88
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter;
9+
import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.HeaderUtil;
910
import java.lang.invoke.MethodHandle;
1011
import java.lang.invoke.MethodHandles;
1112
import java.lang.invoke.MethodType;

instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/WebfluxTextMapGetter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static java.util.Collections.emptyIterator;
99

1010
import io.opentelemetry.context.propagation.TextMapGetter;
11+
import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.HeaderUtil;
1112
import java.util.Iterator;
1213
import javax.annotation.Nullable;
1314
import org.springframework.web.server.ServerWebExchange;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.spring.webflux.v5_3.internal;
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 java.util.Map;
15+
import javax.annotation.Nullable;
16+
import org.springframework.http.HttpHeaders;
17+
18+
/**
19+
* This class is internal and experimental. Its APIs are unstable and can change at any time. Its
20+
* APIs (or a version of them) may be promoted to the public stable API in the future, but no
21+
* guarantees are made.
22+
*/
23+
public final class HeaderUtil {
24+
@Nullable private static final MethodHandle GET_HEADERS;
25+
26+
static {
27+
// since spring web 7.0
28+
GET_HEADERS = findGetHeadersMethod(MethodType.methodType(List.class, String.class, List.class));
29+
}
30+
31+
private static MethodHandle findGetHeadersMethod(MethodType methodType) {
32+
try {
33+
return MethodHandles.lookup().findVirtual(HttpHeaders.class, "getOrDefault", methodType);
34+
} catch (Throwable t) {
35+
return null;
36+
}
37+
}
38+
39+
// before spring web 7.0 HttpHeaders implements Map<String, List<String>>, this triggers
40+
// errorprone BadInstanceof warning since errorpone is not aware that this instanceof check does
41+
// not pass with spring web 7.0+
42+
@SuppressWarnings({"unchecked", "BadInstanceof"})
43+
public static List<String> getHeader(HttpHeaders headers, String name) {
44+
if (headers instanceof Map) {
45+
// before spring web 7.0
46+
return ((Map<String, List<String>>) headers).getOrDefault(name, emptyList());
47+
} else if (GET_HEADERS != null) {
48+
// spring web 7.0
49+
try {
50+
return (List<String>) GET_HEADERS.invoke(headers, name, emptyList());
51+
} catch (Throwable t) {
52+
// ignore
53+
}
54+
}
55+
return emptyList();
56+
}
57+
58+
private HeaderUtil() {}
59+
}

0 commit comments

Comments
 (0)