Skip to content

Commit dd5def2

Browse files
test(rabbitmq): read NETWORK_PEER_PORT as Long; accept legacy or new semconv
1 parent e1a9b73 commit dd5def2

File tree

3 files changed

+8859
-105
lines changed

3 files changed

+8859
-105
lines changed

build_rabbitmq_test.log

Lines changed: 8826 additions & 0 deletions
Large diffs are not rendered by default.

instrumentation/rabbitmq-2.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitMqNewNetAttributesTest.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

instrumentation/rabbitmq-2.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitMqTest.java

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -870,22 +870,39 @@ private static SpanKind captureSpanKind(String rabbitCommand) {
870870
}
871871

872872
private static void verifyNetAttributes(SpanDataAssert span) {
873-
span.hasAttributesSatisfying(
874-
attributes -> {
875-
assertThat(attributes)
876-
.satisfies(
877-
attrs -> {
878-
String peerAddr = attrs.get(NETWORK_PEER_ADDRESS);
879-
assertThat(peerAddr).isIn(rabbitMqIp, null);
880-
881-
String networkType = attrs.get(NETWORK_TYPE);
882-
assertThat(networkType).isIn("ipv4", "ipv6", null);
883-
884-
assertNotNull(attrs.get(NETWORK_PEER_PORT));
885-
});
886-
});
887-
}
888-
873+
span.hasAttributesSatisfying(
874+
attributes -> {
875+
assertThat(attributes)
876+
.satisfies(
877+
attrs -> {
878+
// Legacy convention keys (already imported statically)
879+
String legacyPeerAddr = attrs.get(NETWORK_PEER_ADDRESS);
880+
String legacyType = attrs.get(NETWORK_TYPE);
881+
Long legacyPeerPort = attrs.get(NETWORK_PEER_PORT); // <-- Long, not Integer
882+
883+
// New(er) semconv keys — use literal names via AttributeKey
884+
String serverAddr = attrs.get(AttributeKey.stringKey("server.address"));
885+
Long serverPortNum = attrs.get(AttributeKey.longKey("server.port"));
886+
String clientAddr = attrs.get(AttributeKey.stringKey("client.address"));
887+
Long clientPortNum = attrs.get(AttributeKey.longKey("client.port"));
888+
889+
boolean hasAddress =
890+
(legacyPeerAddr != null) || (serverAddr != null) || (clientAddr != null);
891+
boolean hasPort =
892+
(legacyPeerPort != null) || (serverPortNum != null) || (clientPortNum != null);
893+
894+
assertThat(hasAddress)
895+
.as("Expect network peer/server/client address attribute")
896+
.isTrue();
897+
assertThat(hasPort)
898+
.as("Expect network peer/server/client port attribute")
899+
.isTrue();
900+
901+
// Optional; if present must be ipv4/ipv6
902+
assertThat(legacyType).isIn("ipv4", "ipv6", null);
903+
});
904+
});
905+
}
889906
private static void verifyException(SpanDataAssert span, Throwable exception, String errorMsg) {
890907
span.hasStatus(StatusData.error())
891908
.hasEventsSatisfying(

0 commit comments

Comments
 (0)