diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java index 3e5bdde89b59..7b7969f52457 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java @@ -135,7 +135,6 @@ InternalNetClientAttributesExtractor buildNetExtractor() { InternalNetworkAttributesExtractor buildNetworkExtractor() { return new InternalNetworkAttributesExtractor<>( netAttributesGetter, - AddressAndPortExtractor.noop(), serverAddressAndPortExtractor, /* captureNetworkTransportAndType= */ false, /* captureLocalSocketAttributes= */ false, diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java index 3667bc9f0f91..c16834e69e4a 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java @@ -148,7 +148,6 @@ InternalNetServerAttributesExtractor buildNetExtractor() { InternalNetworkAttributesExtractor buildNetworkExtractor() { return new InternalNetworkAttributesExtractor<>( netAttributesGetter, - serverAddressPortExtractor, clientAddressPortExtractor, /* captureNetworkTransportAndType= */ false, /* captureLocalSocketAttributes= */ false, diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java index 5e9458ece162..aaf6d1f531ad 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java @@ -50,7 +50,6 @@ private NetClientAttributesExtractor(NetClientAttributesGetter( getter, - AddressAndPortExtractor.noop(), serverAddressAndPortExtractor, /* captureNetworkTransportAndType= */ true, /* captureLocalSocketAttributes= */ false, diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java index 67493be7ed77..dae29c4b33dc 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java @@ -52,7 +52,6 @@ private NetServerAttributesExtractor(NetServerAttributesGetter( getter, - serverAddressAndPortExtractor, clientAddressAndPortExtractor, /* captureNetworkTransportAndType= */ true, /* captureLocalSocketAttributes= */ true, diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractor.java index 89ea385b8b34..e232a8db1067 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractor.java @@ -37,7 +37,6 @@ public static NetworkAttributesExtractor new InternalNetworkAttributesExtractor<>( getter, AddressAndPortExtractor.noop(), - AddressAndPortExtractor.noop(), /* captureNetworkTransportAndType= */ true, /* captureLocalSocketAttributes= */ true, // capture the old net.sock.peer.name attr for backwards compatibility diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalNetworkAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalNetworkAttributesExtractor.java index f2529cbe7a0d..6ebadd2657d5 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalNetworkAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalNetworkAttributesExtractor.java @@ -22,7 +22,6 @@ public final class InternalNetworkAttributesExtractor { private final NetworkAttributesGetter getter; - private final AddressAndPortExtractor logicalLocalAddressAndPortExtractor; private final AddressAndPortExtractor logicalPeerAddressAndPortExtractor; private final boolean captureNetworkTransportAndType; private final boolean captureLocalSocketAttributes; @@ -32,7 +31,6 @@ public final class InternalNetworkAttributesExtractor { public InternalNetworkAttributesExtractor( NetworkAttributesGetter getter, - AddressAndPortExtractor logicalLocalAddressAndPortExtractor, AddressAndPortExtractor logicalPeerAddressAndPortExtractor, boolean captureNetworkTransportAndType, boolean captureLocalSocketAttributes, @@ -40,7 +38,6 @@ public InternalNetworkAttributesExtractor( boolean emitStableUrlAttributes, boolean emitOldHttpAttributes) { this.getter = getter; - this.logicalLocalAddressAndPortExtractor = logicalLocalAddressAndPortExtractor; this.logicalPeerAddressAndPortExtractor = logicalPeerAddressAndPortExtractor; this.captureNetworkTransportAndType = captureNetworkTransportAndType; this.captureLocalSocketAttributes = captureLocalSocketAttributes; @@ -74,8 +71,7 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO } String localAddress = getter.getNetworkLocalAddress(request, response); - String logicalLocalAddress = logicalLocalAddressAndPortExtractor.extract(request).address; - if (localAddress != null && !localAddress.equals(logicalLocalAddress)) { + if (localAddress != null) { if (emitStableUrlAttributes && captureLocalSocketAttributes) { internalSet(attributes, NetworkAttributes.NETWORK_LOCAL_ADDRESS, localAddress); } @@ -95,8 +91,7 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO } String peerAddress = getter.getNetworkPeerAddress(request, response); - String logicalPeerAddress = logicalPeerAddressAndPortExtractor.extract(request).address; - if (peerAddress != null && !peerAddress.equals(logicalPeerAddress)) { + if (peerAddress != null) { if (emitStableUrlAttributes) { internalSet(attributes, NetworkAttributes.NETWORK_PEER_ADDRESS, peerAddress); } @@ -119,6 +114,7 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO getter.getNetworkPeerInetSocketAddress(request, response); if (peerSocketAddress != null) { String peerSocketDomain = InetSocketAddressUtil.getDomainName(peerSocketAddress); + String logicalPeerAddress = logicalPeerAddressAndPortExtractor.extract(request).address; if (peerSocketDomain != null && !peerSocketDomain.equals(logicalPeerAddress)) { internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_NAME, peerSocketDomain); } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java index 79fbf5bdec9d..1a4d66015da0 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java @@ -147,36 +147,6 @@ void empty() { assertThat(endAttributes.build()).isEmpty(); } - @Test - void doesNotSetDuplicateSocketAddress() { - // given - Map map = new HashMap<>(); - map.put("netTransport", IP_TCP); - map.put("peerName", "1:2:3:4::"); - map.put("peerPort", "42"); - map.put("sockFamily", "inet6"); - map.put("sockPeerAddr", "1:2:3:4::"); - map.put("sockPeerName", "proxy.opentelemetry.io"); - map.put("sockPeerPort", "123"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, map, null); - - // then - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_PEER_NAME, "1:2:3:4::"), - entry(SemanticAttributes.NET_PEER_PORT, 42L)); - - assertThat(endAttributes.build()).containsOnly(entry(SemanticAttributes.NET_TRANSPORT, IP_TCP)); - } - @Test void doesNotSetNegativePortValues() { // given diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java index ac332991027c..498e046b9160 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java @@ -163,36 +163,6 @@ void empty() { assertThat(endAttributes.build()).isEmpty(); } - @Test - void doesNotSetDuplicatesSocketAddress() { - // given - Map map = new HashMap<>(); - map.put("netTransport", IP_TCP); - map.put("hostName", "4:3:2:1::"); - map.put("hostPort", "80"); - map.put("sockFamily", "inet6"); - map.put("sockHostAddr", "4:3:2:1::"); - map.put("sockHostPort", "8080"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, null, null); - - // then - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), - entry(SemanticAttributes.NET_HOST_NAME, "4:3:2:1::"), - entry(SemanticAttributes.NET_HOST_PORT, 80L)); - - assertThat(endAttributes.build()).isEmpty(); - } - @Test void doesNotSetNegativePort() { // given diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java index 517e6e6963a4..d686cd725869 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java @@ -371,7 +371,7 @@ void shouldExtractServerAddressAndPortFromHostHeader() { } @Test - void shouldNotExtractDuplicatePeerAddress() { + void shouldExtractPeerAddressEvenIfItDuplicatesServerAddress() { Map request = new HashMap<>(); request.put("networkPeerAddress", "1.2.3.4"); request.put("networkPeerPort", "456"); @@ -394,6 +394,9 @@ void shouldNotExtractDuplicatePeerAddress() { AttributesBuilder endAttributes = Attributes.builder(); extractor.onEnd(endAttributes, Context.root(), request, response, null); assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + .containsOnly( + entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 456L)); } } diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java index 4cba765d7157..6d88f3016b95 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java @@ -505,7 +505,7 @@ void shouldExtractServerAddressAndPortFromHostHeader() { } @Test - void shouldNotExtractDuplicatePeerAddress() { + void shouldExtractPeerAddressEvenIfItDuplicatesClientAddress() { Map request = new HashMap<>(); request.put("networkPeerAddress", "1.2.3.4"); request.put("networkPeerPort", "456"); @@ -527,6 +527,9 @@ void shouldNotExtractDuplicatePeerAddress() { AttributesBuilder endAttributes = Attributes.builder(); extractor.onEnd(endAttributes, Context.root(), request, response, null); assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + .containsOnly( + entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 456L)); } } diff --git a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.java b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.java index 0aa7db927309..298f6a070a2d 100644 --- a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.java +++ b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.java @@ -153,6 +153,9 @@ void twoCamelServiceSpans() throws Exception { equalTo( SemanticAttributes.USER_AGENT_ORIGINAL, "Jakarta Commons-HttpClient/3.1"), + satisfies( + SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, + val -> val.isInstanceOf(Long.class)), equalTo(SemanticAttributes.HTTP_ROUTE, "/serviceTwo"), equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), @@ -160,10 +163,11 @@ void twoCamelServiceSpans() throws Exception { equalTo(SemanticAttributes.NET_HOST_PORT, portTwo), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), satisfies( - SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, + SemanticAttributes.NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), + equalTo(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + SemanticAttributes.NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class))), span -> span.hasName("POST /serviceTwo") diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java index 8389b1ea5e27..255c3fba3541 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java @@ -757,6 +757,13 @@ protected SpanDataAssert assertServerSpan( if (attrs.get(netHostPortKey) != null) { assertThat(attrs).containsEntry(netHostPortKey, port); } + + AttributeKey netSockPeerAddrKey = + getAttributeKey(SemanticAttributes.NET_SOCK_PEER_ADDR); + if (attrs.get(netSockPeerAddrKey) != null) { + assertThat(attrs) + .containsEntry(netSockPeerAddrKey, options.sockPeerAddr.apply(endpoint)); + } AttributeKey netSockPeerPortKey = getAttributeKey(SemanticAttributes.NET_SOCK_PEER_PORT); if (attrs.get(netSockPeerPortKey) != null) { @@ -768,17 +775,6 @@ protected SpanDataAssert assertServerSpan( .isInstanceOf(Long.class) .isNotEqualTo(Long.valueOf(port))); } - AttributeKey netSockPeerAddrKey = - getAttributeKey(SemanticAttributes.NET_SOCK_PEER_ADDR); - if (attrs.get(netSockPeerAddrKey) != null) { - assertThat(attrs) - .containsEntry(netSockPeerAddrKey, options.sockPeerAddr.apply(endpoint)); - } - AttributeKey netSockHostAddrKey = - getAttributeKey(SemanticAttributes.NET_SOCK_PEER_ADDR); - if (attrs.get(netSockHostAddrKey) != null) { - assertThat(attrs).containsEntry(netSockHostAddrKey, "127.0.0.1"); - } assertThat(attrs) .hasEntrySatisfying(