Skip to content

Commit 2371589

Browse files
authored
Statically import semconv constants in tests (#12575)
1 parent 6f4ee3c commit 2371589

File tree

186 files changed

+4013
-4481
lines changed

Some content is hidden

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

186 files changed

+4013
-4481
lines changed

instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java

+21-29
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
import static io.opentelemetry.instrumentation.testing.GlobalTraceUtil.runWithSpan;
99
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1010
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
11+
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
12+
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT;
13+
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_TYPE;
14+
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
15+
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
1116
import static org.assertj.core.api.Assertions.assertThat;
1217

1318
import io.opentelemetry.api.trace.SpanKind;
@@ -16,8 +21,6 @@
1621
import io.opentelemetry.instrumentation.test.utils.PortUtils;
1722
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
1823
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
19-
import io.opentelemetry.semconv.NetworkAttributes;
20-
import io.opentelemetry.semconv.ServerAttributes;
2124
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes;
2225
import java.lang.reflect.Field;
2326
import java.net.InetAddress;
@@ -135,23 +138,22 @@ void testApacheDubboBase() throws ReflectiveOperationException {
135138
RpcIncubatingAttributes.RPC_SERVICE,
136139
"org.apache.dubbo.rpc.service.GenericService"),
137140
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
138-
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
141+
equalTo(SERVER_ADDRESS, "localhost"),
142+
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
139143
satisfies(
140-
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
141-
satisfies(
142-
NetworkAttributes.NETWORK_PEER_ADDRESS,
144+
NETWORK_PEER_ADDRESS,
143145
k ->
144146
k.satisfiesAnyOf(
145147
val -> assertThat(val).isNull(),
146148
val -> assertThat(val).isInstanceOf(String.class))),
147149
satisfies(
148-
NetworkAttributes.NETWORK_PEER_PORT,
150+
NETWORK_PEER_PORT,
149151
k ->
150152
k.satisfiesAnyOf(
151153
val -> assertThat(val).isNull(),
152154
val -> assertThat(val).isInstanceOf(Long.class))),
153155
satisfies(
154-
NetworkAttributes.NETWORK_TYPE,
156+
NETWORK_TYPE,
155157
k ->
156158
k.satisfiesAnyOf(
157159
val -> assertThat(val).isNull(),
@@ -170,14 +172,9 @@ void testApacheDubboBase() throws ReflectiveOperationException {
170172
RpcIncubatingAttributes.RPC_SERVICE,
171173
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
172174
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
173-
satisfies(
174-
NetworkAttributes.NETWORK_PEER_ADDRESS,
175-
k -> k.isInstanceOf(String.class)),
176-
satisfies(
177-
NetworkAttributes.NETWORK_PEER_PORT,
178-
k -> k.isInstanceOf(Long.class)),
179-
satisfies(
180-
NetworkAttributes.NETWORK_TYPE, AbstractAssert::isNull))));
175+
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
176+
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
177+
satisfies(NETWORK_TYPE, AbstractAssert::isNull))));
181178
}
182179

