Skip to content

Commit 5b1ad52

Browse files
authored
Split out camel experimental assertions (open-telemetry#14433)
1 parent 092fde6 commit 5b1ad52

File tree

12 files changed

+200
-27
lines changed

12 files changed

+200
-27
lines changed

buildscripts/checkstyle.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@
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. -->
5355
<module name="RegexpSinglelineJava">
5456
<property name="format"
55-
value="(?&lt;!import static io.opentelemetry.sdk.testing.assertj.)OpenTelemetryAssertions\."/>
57+
value="^(?!.*import).*OpenTelemetryAssertions\.[a-z]"/>
5658
<property name="message"
5759
value="Please statically import methods from OpenTelemetryAssertions"/>
5860
</module>

docs/instrumentation-list.yaml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,115 @@ libraries:
16631663
Enable the capture of experimental `camel.uri`, `camel.kafka.partitionKey`, `camel.kafka.key` and `camel.kafka.offset` span attributes.
16641664
type: boolean
16651665
default: false
1666+
telemetry:
1667+
- when: default
1668+
spans:
1669+
- span_kind: CLIENT
1670+
attributes:
1671+
- name: db.name
1672+
type: STRING
1673+
- name: db.statement
1674+
type: STRING
1675+
- name: db.system
1676+
type: STRING
1677+
- name: http.request.method
1678+
type: STRING
1679+
- name: http.response.status_code
1680+
type: LONG
1681+
- name: url.full
1682+
type: STRING
1683+
- span_kind: INTERNAL
1684+
attributes:
1685+
- name: http.request.method
1686+
type: STRING
1687+
- name: messaging.destination.name
1688+
type: STRING
1689+
- name: messaging.message.id
1690+
type: STRING
1691+
- name: url.full
1692+
type: STRING
1693+
- span_kind: SERVER
1694+
attributes:
1695+
- name: http.request.method
1696+
type: STRING
1697+
- name: http.response.status_code
1698+
type: LONG
1699+
- name: url.full
1700+
type: STRING
1701+
- when: otel.instrumentation.camel.experimental-span-attributes=true
1702+
spans:
1703+
- span_kind: CLIENT
1704+
attributes:
1705+
- name: camel.uri
1706+
type: STRING
1707+
- name: db.name
1708+
type: STRING
1709+
- name: db.statement
1710+
type: STRING
1711+
- name: db.system
1712+
type: STRING
1713+
- name: http.request.method
1714+
type: STRING
1715+
- name: http.response.status_code
1716+
type: LONG
1717+
- name: url.full
1718+
type: STRING
1719+
- span_kind: INTERNAL
1720+
attributes:
1721+
- name: camel.uri
1722+
type: STRING
1723+
- name: http.request.method
1724+
type: STRING
1725+
- name: messaging.destination.name
1726+
type: STRING
1727+
- name: messaging.message.id
1728+
type: STRING
1729+
- name: url.full
1730+
type: STRING
1731+
- span_kind: SERVER
1732+
attributes:
1733+
- name: camel.uri
1734+
type: STRING
1735+
- name: http.request.method
1736+
type: STRING
1737+
- name: http.response.status_code
1738+
type: LONG
1739+
- name: url.full
1740+
type: STRING
1741+
- when: otel.semconv-stability.opt-in=database
1742+
spans:
1743+
- span_kind: CLIENT
1744+
attributes:
1745+
- name: db.namespace
1746+
type: STRING
1747+
- name: db.query.text
1748+
type: STRING
1749+
- name: db.system.name
1750+
type: STRING
1751+
- name: http.request.method
1752+
type: STRING
1753+
- name: http.response.status_code
1754+
type: LONG
1755+
- name: url.full
1756+
type: STRING
1757+
- span_kind: INTERNAL
1758+
attributes:
1759+
- name: http.request.method
1760+
type: STRING
1761+
- name: messaging.destination.name
1762+
type: STRING
1763+
- name: messaging.message.id
1764+
type: STRING
1765+
- name: url.full
1766+
type: STRING
1767+
- span_kind: SERVER
1768+
attributes:
1769+
- name: http.request.method
1770+
type: STRING
1771+
- name: http.response.status_code
1772+
type: LONG
1773+
- name: url.full
1774+
type: STRING
16661775
cassandra:
16671776
- name: cassandra-3.0
16681777
description: |

instrumentation-docs/instrumentations.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ readonly INSTRUMENTATIONS=(
122122
"cassandra:cassandra-4.0:javaagent:testStableSemconv"
123123
"cassandra:cassandra-4.4:javaagent:test"
124124
"cassandra:cassandra-4.4:javaagent:testStableSemconv"
125+
"camel-2.20:javaagent:test"
126+
"camel-2.20:javaagent:testStableSemconv"
127+
"camel-2.20:javaagent:testExperimental"
125128
)
126129

127130
# Some instrumentation test suites don't run ARM, so we use colima to run them in an x86_64

instrumentation/camel-2.20/javaagent/build.gradle.kts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ dependencies {
6969

7070
tasks {
7171
withType<Test>().configureEach {
72-
// TODO run tests both with and without experimental span attributes
73-
jvmArgs("-Dotel.instrumentation.camel.experimental-span-attributes=true")
7472
jvmArgs("-Dotel.instrumentation.aws-sdk.experimental-span-attributes=true")
7573

7674
// TODO: fix camel instrumentation so that it uses semantic attributes extractors
@@ -81,14 +79,22 @@ tasks {
8179
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
8280

8381
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")
82+
83+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
84+
}
85+
86+
val testExperimental by registering(Test::class) {
87+
jvmArgs("-Dotel.instrumentation.camel.experimental-span-attributes=true")
88+
systemProperty("metadataConfig", "otel.instrumentation.camel.experimental-span-attributes=true")
8489
}
8590

8691
val testStableSemconv by registering(Test::class) {
8792
jvmArgs("-Dotel.semconv-stability.opt-in=database")
93+
systemProperty("metadataConfig", "otel.semconv-stability.opt-in=database")
8894
}
8995

9096
check {
91-
dependsOn(testStableSemconv)
97+
dependsOn(testStableSemconv, testExperimental)
9298
}
9399
}
94100

instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/DirectCamelTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.javaagent.instrumentation.apachecamel;
77

88
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimental;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1011

1112
import io.opentelemetry.api.trace.SpanKind;
@@ -70,12 +71,12 @@ void simpleDirectToSingleService() {
7071
.hasKind(SpanKind.INTERNAL)
7172
.hasNoParent()
7273
.hasAttributesSatisfyingExactly(
73-
equalTo(stringKey("camel.uri"), "direct://input")),
74+
equalTo(stringKey("camel.uri"), experimental("direct://input"))),
7475
span ->
7576
span.hasName("receiver")
7677
.hasKind(SpanKind.INTERNAL)
7778
.hasParent(trace.getSpan(0))
7879
.hasAttributesSatisfyingExactly(
79-
equalTo(stringKey("camel.uri"), "direct://receiver"))));
80+
equalTo(stringKey("camel.uri"), experimental("direct://receiver")))));
8081
}
8182
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.apachecamel;
7+
8+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
9+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
10+
11+
import io.opentelemetry.api.common.AttributeKey;
12+
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
13+
import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.StringAssertConsumer;
14+
15+
public class ExperimentalTest {
16+
private static final String EXPERIMENTAL_FLAG =
17+
"otel.instrumentation.camel.experimental-span-attributes";
18+
19+
public static String experimental(String value) {
20+
if (!Boolean.getBoolean(EXPERIMENTAL_FLAG)) {
21+
return null;
22+
}
23+
return value;
24+
}
25+
26+
static AttributeAssertion experimentalSatisfies(
27+
AttributeKey<String> key, StringAssertConsumer assertion) {
28+
if (Boolean.getBoolean(EXPERIMENTAL_FLAG)) {
29+
return satisfies(key, assertion);
30+
} else {
31+
return equalTo(key, null);
32+
}
33+
}
34+
35+
private ExperimentalTest() {}
36+
}

instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/MulticastDirectCamelTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.javaagent.instrumentation.apachecamel;
77

88
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimental;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1011

1112
import io.opentelemetry.api.trace.SpanKind;
@@ -70,18 +71,18 @@ void parallelMulticastToTwoChildServices() {
7071
.hasKind(SpanKind.INTERNAL)
7172
.hasNoParent()
7273
.hasAttributesSatisfyingExactly(
73-
equalTo(stringKey("camel.uri"), "direct://input")),
74+
equalTo(stringKey("camel.uri"), experimental("direct://input"))),
7475
span ->
7576
span.hasName("first")
7677
.hasKind(SpanKind.INTERNAL)
7778
.hasParent(trace.getSpan(0))
7879
.hasAttributesSatisfyingExactly(
79-
equalTo(stringKey("camel.uri"), "direct://first")),
80+
equalTo(stringKey("camel.uri"), experimental("direct://first"))),
8081
span ->
8182
span.hasName("second")
8283
.hasKind(SpanKind.INTERNAL)
8384
.hasParent(trace.getSpan(0))
8485
.hasAttributesSatisfyingExactly(
85-
equalTo(stringKey("camel.uri"), "direct://second"))));
86+
equalTo(stringKey("camel.uri"), experimental("direct://second")))));
8687
}
8788
}

instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.java

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

