Skip to content

Commit 11ce454

Browse files
authored
Merge branch 'main' into small-db-info-prefactor
2 parents 61d4637 + bc8deee commit 11ce454

455 files changed

Lines changed: 2638 additions & 2250 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmark-overhead/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies {
2525
testImplementation("org.junit.jupiter:junit-jupiter-params")
2626
testImplementation("com.squareup.okhttp3:okhttp:5.3.2")
2727
testImplementation("org.jooq:joox:2.0.1")
28-
testImplementation("com.jayway.jsonpath:json-path:2.10.0")
28+
testImplementation("com.jayway.jsonpath:json-path:3.0.0")
2929
testImplementation("org.slf4j:slf4j-simple:2.0.17")
3030
testImplementation("org.assertj:assertj-core:3.27.7")
3131

buildscripts/checkstyle.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,6 @@
5050
-->
5151

5252
<module name="TreeWalker">
53-
<!-- Enforce static imports for OpenTelemetryAssertions methods (lowercase), but allow inner
54-
classes (uppercase). The negative lookahead is needed so we don't match import lines. -->
55-
<module name="RegexpSinglelineJava">
56-
<property name="format"
57-
value="^(?!.*import).*OpenTelemetryAssertions\.[a-z]"/>
58-
<property name="message"
59-
value="Please statically import methods from OpenTelemetryAssertions"/>
60-
</module>
61-
<module name="RegexpSinglelineJava">
62-
<property name="format"
63-
value="(?&lt;!import static org.assertj.core.api.|OpenTelemetry)Assertions.assertThat"/>
64-
<property name="message"
65-
value="Please statically import methods from Assertions (OpenTelemetryAssertions extends Assertions)"/>
66-
</module>
6753
<module name="OuterTypeFilename"/>
6854
<module name="IllegalTokenText">
6955
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>

conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/StaticImportFormatter.kt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class StaticImportFormatter : FormatterFunc, Serializable {
3535
"java.nio.charset.StandardCharsets",
3636
"[A-Z][A-Z_0-9]*"
3737
),
38+
Triple(
39+
"Collections",
40+
"java.util.Collections",
41+
"singleton[a-zA-Z0-9]*|empty[a-zA-Z0-9]*"
42+
),
3843
Triple(
3944
"ArgumentMatchers",
4045
"org.mockito.ArgumentMatchers",
@@ -45,6 +50,17 @@ class StaticImportFormatter : FormatterFunc, Serializable {
4550
"org.mockito.Mockito",
4651
"mock|mockStatic|spy|when|verify|verifyNoInteractions|verifyNoMoreInteractions|doAnswer|doReturn|doThrow|lenient|never|times|atLeastOnce|withSettings"
4752
),
53+
Triple("Assertions", "org.assertj.core.api.Assertions", "assertThat"),
54+
Triple(
55+
"OpenTelemetryAssertions",
56+
"io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions",
57+
"[a-z][a-zA-Z0-9]*"
58+
),
59+
Triple(
60+
"SemconvStability",
61+
"io.opentelemetry.instrumentation.api.internal.SemconvStability",
62+
"emit[a-zA-Z0-9]*"
63+
),
4864
)
4965

5066
var content = input
@@ -63,6 +79,44 @@ class StaticImportFormatter : FormatterFunc, Serializable {
6379
content = lines.joinToString("\n")
6480
}
6581

82+
// Handle semconv classes: find all imported semconv classes (except SchemaUrls) and convert
83+
// qualified constant references (e.g. HttpAttributes.HTTP_METHOD) to static imports.
84+
// Also handles nested value classes (e.g. DbIncubatingAttributes.DbSystemNameIncubatingValues).
85+
val semconvImportRegex =
86+
Regex(
87+
"""^import (io\.opentelemetry\.semconv\.(?:[a-z][a-z.]*\.)?([A-Z][a-zA-Z0-9]+)(?:\.([A-Z][a-zA-Z0-9]+))?);"""
88+
)
89+
val semconvRules =
90+
content
91+
.lines()
92+
.mapNotNull { line -> semconvImportRegex.find(line.trim()) }
93+
.filter { it.groupValues[2] != "SchemaUrls" }
94+
.map { m ->
95+
// If there is a nested class (group 3), use the nested class as the className so that
96+
// references like `DbSystemNameIncubatingValues.COUCHBASE` are rewritten correctly.
97+
val className = if (m.groupValues[3].isNotEmpty()) m.groupValues[3] else m.groupValues[2]
98+
Triple(className, m.groupValues[1], "[A-Z][A-Z_0-9]*")
99+
}
100+
for ((className, pkg, memberPattern) in semconvRules) {
101+
val regex = Regex("\\b${className}\\.(${memberPattern})\\b")
102+
val lines = content.lines().toMutableList()
103+
var inBlockComment = false
104+
for (i in lines.indices) {
105+
val trimmed = lines[i].trimStart()
106+
if (trimmed.startsWith("/*")) inBlockComment = true
107+
if (inBlockComment) {
108+
if (trimmed.contains("*/")) inBlockComment = false
109+
continue
110+
}
111+
if (trimmed.startsWith("import ")) continue
112+
for (match in regex.findAll(lines[i])) {
113+
importsToAdd.add("import static ${pkg}.${match.groupValues[1]};")
114+
}
115+
lines[i] = regex.replace(lines[i], "$1")
116+
}
117+
content = lines.joinToString("\n")
118+
}
119+
66120
if (importsToAdd.isNotEmpty()) {
67121
val lines = content.lines().toMutableList()
68122
val firstImportIndex = lines.indexOfFirst { it.trimStart().startsWith("import ") }

declarative-config-bridge/src/main/java/io/opentelemetry/instrumentation/config/bridge/ConfigPropertiesBackedDeclarativeConfigProperties.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
package io.opentelemetry.instrumentation.config.bridge;
77

8+
import static java.util.Collections.emptyList;
89
import static java.util.Collections.emptySet;
910

1011
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
1112
import io.opentelemetry.common.ComponentLoader;
1213
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1314
import java.time.Duration;
1415
import java.util.ArrayList;
15-
import java.util.Collections;
1616
import java.util.HashMap;
1717
import java.util.List;
1818
import java.util.Map;
@@ -102,8 +102,7 @@ public final class ConfigPropertiesBackedDeclarativeConfigProperties
102102

103103
public static DeclarativeConfigProperties createInstrumentationConfig(
104104
ConfigProperties configProperties) {
105-
return new ConfigPropertiesBackedDeclarativeConfigProperties(
106-
configProperties, Collections.emptyList());
105+
return new ConfigPropertiesBackedDeclarativeConfigProperties(configProperties, emptyList());
107106
}
108107

109108
private ConfigPropertiesBackedDeclarativeConfigProperties(

declarative-config-bridge/src/main/java/io/opentelemetry/instrumentation/config/bridge/DeclarativeConfigPropertiesBridge.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package io.opentelemetry.instrumentation.config.bridge;
77

88
import static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties.empty;
9+
import static java.util.Collections.emptyList;
10+
import static java.util.Collections.emptyMap;
911
import static java.util.Objects.requireNonNull;
1012

1113
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
@@ -115,7 +117,7 @@ public List<String> getList(String propertyName) {
115117
propertyName,
116118
o -> (List<String>) o,
117119
(properties, lastPart) -> properties.getScalarList(lastPart, String.class));
118-
return propertyValue == null ? Collections.emptyList() : propertyValue;
120+
return propertyValue == null ? emptyList() : propertyValue;
119121
}
120122

121123
@Override
@@ -126,7 +128,7 @@ public Map<String, String> getMap(String propertyName) {
126128
DeclarativeConfigProperties.class,
127129
DeclarativeConfigProperties::getStructured);
128130
if (propertyValue == null) {
129-
return Collections.emptyMap();
131+
return emptyMap();
130132
}
131133
Map<String, String> result = new HashMap<>();
132134
propertyValue

docs/contributing/style-guide.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,25 @@ Following the reasoning from
149149
- `Optional` shouldn't appear in public API signatures
150150
- Avoid `Optional` on the hot path (instrumentation code), unless the instrumented library uses it
151151

152+
## Semantic convention constants
153+
154+
**Library instrumentation**: Copy semantic convention constants directly into library
155+
instrumentation classes rather than depending on the semconv artifact. Library instrumentation is
156+
used by end users, and this avoids exposing a dependency on the semconv artifact (which may change
157+
across versions). For example:
158+
159+
```java
160+
// copied from MessagingIncubatingAttributes
161+
private static final AttributeKey<String> MESSAGING_SYSTEM =
162+
AttributeKey.stringKey("messaging.system");
163+
```
164+
165+
**Javaagent instrumentation**: Use the semconv constants from the semconv artifact directly. The
166+
javaagent bundles its own dependencies, so there is no risk of version conflicts for end users.
167+
168+
**Tests**: Use the semconv constants from the semconv artifact directly. Test dependencies do not
169+
affect end users.
170+
152171
## Tooling conventions
153172

154173
### AssertJ

docs/instrumentation-list.yaml

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ libraries:
7979
type: STRING
8080
- name: url.query
8181
type: STRING
82+
- name: url.query
83+
type: VALUE
8284
- name: url.scheme
8385
type: STRING
8486
- name: user_agent.original
@@ -3297,7 +3299,7 @@ libraries:
32973299
type: LONG
32983300
- name: url.full
32993301
type: STRING
3300-
- when: otel.semconv-stability.opt-in=database,service.peer
3302+
- when: otel.semconv-stability.opt-in=database
33013303
metrics:
33023304
- name: db.client.operation.duration
33033305
description: Duration of database client operations.
@@ -3370,7 +3372,7 @@ libraries:
33703372
type: LONG
33713373
- name: url.full
33723374
type: STRING
3373-
- when: otel.semconv-stability.opt-in=database,service.peer
3375+
- when: otel.semconv-stability.opt-in=database
33743376
metrics:
33753377
- name: db.client.operation.duration
33763378
description: Duration of database client operations.
@@ -3434,7 +3436,7 @@ libraries:
34343436
type: LONG
34353437
- name: url.full
34363438
type: STRING
3437-
- when: otel.semconv-stability.opt-in=database,service.peer
3439+
- when: otel.semconv-stability.opt-in=database
34383440
metrics:
34393441
- name: db.client.operation.duration
34403442
description: Duration of database client operations.
@@ -3499,7 +3501,7 @@ libraries:
34993501
type: LONG
35003502
- name: url.full
35013503
type: STRING
3502-
- when: otel.semconv-stability.opt-in=database,service.peer
3504+
- when: otel.semconv-stability.opt-in=database
35033505
metrics:
35043506
- name: db.client.operation.duration
35053507
description: Duration of database client operations.
@@ -4721,6 +4723,8 @@ libraries:
47214723
type: STRING
47224724
- name: url.query
47234725
type: STRING
4726+
- name: url.query
4727+
type: VALUE
47244728
- name: url.scheme
47254729
type: STRING
47264730
- name: user_agent.original
@@ -9671,7 +9675,7 @@ libraries:
96719675
type: STRING
96729676
- name: db.system
96739677
type: STRING
9674-
- when: otel.semconv-stability.opt-in=database,service.peer
9678+
- when: otel.semconv-stability.opt-in=database
96759679
metrics:
96769680
- name: db.client.operation.duration
96779681
description: Duration of database client operations.
@@ -9715,7 +9719,7 @@ libraries:
97159719
type: STRING
97169720
- name: db.system
97179721
type: STRING
9718-
- when: otel.semconv-stability.opt-in=database,service.peer
9722+
- when: otel.semconv-stability.opt-in=database
97199723
metrics:
97209724
- name: db.client.operation.duration
97219725
description: Duration of database client operations.
@@ -9759,7 +9763,7 @@ libraries:
97599763
type: STRING
97609764
- name: db.system
97619765
type: STRING
9762-
- when: otel.semconv-stability.opt-in=database,service.peer
9766+
- when: otel.semconv-stability.opt-in=database
97639767
metrics:
97649768
- name: db.client.operation.duration
97659769
description: Duration of database client operations.
@@ -12927,6 +12931,10 @@ libraries:
1292712931
type: STRING
1292812932
- name: db.system
1292912933
type: STRING
12934+
- name: server.address
12935+
type: STRING
12936+
- name: server.port
12937+
type: LONG
1293012938
- when: otel.instrumentation.spymemcached.experimental-span-attributes=true
1293112939
spans:
1293212940
- span_kind: CLIENT
@@ -12935,6 +12943,10 @@ libraries:
1293512943
type: STRING
1293612944
- name: db.system
1293712945
type: STRING
12946+
- name: server.address
12947+
type: STRING
12948+
- name: server.port
12949+
type: LONG
1293812950
- name: spymemcached.command.cancelled
1293912951
type: BOOLEAN
1294012952
- name: spymemcached.result
@@ -12950,6 +12962,10 @@ libraries:
1295012962
type: STRING
1295112963
- name: db.system.name
1295212964
type: STRING
12965+
- name: server.address
12966+
type: STRING
12967+
- name: server.port
12968+
type: LONG
1295312969
spans:
1295412970
- span_kind: CLIENT
1295512971
attributes:
@@ -12959,6 +12975,10 @@ libraries:
1295912975
type: STRING
1296012976
- name: error.type
1296112977
type: STRING
12978+
- name: server.address
12979+
type: STRING
12980+
- name: server.port
12981+
type: LONG
1296212982
struts:
1296312983
- name: struts-2.3
1296412984
display_name: Apache Struts
@@ -13608,6 +13628,20 @@ libraries:
1360813628
- dev.zio:zio_2.13:[2.0.0,)
1360913629
- dev.zio:zio_3:[2.0.0,)
1361013630
- dev.zio:zio_2.12:[2.0.0,)
13631+
- name: zio-http-3.0
13632+
description: |
13633+
This instrumentation does not emit telemetry on its own. Instead, it extracts the HTTP route and attaches it to HTTP server spans and HTTP server metrics.
13634+
library_link: https://ziohttp.com/
13635+
features:
13636+
- HTTP_ROUTE
13637+
source_path: instrumentation/zio/zio-http-3.0
13638+
minimum_java_version: 11
13639+
scope:
13640+
name: io.opentelemetry.zio-http-3.0
13641+
javaagent_target_versions:
13642+
- dev.zio:zio-http_2.12:[3.0.0,)
13643+
- dev.zio:zio-http_3:[3.0.0,)
13644+
- dev.zio:zio-http_2.13:[3.0.0,)
1361113645
internal:
1361213646
- name: internal-application-logger
1361313647
source_path: instrumentation/internal/internal-application-logger
@@ -13702,6 +13736,10 @@ internal:
1370213736
source_path: instrumentation/opentelemetry-api/opentelemetry-api-1.57
1370313737
scope:
1370413738
name: io.opentelemetry.opentelemetry-api-1.57
13739+
- name: opentelemetry-api-1.59
13740+
source_path: instrumentation/opentelemetry-api/opentelemetry-api-1.59
13741+
scope:
13742+
name: io.opentelemetry.opentelemetry-api-1.59
1370513743
- name: opentelemetry-extension-kotlin-1.0
1370613744
description: |
1370713745
Our Kotlin coroutine instrumentation relies on a shaded copy of the opentelemetry-extension-kotlin library. This can cause conflicts when the application itself also uses opentelemetry-extension-kotlin, because the shaded and unshaded versions store the OpenTelemetry context under different keys. To resolve this issue, this instrumentation modifies the application's copy of opentelemetry-extension-kotlin so that it delegates to the shaded version bundled within the agent.

docs/supported-libraries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ These are the supported libraries and frameworks:
9191
| [Java Http Server](https://docs.oracle.com/en/java/javase/21/docs/api/jdk.httpserver/module-summary.html) | Java 8+ | [opentelemetry-java-http-server](../instrumentation/java-http-server/library) | [HTTP Server Spans], [HTTP Server Metrics] |
9292
| [java.util.logging](https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html) | Java 8+ | N/A | none |
9393
| [Java Platform](https://docs.oracle.com/javase/8/docs/api/java/lang/management/ManagementFactory.html) | Java 8+ | [opentelemetry-runtime-telemetry-java8](../instrumentation/runtime-telemetry/runtime-telemetry-java8/library),<br>[opentelemetry-runtime-telemetry-java17](../instrumentation/runtime-telemetry/runtime-telemetry-java17/library),<br>[opentelemetry-resources](../instrumentation/resources/library) | [JVM Runtime Metrics] |
94-
| [Javalin](https://javalin.io/) | 5.0+ | N/A | Provides `http.route` [2] |
94+
| [Javalin](https://javalin.io/) | 5.0+ (not including 7.0+ yet) | N/A | Provides `http.route` [2] |
9595
| [JAX-RS](https://javaee.github.io/javaee-spec/javadocs/javax/ws/rs/package-summary.html) | 0.5+ | N/A | Provides `http.route` [2], Controller Spans [3] |
9696
| [JAX-RS Client](https://javaee.github.io/javaee-spec/javadocs/javax/ws/rs/client/package-summary.html) | 1.1+ | N/A | [HTTP Client Spans], [HTTP Client Metrics] |
9797
| [JAX-WS](https://jakarta.ee/specifications/xml-web-services/2.3/apidocs/javax/xml/ws/package-summary.html) | 2.0+ (not including 3.0+ yet) | N/A | Provides `http.route` [2], Controller Spans [3] |

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/code/CodeAttributesExtractor.java

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

66
package io.opentelemetry.instrumentation.api.incubator.semconv.code;
77

8+
import static io.opentelemetry.semconv.CodeAttributes.CODE_FUNCTION_NAME;
9+
810
import io.opentelemetry.api.common.AttributeKey;
911
import io.opentelemetry.api.common.AttributesBuilder;
1012
import io.opentelemetry.context.Context;
1113
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
1214
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
13-
import io.opentelemetry.semconv.CodeAttributes;
1415
import javax.annotation.Nullable;
1516

1617
/**
@@ -60,7 +61,7 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
6061
}
6162
}
6263
if (SemconvStability.isEmitStableCodeSemconv() && sb.length() > 0) {
63-
attributes.put(CodeAttributes.CODE_FUNCTION_NAME, sb.toString());
64+
attributes.put(CODE_FUNCTION_NAME, sb.toString());
6465
}
6566
}
6667

0 commit comments

Comments
 (0)