183180
@Test
@@ -235,23 +232,22 @@ void testApacheDubboTest()
235232
RpcIncubatingAttributes.RPC_SERVICE,
236233
"org.apache.dubbo.rpc.service.GenericService"),
237234
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invokeAsync"),
238-
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
235+
equalTo(SERVER_ADDRESS, "localhost"),
236+
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
239237
satisfies(
240-
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
241-
satisfies(
242-
NetworkAttributes.NETWORK_PEER_ADDRESS,
238+
NETWORK_PEER_ADDRESS,
243239
k ->
244240
k.satisfiesAnyOf(
245241
val -> assertThat(val).isNull(),
246242
val -> assertThat(val).isInstanceOf(String.class))),
247243
satisfies(
248-
NetworkAttributes.NETWORK_PEER_PORT,
244+
NETWORK_PEER_PORT,
249245
k ->
250246
k.satisfiesAnyOf(
251247
val -> assertThat(val).isNull(),
252248
val -> assertThat(val).isInstanceOf(Long.class))),
253249
satisfies(
254-
NetworkAttributes.NETWORK_TYPE,
250+
NETWORK_TYPE,
255251
k ->
256252
k.satisfiesAnyOf(
257253
val -> assertThat(val).isNull(),
@@ -270,14 +266,10 @@ void testApacheDubboTest()
270266
RpcIncubatingAttributes.RPC_SERVICE,
271267
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
272268
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
269+
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
270+
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
273271
satisfies(
274-
NetworkAttributes.NETWORK_PEER_ADDRESS,
275-
k -> k.isInstanceOf(String.class)),
276-
satisfies(
277-
NetworkAttributes.NETWORK_PEER_PORT,
278-
k -> k.isInstanceOf(Long.class)),
279-
satisfies(
280-
NetworkAttributes.NETWORK_TYPE,
272+
NETWORK_TYPE,
281273
k ->
282274
k.satisfiesAnyOf(
283275
val -> assertThat(val).isNull(),

instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java

+29-41
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
import static io.opentelemetry.instrumentation.testing.GlobalTraceUtil.runWithSpan;
99
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1010
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
11+
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
12+
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT;
13+
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_TYPE;
14+
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
15+
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
1116
import static org.assertj.core.api.Assertions.assertThat;
1217

1318
import io.opentelemetry.api.trace.SpanKind;
@@ -18,8 +23,6 @@
1823
import io.opentelemetry.instrumentation.test.utils.PortUtils;
1924
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
2025
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
21-
import io.opentelemetry.semconv.NetworkAttributes;
22-
import io.opentelemetry.semconv.ServerAttributes;
2326
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes;
2427
import java.lang.reflect.Field;
2528
import java.net.InetAddress;
@@ -178,23 +181,22 @@ void testDubboChain() throws ReflectiveOperationException {
178181
RpcIncubatingAttributes.RPC_SERVICE,
179182
"org.apache.dubbo.rpc.service.GenericService"),
180183
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
181-
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
184+
equalTo(SERVER_ADDRESS, "localhost"),
185+
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
182186
satisfies(
183-
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
184-
satisfies(
185-
NetworkAttributes.NETWORK_PEER_ADDRESS,
187+
NETWORK_PEER_ADDRESS,
186188
k ->
187189
k.satisfiesAnyOf(
188190
val -> assertThat(val).isNull(),
189191
val -> assertThat(val).isInstanceOf(String.class))),
190192
satisfies(
191-
NetworkAttributes.NETWORK_PEER_PORT,
193+
NETWORK_PEER_PORT,
192194
k ->
193195
k.satisfiesAnyOf(
194196
val -> assertThat(val).isNull(),
195197
val -> assertThat(val).isInstanceOf(Long.class))),
196198
satisfies(
197-
NetworkAttributes.NETWORK_TYPE,
199+
NETWORK_TYPE,
198200
k ->
199201
k.satisfiesAnyOf(
200202
val -> assertThat(val).isNull(),
@@ -213,14 +215,10 @@ void testDubboChain() throws ReflectiveOperationException {
213215
RpcIncubatingAttributes.RPC_SERVICE,
214216
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"),
215217
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
218+
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
219+
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
216220
satisfies(
217-
NetworkAttributes.NETWORK_PEER_ADDRESS,
218-
k -> k.isInstanceOf(String.class)),
219-
satisfies(
220-
NetworkAttributes.NETWORK_PEER_PORT,
221-
k -> k.isInstanceOf(Long.class)),
222-
satisfies(
223-
NetworkAttributes.NETWORK_TYPE,
221+
NETWORK_TYPE,
224222
k ->
225223
k.satisfiesAnyOf(
226224
val -> assertThat(val).isNull(),
@@ -238,23 +236,22 @@ void testDubboChain() throws ReflectiveOperationException {
238236
RpcIncubatingAttributes.RPC_SERVICE,
239237
"org.apache.dubbo.rpc.service.GenericService"),
240238
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
241-
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
239+
equalTo(SERVER_ADDRESS, "localhost"),
240+
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
242241
satisfies(
243-
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
244-
satisfies(
245-
NetworkAttributes.NETWORK_PEER_ADDRESS,
242+
NETWORK_PEER_ADDRESS,
246243
k ->
247244
k.satisfiesAnyOf(
248245
val -> assertThat(val).isNull(),
249246
val -> assertThat(val).isInstanceOf(String.class))),
250247
satisfies(
251-
NetworkAttributes.NETWORK_PEER_PORT,
248+
NETWORK_PEER_PORT,
252249
k ->
253250
k.satisfiesAnyOf(
254251
val -> assertThat(val).isNull(),
255252
val -> assertThat(val).isInstanceOf(Long.class))),
256253
satisfies(
257-
NetworkAttributes.NETWORK_TYPE,
254+
NETWORK_TYPE,
258255
k ->
259256
k.satisfiesAnyOf(
260257
val -> assertThat(val).isNull(),
@@ -273,14 +270,10 @@ void testDubboChain() throws ReflectiveOperationException {
273270
RpcIncubatingAttributes.RPC_SERVICE,
274271
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
275272
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
273+
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
274+
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
276275
satisfies(
277-
NetworkAttributes.NETWORK_PEER_ADDRESS,
278-
k -> k.isInstanceOf(String.class)),
279-
satisfies(
280-
NetworkAttributes.NETWORK_PEER_PORT,
281-
k -> k.isInstanceOf(Long.class)),
282-
satisfies(
283-
NetworkAttributes.NETWORK_TYPE,
276+
NETWORK_TYPE,
284277
k ->
285278
k.satisfiesAnyOf(
286279
val -> assertThat(val).isNull(),
@@ -359,23 +352,22 @@ void testDubboChainInJvm() throws ReflectiveOperationException {
359352
RpcIncubatingAttributes.RPC_SERVICE,
360353
"org.apache.dubbo.rpc.service.GenericService"),
361354
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
362-
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
363-
satisfies(
364-
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
355+
equalTo(SERVER_ADDRESS, "localhost"),
356+
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
365357
satisfies(
366-
NetworkAttributes.NETWORK_PEER_ADDRESS,
358+
NETWORK_PEER_ADDRESS,
367359
k ->
368360
k.satisfiesAnyOf(
369361
val -> assertThat(val).isNull(),
370362
val -> assertThat(val).isInstanceOf(String.class))),
371363
satisfies(
372-
NetworkAttributes.NETWORK_PEER_PORT,
364+
NETWORK_PEER_PORT,
373365
k ->
374366
k.satisfiesAnyOf(
375367
val -> assertThat(val).isNull(),
376368
val -> assertThat(val).isInstanceOf(Long.class))),
377369
satisfies(
378-
NetworkAttributes.NETWORK_TYPE,
370+
NETWORK_TYPE,
379371
k ->
380372
k.satisfiesAnyOf(
381373
val -> assertThat(val).isNull(),
@@ -394,14 +386,10 @@ void testDubboChainInJvm() throws ReflectiveOperationException {
394386
RpcIncubatingAttributes.RPC_SERVICE,
395387
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"),
396388
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
389+
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
390+
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
397391
satisfies(
398-
NetworkAttributes.NETWORK_PEER_ADDRESS,
399-
k -> k.isInstanceOf(String.class)),
400-
satisfies(
401-
NetworkAttributes.NETWORK_PEER_PORT,
402-
k -> k.isInstanceOf(Long.class)),
403-
satisfies(
404-
NetworkAttributes.NETWORK_TYPE,
392+
NETWORK_TYPE,
405393
k ->
406394
k.satisfiesAnyOf(
407395
val -> assertThat(val).isNull(),

instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/AbstractApacheHttpClientTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0;
77

8+
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PROTOCOL_VERSION;
9+
810
import io.opentelemetry.api.common.AttributeKey;
911
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
1012
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
1113
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
12-
import io.opentelemetry.semconv.NetworkAttributes;
1314
import java.net.URI;
1415
import java.time.Duration;
1516
import java.util.HashSet;
@@ -40,7 +41,7 @@ protected Set<AttributeKey<?>> getHttpAttributes(URI uri) {
4041
|| "https://192.0.2.1/".equals(uri.toString())
4142
|| uri.toString().contains("/read-timeout")
4243
|| uri.toString().contains("/circular-redirect")) {
43-
attributes.remove(NetworkAttributes.NETWORK_PROTOCOL_VERSION);
44+
attributes.remove(NETWORK_PROTOCOL_VERSION);
4445
}
4546
return attributes;
4647
}

0 commit comments

Comments
 (0)