88
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimental;
10+
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimentalSatisfies;
911
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1012
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
1113
import static io.opentelemetry.semconv.ClientAttributes.CLIENT_ADDRESS;
@@ -92,15 +94,15 @@ void restComponentServerAndClientCallWithJettyBackend() {
9294
span.hasName("start")
9395
.hasKind(SpanKind.INTERNAL)
9496
.hasAttributesSatisfyingExactly(
95-
equalTo(stringKey("camel.uri"), "direct://start")),
97+
equalTo(stringKey("camel.uri"), experimental("direct://start"))),
9698
span ->
9799
span.hasName("GET")
98100
.hasKind(SpanKind.CLIENT)
99101
.hasParent(trace.getSpan(0))
100102
.hasAttributesSatisfyingExactly(
101103
equalTo(
102104
stringKey("camel.uri"),
103-
"rest://get:api/%7Bmodule%7D/unit/%7BunitId%7D"),
105+
experimental("rest://get:api/%7Bmodule%7D/unit/%7BunitId%7D")),
104106
equalTo(HTTP_REQUEST_METHOD, "GET"),
105107
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L)),
106108
span ->
@@ -129,13 +131,13 @@ void restComponentServerAndClientCallWithJettyBackend() {
129131
equalTo(
130132
URL_FULL,
131133
"http://localhost:" + port + "/api/firstModule/unit/unitOne"),
132-
satisfies(
134+
experimentalSatisfies(
133135
stringKey("camel.uri"), val -> val.isInstanceOf(String.class))),
134136
span ->
135137
span.hasName("moduleUnit")
136138
.hasKind(SpanKind.INTERNAL)
137139
.hasParent(trace.getSpan(3))
138140
.hasAttributesSatisfyingExactly(
139-
equalTo(stringKey("camel.uri"), "direct://moduleUnit"))));
141+
equalTo(stringKey("camel.uri"), experimental("direct://moduleUnit")))));
140142
}
141143
}

instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/SingleServiceCamelTest.java

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

88
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimental;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1011
import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD;
1112
import static io.opentelemetry.semconv.UrlAttributes.URL_FULL;
@@ -56,7 +57,7 @@ protected void cleanUp() {
5657
}
5758

5859
@Test
59-
public void singleCamelServiceSpan() {
60+
void singleCamelServiceSpan() {
6061
URI requestUrl = address.resolve("/camelService");
6162

6263
client.post(requestUrl.toString(), "testContent").aggregate().join();
@@ -72,6 +73,7 @@ public void singleCamelServiceSpan() {
7273
equalTo(URL_FULL, requestUrl.toString()),
7374
equalTo(
7475
stringKey("camel.uri"),
75-
requestUrl.toString().replace("localhost", "0.0.0.0")))));
76+
experimental(
77+
requestUrl.toString().replace("localhost", "0.0.0.0"))))));
7678
}
7779
}

instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.javaagent.instrumentation.apachecamel;
77

88
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimental;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1011
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
1112
import static io.opentelemetry.semconv.ClientAttributes.CLIENT_ADDRESS;
@@ -111,7 +112,7 @@ void twoCamelServiceSpans() throws Exception {
111112
.hasKind(SpanKind.INTERNAL)
112113
.hasNoParent()
113114
.hasAttributesSatisfyingExactly(
114-
equalTo(stringKey("camel.uri"), "direct://input")),
115+
equalTo(stringKey("camel.uri"), experimental("direct://input"))),
115116
span ->
116117
span.hasName("POST")
117118
.hasKind(SpanKind.CLIENT)
@@ -122,7 +123,7 @@ void twoCamelServiceSpans() throws Exception {
122123
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L),
123124
equalTo(
124125
stringKey("camel.uri"),
125-
"http://localhost:" + portOne + "/serviceOne")),
126+
experimental("http://localhost:" + portOne + "/serviceOne"))),
126127
span ->
127128
span.hasName("POST /serviceOne")
128129
.hasKind(SpanKind.SERVER)
@@ -133,7 +134,7 @@ void twoCamelServiceSpans() throws Exception {
133134
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L),
134135
equalTo(
135136
stringKey("camel.uri"),
136-
"http://0.0.0.0:" + portOne + "/serviceOne")),
137+
experimental("http://0.0.0.0:" + portOne + "/serviceOne"))),
137138
span ->
138139
span.hasName("POST")
139140
.hasKind(SpanKind.CLIENT)
@@ -144,7 +145,7 @@ void twoCamelServiceSpans() throws Exception {
144145
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L),
145146
equalTo(
146147
stringKey("camel.uri"),
147-
"http://127.0.0.1:" + portTwo + "/serviceTwo")),
148+
experimental("http://127.0.0.1:" + portTwo + "/serviceTwo"))),
148149
span ->
149150
span.hasName("POST /serviceTwo")
150151
.hasKind(SpanKind.SERVER)
@@ -171,6 +172,9 @@ void twoCamelServiceSpans() throws Exception {
171172
equalTo(URL_FULL, "http://127.0.0.1:" + portTwo + "/serviceTwo"),
172173
equalTo(
173174
stringKey("camel.uri"),
174-
"jetty:http://0.0.0.0:" + portTwo + "/serviceTwo?arg=value"))));
175+
experimental(
176+
"jetty:http://0.0.0.0:"
177+
+ portTwo
178+
+ "/serviceTwo?arg=value")))));
175179
}
176180
}

0 commit comments

Comments
 (0)