From 9cb157492c366b09ad06e726dce2f225a2cfa939 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Wed, 18 Oct 2023 12:36:32 +0200 Subject: [PATCH] Replace `(client|server).socket.(address|port)` attributes with `network.(peer|local).(address|port)` (#9676) --- ... => ForwardedAddressAndPortExtractor.java} | 7 +- ....java => HostAddressAndPortExtractor.java} | 6 +- .../http/HttpClientAttributesExtractor.java | 3 +- .../HttpClientAttributesExtractorBuilder.java | 22 ++-- .../http/HttpServerAttributesExtractor.java | 6 +- .../HttpServerAttributesExtractorBuilder.java | 33 ++++-- .../net/NetClientAttributesExtractor.java | 21 ++-- .../net/NetClientAttributesGetter.java | 19 +++ .../net/NetServerAttributesExtractor.java | 30 +++-- .../net/NetServerAttributesGetter.java | 38 ++++++ .../InternalNetClientAttributesExtractor.java | 23 ++-- .../InternalNetServerAttributesExtractor.java | 10 +- .../network/ClientAttributesExtractor.java | 12 +- .../network/ClientAttributesGetter.java | 2 + .../network/NetworkAttributesExtractor.java | 6 + .../network/NetworkAttributesGetter.java | 94 ++++++++++++++- .../network/ServerAttributesExtractor.java | 15 +-- .../network/ServerAttributesGetter.java | 2 + .../network/internal/AddressAndPort.java | 4 +- ...ctor.java => AddressAndPortExtractor.java} | 12 +- .../ClientAddressAndPortExtractor.java | 38 ++++++ .../InternalClientAttributesExtractor.java | 51 +-------- .../InternalNetworkAttributesExtractor.java | 67 +++++++++++ .../InternalServerAttributesExtractor.java | 94 ++------------- .../network/internal/NetworkAttributes.java | 29 +++++ .../ServerAddressAndPortExtractor.java | 38 ++++++ ...ForwardedAddressAndPortExtractorTest.java} | 10 +- ...a => HostAddressAndPortExtractorTest.java} | 8 +- ...tAddressNetClientAttributesGetterTest.java | 7 +- ...tAddressNetServerAttributesGetterTest.java | 6 +- .../net/NetClientAttributesExtractorTest.java | 53 +-------- .../net/NetServerAttributesExtractorTest.java | 42 +------ ...ientAttributesExtractorOldSemconvTest.java | 20 +--- ...workAttributesExtractorOldSemconvTest.java | 36 +++++- ...rverAttributesExtractorOldSemconvTest.java | 36 +----- ...entAttributesExtractorBothSemconvTest.java | 7 +- ...verAttributesExtractorBothSemconvTest.java | 9 +- ...tAttributesExtractorStableSemconvTest.java | 85 ++++++++++++-- ...tExperimentalMetricsStableSemconvTest.java | 6 +- .../HttpClientMetricsStableSemconvTest.java | 6 +- ...rAttributesExtractorStableSemconvTest.java | 108 +++++++++++++++--- ...rExperimentalMetricsStableSemconvTest.java | 9 +- .../HttpServerMetricsStableSemconvTest.java | 9 +- ...tAttributesExtractorStableSemconvTest.java | 12 +- ...rAttributesExtractorStableSemconvTest.java | 9 +- ...ributesExtractorInetSocketAddressTest.java | 81 ------------- .../ClientAttributesExtractorTest.java | 46 +------- ...ributesExtractorInetSocketAddressTest.java | 77 +++++++++++++ .../NetworkAttributesExtractorTest.java | 60 +++++++++- ...ributesExtractorInetSocketAddressTest.java | 82 ------------- .../ServerAttributesExtractorTest.java | 61 +--------- .../DubboNetworkServerAttributesGetter.java | 8 +- .../v2_7/DubboTelemetryBuilder.java | 5 +- .../DubboClientNetworkAttributesGetter.java | 6 +- .../apachedubbo/v2_7/AbstractDubboTest.groovy | 8 +- .../v2_7/AbstractDubboTraceChainTest.groovy | 10 +- .../apachecamel/RestCamelTest.java | 3 + .../CassandraNetworkAttributesGetter.java | 6 +- .../cassandra/v3_0/CassandraSingletons.java | 4 +- .../CassandraNetworkAttributesGetter.java | 6 +- .../cassandra/v4_0/CassandraSingletons.java | 4 +- .../CassandraNetworkAttributesGetter.java | 6 +- .../v4_4/CassandraTelemetryBuilder.java | 4 +- .../CouchbaseNetworkAttributesGetter.java | 6 +- .../couchbase/v2_0/CouchbaseSingletons.java | 9 +- .../Elasticsearch5TransportSingletons.java | 4 +- .../Elasticsearch5TransportClientTest.groovy | 5 - .../Elasticsearch53TransportSingletons.java | 4 +- .../Elasticsearch53TransportClientTest.groovy | 5 - ...arch6TransportNetworkAttributesGetter.java | 6 +- .../Elasticsearch6TransportSingletons.java | 4 +- ...asticTransportNetworkAttributesGetter.java | 30 +---- .../GrpcNetworkServerAttributesGetter.java | 8 +- .../grpc/v1_6/GrpcTelemetryBuilder.java | 5 +- .../GrpcClientNetworkAttributesGetter.java | 6 +- .../grpc/v1_6/AbstractGrpcStreamingTest.java | 3 + .../grpc/v1_6/AbstractGrpcTest.java | 31 +++++ .../groovy/AbstractJaxRsHttpServerTest.groovy | 1 + .../v3_0/JedisNetworkAttributesGetter.java | 7 +- .../jedis/v3_0/JedisSingletons.java | 2 + .../jedis/v3_0/Jedis30ClientTest.java | 42 ++++++- .../v4_0/JedisNetworkAttributesGetter.java | 6 +- .../jedis/v4_0/JedisSingletons.java | 9 +- .../src/main/groovy/BaseJsfTest.groovy | 1 + .../src/main/groovy/BaseJsfTest.groovy | 1 + .../JspInstrumentationBasicTests.groovy | 8 ++ .../JspInstrumentationForwardTests.groovy | 6 + .../v5_1/LettuceNetworkAttributesGetter.java | 6 +- .../lettuce/v5_1/OpenTelemetryTracing.java | 4 +- .../test/groovy/Netty40ClientSslTest.groovy | 20 ++-- .../groovy/Netty40ConnectionSpanTest.groovy | 10 +- .../test/groovy/Netty41ClientSslTest.groovy | 20 ++-- .../groovy/Netty41ConnectionSpanTest.groovy | 10 +- .../v0_9/ReactorNettyConnectionSpanTest.java | 11 +- .../v1_0/ReactorNettyBaseUrlOnlyTest.java | 5 +- .../v1_0/ReactorNettyClientSslTest.java | 15 ++- .../v1_0/ReactorNettyConnectionSpanTest.java | 10 +- .../redisson/RedissonInstrumenterFactory.java | 4 +- .../redisson/RedissonNetAttributesGetter.java | 6 +- .../sparkjava/SparkJavaBasedTest.java | 5 +- .../v5_0/server/SpringWebfluxTest.java | 11 ++ .../src/test/groovy/UndertowServerTest.groovy | 12 +- .../VertxReactivePropagationTest.groovy | 2 + .../VertxReactivePropagationTest.groovy | 2 + .../junit/http/AbstractHttpClientTest.java | 11 +- .../junit/http/SemconvStabilityUtil.java | 12 +- 106 files changed, 1137 insertions(+), 885 deletions(-) rename instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/{ClientAddressAndPortExtractor.java => ForwardedAddressAndPortExtractor.java} (95%) rename instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/{HttpAddressPortExtractor.java => HostAddressAndPortExtractor.java} (84%) rename instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/{FallbackAddressPortExtractor.java => AddressAndPortExtractor.java} (64%) create mode 100644 instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/ClientAddressAndPortExtractor.java create mode 100644 instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/NetworkAttributes.java create mode 100644 instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/ServerAddressAndPortExtractor.java rename instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/{ClientAddressAndPortExtractorTest.java => ForwardedAddressAndPortExtractorTest.java} (96%) rename instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/{HttpAddressPortExtractorTest.java => HostAddressAndPortExtractorTest.java} (90%) delete mode 100644 instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorInetSocketAddressTest.java create mode 100644 instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorInetSocketAddressTest.java delete mode 100644 instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorInetSocketAddressTest.java diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientAddressAndPortExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedAddressAndPortExtractor.java similarity index 95% rename from instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientAddressAndPortExtractor.java rename to instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedAddressAndPortExtractor.java index 7ac0fb98399a..a9d625d61b42 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientAddressAndPortExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedAddressAndPortExtractor.java @@ -5,15 +5,14 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; import java.util.Locale; -final class ClientAddressAndPortExtractor - implements FallbackAddressPortExtractor { +final class ForwardedAddressAndPortExtractor implements AddressAndPortExtractor { private final HttpServerAttributesGetter getter; - ClientAddressAndPortExtractor(HttpServerAttributesGetter getter) { + ForwardedAddressAndPortExtractor(HttpServerAttributesGetter getter) { this.getter = getter; } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAddressPortExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HostAddressAndPortExtractor.java similarity index 84% rename from instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAddressPortExtractor.java rename to instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HostAddressAndPortExtractor.java index bd56f8e87b8d..8da25acf58c5 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAddressPortExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HostAddressAndPortExtractor.java @@ -8,16 +8,16 @@ import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpCommonAttributesExtractor.firstHeaderValue; import static java.util.logging.Level.FINE; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; import java.util.logging.Logger; -final class HttpAddressPortExtractor implements FallbackAddressPortExtractor { +final class HostAddressAndPortExtractor implements AddressAndPortExtractor { private static final Logger logger = Logger.getLogger(HttpCommonAttributesGetter.class.getName()); private final HttpCommonAttributesGetter getter; - HttpAddressPortExtractor(HttpCommonAttributesGetter getter) { + HostAddressAndPortExtractor(HttpCommonAttributesGetter getter) { this.getter = getter; } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java index 695bc671b8fa..81e91b1be205 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java @@ -85,7 +85,7 @@ public static HttpClientAttributesExtractorBuilder internalNetExtractor; private final InternalNetworkAttributesExtractor internalNetworkExtractor; - private final InternalServerAttributesExtractor internalServerExtractor; + private final InternalServerAttributesExtractor internalServerExtractor; private final ToIntFunction resendCountIncrementer; HttpClientAttributesExtractor(HttpClientAttributesExtractorBuilder builder) { @@ -133,7 +133,6 @@ public void onEnd( internalNetExtractor.onEnd(attributes, request, response); internalNetworkExtractor.onEnd(attributes, request, response); - internalServerExtractor.onEnd(attributes, request, response); } /** 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 e06a9824c7e1..502f4b5612c3 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 @@ -11,8 +11,10 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ServerAddressAndPortExtractor; import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.api.internal.SemconvStability; import java.util.ArrayList; @@ -31,7 +33,7 @@ public final class HttpClientAttributesExtractorBuilder { REQUEST, RESPONSE> netAttributesGetter; - final HttpAddressPortExtractor addressPortExtractor; + final AddressAndPortExtractor serverAddressAndPortExtractor; List capturedRequestHeaders = emptyList(); List capturedResponseHeaders = emptyList(); Set knownMethods = HttpConstants.KNOWN_METHODS; @@ -45,7 +47,9 @@ public final class HttpClientAttributesExtractorBuilder { netAttributesGetter) { this.httpAttributesGetter = httpAttributesGetter; this.netAttributesGetter = netAttributesGetter; - addressPortExtractor = new HttpAddressPortExtractor<>(httpAttributesGetter); + serverAddressAndPortExtractor = + new ServerAddressAndPortExtractor<>( + netAttributesGetter, new HostAddressAndPortExtractor<>(httpAttributesGetter)); } /** @@ -125,25 +129,27 @@ public AttributesExtractor build() { InternalNetClientAttributesExtractor buildNetExtractor() { return new InternalNetClientAttributesExtractor<>( - netAttributesGetter, addressPortExtractor, SemconvStability.emitOldHttpSemconv()); + netAttributesGetter, serverAddressAndPortExtractor, SemconvStability.emitOldHttpSemconv()); } InternalNetworkAttributesExtractor buildNetworkExtractor() { return new InternalNetworkAttributesExtractor<>( netAttributesGetter, HttpNetworkTransportFilter.INSTANCE, + AddressAndPortExtractor.noop(), + serverAddressAndPortExtractor, + /* captureLocalSocketAttributes= */ false, + /* captureOldPeerDomainAttribute= */ true, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv()); } - InternalServerAttributesExtractor buildServerExtractor() { + InternalServerAttributesExtractor buildServerExtractor() { return new InternalServerAttributesExtractor<>( - netAttributesGetter, new ClientSideServerPortCondition<>(httpAttributesGetter), - addressPortExtractor, + serverAddressAndPortExtractor, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv(), - InternalServerAttributesExtractor.Mode.PEER, - /* captureServerSocketAttributes= */ true); + InternalServerAttributesExtractor.Mode.PEER); } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java index eb851e56c04c..58411f67b904 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java @@ -86,8 +86,8 @@ public static HttpServerAttributesExtractorBuilder internalUrlExtractor; private final InternalNetServerAttributesExtractor internalNetExtractor; private final InternalNetworkAttributesExtractor internalNetworkExtractor; - private final InternalServerAttributesExtractor internalServerExtractor; - private final InternalClientAttributesExtractor internalClientExtractor; + private final InternalServerAttributesExtractor internalServerExtractor; + private final InternalClientAttributesExtractor internalClientExtractor; private final Function httpRouteGetter; HttpServerAttributesExtractor(HttpServerAttributesExtractorBuilder builder) { @@ -128,8 +128,6 @@ public void onEnd( super.onEnd(attributes, context, request, response, error); internalNetworkExtractor.onEnd(attributes, request, response); - internalServerExtractor.onEnd(attributes, request, response); - internalClientExtractor.onEnd(attributes, request, response); internalSet(attributes, SemanticAttributes.HTTP_ROUTE, httpRouteGetter.apply(context)); } 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 6fda831705a3..e61f583dc4c5 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 @@ -11,9 +11,12 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ClientAddressAndPortExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ServerAddressAndPortExtractor; import io.opentelemetry.instrumentation.api.instrumenter.url.internal.InternalUrlAttributesExtractor; import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.api.internal.SemconvStability; @@ -33,7 +36,8 @@ public final class HttpServerAttributesExtractorBuilder { REQUEST, RESPONSE> netAttributesGetter; - final HttpAddressPortExtractor addressPortExtractor; + final AddressAndPortExtractor clientAddressPortExtractor; + final AddressAndPortExtractor serverAddressPortExtractor; List capturedRequestHeaders = emptyList(); List capturedResponseHeaders = emptyList(); Set knownMethods = HttpConstants.KNOWN_METHODS; @@ -47,7 +51,13 @@ public final class HttpServerAttributesExtractorBuilder { netAttributesGetter) { this.httpAttributesGetter = httpAttributesGetter; this.netAttributesGetter = netAttributesGetter; - addressPortExtractor = new HttpAddressPortExtractor<>(httpAttributesGetter); + + clientAddressPortExtractor = + new ClientAddressAndPortExtractor<>( + netAttributesGetter, new ForwardedAddressAndPortExtractor<>(httpAttributesGetter)); + serverAddressPortExtractor = + new ServerAddressAndPortExtractor<>( + netAttributesGetter, new HostAddressAndPortExtractor<>(httpAttributesGetter)); } /** @@ -135,32 +145,33 @@ InternalUrlAttributesExtractor buildUrlExtractor() { InternalNetServerAttributesExtractor buildNetExtractor() { return new InternalNetServerAttributesExtractor<>( - netAttributesGetter, addressPortExtractor, SemconvStability.emitOldHttpSemconv()); + netAttributesGetter, serverAddressPortExtractor, SemconvStability.emitOldHttpSemconv()); } InternalNetworkAttributesExtractor buildNetworkExtractor() { return new InternalNetworkAttributesExtractor<>( netAttributesGetter, HttpNetworkTransportFilter.INSTANCE, + serverAddressPortExtractor, + clientAddressPortExtractor, + /* captureLocalSocketAttributes= */ false, + /* captureOldPeerDomainAttribute= */ false, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv()); } - InternalServerAttributesExtractor buildServerExtractor() { + InternalServerAttributesExtractor buildServerExtractor() { return new InternalServerAttributesExtractor<>( - netAttributesGetter, new ServerSideServerPortCondition<>(httpAttributesGetter), - addressPortExtractor, + serverAddressPortExtractor, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv(), - InternalServerAttributesExtractor.Mode.HOST, - /* captureServerSocketAttributes= */ false); + InternalServerAttributesExtractor.Mode.HOST); } - InternalClientAttributesExtractor buildClientExtractor() { + InternalClientAttributesExtractor buildClientExtractor() { return new InternalClientAttributesExtractor<>( - netAttributesGetter, - new ClientAddressAndPortExtractor<>(httpAttributesGetter), + clientAddressPortExtractor, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv()); } 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 04665033183f..e74291670d65 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 @@ -9,10 +9,11 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ServerAddressAndPortExtractor; import io.opentelemetry.instrumentation.api.internal.SemconvStability; import javax.annotation.Nullable; @@ -33,7 +34,7 @@ public final class NetClientAttributesExtractor private final InternalNetClientAttributesExtractor internalExtractor; private final InternalNetworkAttributesExtractor internalNetworkExtractor; - private final InternalServerAttributesExtractor internalServerExtractor; + private final InternalServerAttributesExtractor internalServerExtractor; public static AttributesExtractor create( NetClientAttributesGetter getter) { @@ -41,24 +42,29 @@ public static AttributesExtractor create( } private NetClientAttributesExtractor(NetClientAttributesGetter getter) { + ServerAddressAndPortExtractor serverAddressAndPortExtractor = + new ServerAddressAndPortExtractor<>(getter, AddressAndPortExtractor.noop()); + internalExtractor = new InternalNetClientAttributesExtractor<>( - getter, FallbackAddressPortExtractor.noop(), SemconvStability.emitOldHttpSemconv()); + getter, AddressAndPortExtractor.noop(), SemconvStability.emitOldHttpSemconv()); internalNetworkExtractor = new InternalNetworkAttributesExtractor<>( getter, NetworkTransportFilter.alwaysTrue(), + AddressAndPortExtractor.noop(), + serverAddressAndPortExtractor, + /* captureLocalSocketAttributes= */ false, + /* captureOldPeerDomainAttribute= */ true, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv()); internalServerExtractor = new InternalServerAttributesExtractor<>( - getter, (port, request) -> true, - FallbackAddressPortExtractor.noop(), + serverAddressAndPortExtractor, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv(), - InternalServerAttributesExtractor.Mode.PEER, - /* captureServerSocketAttributes= */ true); + InternalServerAttributesExtractor.Mode.PEER); } @Override @@ -75,6 +81,5 @@ public void onEnd( @Nullable Throwable error) { internalExtractor.onEnd(attributes, request, response); internalNetworkExtractor.onEnd(attributes, request, response); - internalServerExtractor.onEnd(attributes, request, response); } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesGetter.java index e6384b158ed6..05d79725d736 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesGetter.java @@ -56,4 +56,23 @@ default String getNetworkType(REQUEST request, @Nullable RESPONSE response) { return InetSocketAddressUtil.getNetworkType( getServerInetSocketAddress(request, response), null); } + + @Nullable + @Override + default InetSocketAddress getNetworkPeerInetSocketAddress( + REQUEST request, @Nullable RESPONSE response) { + return getServerInetSocketAddress(request, response); + } + + @Nullable + @Override + default String getNetworkPeerAddress(REQUEST request, @Nullable RESPONSE response) { + return getServerSocketAddress(request, response); + } + + @Nullable + @Override + default Integer getNetworkPeerPort(REQUEST request, @Nullable RESPONSE response) { + return getServerSocketPort(request, response); + } } 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 9f8d4dbbaba3..b819c4a2997a 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 @@ -9,11 +9,13 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ClientAddressAndPortExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ServerAddressAndPortExtractor; import io.opentelemetry.instrumentation.api.internal.SemconvStability; import javax.annotation.Nullable; @@ -36,32 +38,38 @@ public static AttributesExtractor create( private final InternalNetServerAttributesExtractor internalExtractor; private final InternalNetworkAttributesExtractor internalNetworkExtractor; - private final InternalServerAttributesExtractor internalServerExtractor; - private final InternalClientAttributesExtractor internalClientExtractor; + private final InternalServerAttributesExtractor internalServerExtractor; + private final InternalClientAttributesExtractor internalClientExtractor; private NetServerAttributesExtractor(NetServerAttributesGetter getter) { + ServerAddressAndPortExtractor serverAddressAndPortExtractor = + new ServerAddressAndPortExtractor<>(getter, AddressAndPortExtractor.noop()); + ClientAddressAndPortExtractor clientAddressAndPortExtractor = + new ClientAddressAndPortExtractor<>(getter, AddressAndPortExtractor.noop()); + internalExtractor = new InternalNetServerAttributesExtractor<>( - getter, FallbackAddressPortExtractor.noop(), SemconvStability.emitOldHttpSemconv()); + getter, AddressAndPortExtractor.noop(), SemconvStability.emitOldHttpSemconv()); internalNetworkExtractor = new InternalNetworkAttributesExtractor<>( getter, NetworkTransportFilter.alwaysTrue(), + serverAddressAndPortExtractor, + clientAddressAndPortExtractor, + /* captureLocalSocketAttributes= */ true, + /* captureOldPeerDomainAttribute= */ false, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv()); internalServerExtractor = new InternalServerAttributesExtractor<>( - getter, (port, request) -> true, - FallbackAddressPortExtractor.noop(), + serverAddressAndPortExtractor, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv(), - InternalServerAttributesExtractor.Mode.HOST, - /* captureServerSocketAttributes= */ true); + InternalServerAttributesExtractor.Mode.HOST); internalClientExtractor = new InternalClientAttributesExtractor<>( - getter, - FallbackAddressPortExtractor.noop(), + clientAddressAndPortExtractor, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv()); } @@ -81,7 +89,5 @@ public void onEnd( @Nullable RESPONSE response, @Nullable Throwable error) { internalNetworkExtractor.onEnd(attributes, request, response); - internalServerExtractor.onEnd(attributes, request, response); - internalClientExtractor.onEnd(attributes, request, response); } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesGetter.java index 574e5ec1bcd1..0343c20aec23 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesGetter.java @@ -62,4 +62,42 @@ default String getNetworkType(REQUEST request, @Nullable RESPONSE response) { getClientInetSocketAddress(request, response), getServerInetSocketAddress(request, response)); } + + @Nullable + @Override + default InetSocketAddress getNetworkLocalInetSocketAddress( + REQUEST request, @Nullable RESPONSE response) { + return getServerInetSocketAddress(request, response); + } + + @Nullable + @Override + default String getNetworkLocalAddress(REQUEST request, @Nullable RESPONSE response) { + return getServerSocketAddress(request, response); + } + + @Nullable + @Override + default Integer getNetworkLocalPort(REQUEST request, @Nullable RESPONSE response) { + return getServerSocketPort(request, response); + } + + @Nullable + @Override + default InetSocketAddress getNetworkPeerInetSocketAddress( + REQUEST request, @Nullable RESPONSE response) { + return getClientInetSocketAddress(request, response); + } + + @Nullable + @Override + default String getNetworkPeerAddress(REQUEST request, @Nullable RESPONSE response) { + return getClientSocketAddress(request, response); + } + + @Nullable + @Override + default Integer getNetworkPeerPort(REQUEST request, @Nullable RESPONSE response) { + return getClientSocketPort(request, response); + } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java index 4d0a36d66ec1..f06fe03ebc44 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetClientAttributesExtractor.java @@ -8,8 +8,8 @@ import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPort; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ServerAddressAndPortExtractor; import io.opentelemetry.semconv.SemanticAttributes; import javax.annotation.Nullable; @@ -23,17 +23,18 @@ public final class InternalNetClientAttributesExtractor { private final io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter< REQUEST, RESPONSE> getter; - private final FallbackAddressPortExtractor fallbackAddressPortExtractor; + private final AddressAndPortExtractor logicalAddressAndPortExtractor; private final boolean emitOldHttpAttributes; public InternalNetClientAttributesExtractor( io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter< REQUEST, RESPONSE> getter, - FallbackAddressPortExtractor fallbackAddressPortExtractor, + AddressAndPortExtractor fallbackAddressAndPortExtractor, boolean emitOldHttpAttributes) { this.getter = getter; - this.fallbackAddressPortExtractor = fallbackAddressPortExtractor; + this.logicalAddressAndPortExtractor = + new ServerAddressAndPortExtractor<>(getter, fallbackAddressAndPortExtractor); this.emitOldHttpAttributes = emitOldHttpAttributes; } @@ -43,7 +44,7 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO internalSet( attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request, response)); - String peerName = extractPeerName(request); + String peerName = logicalAddressAndPortExtractor.extract(request).getAddress(); String sockPeerAddr = getter.getServerSocketAddress(request, response); if (sockPeerAddr != null && !sockPeerAddr.equals(peerName)) { String sockFamily = getter.getSockFamily(request, response); @@ -53,14 +54,4 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO } } } - - private String extractPeerName(REQUEST request) { - String serverAddress = getter.getServerAddress(request); - if (serverAddress != null) { - return serverAddress; - } - AddressAndPort addressAndPort = new AddressAndPort(); - fallbackAddressPortExtractor.extract(addressAndPort, request); - return addressAndPort.getAddress(); - } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java index 591a5b08e646..cc1d14a7bd75 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.java @@ -9,7 +9,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPort; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; import io.opentelemetry.semconv.SemanticAttributes; /** @@ -22,17 +22,17 @@ public final class InternalNetServerAttributesExtractor { private final io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter< REQUEST, RESPONSE> getter; - private final FallbackAddressPortExtractor fallbackAddressPortExtractor; + private final AddressAndPortExtractor fallbackAddressAndPortExtractor; private final boolean emitOldHttpAttributes; public InternalNetServerAttributesExtractor( io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter< REQUEST, RESPONSE> getter, - FallbackAddressPortExtractor fallbackAddressPortExtractor, + AddressAndPortExtractor fallbackAddressAndPortExtractor, boolean emitOldHttpAttributes) { this.getter = getter; - this.fallbackAddressPortExtractor = fallbackAddressPortExtractor; + this.fallbackAddressAndPortExtractor = fallbackAddressAndPortExtractor; this.emitOldHttpAttributes = emitOldHttpAttributes; } @@ -69,7 +69,7 @@ private String extractServerAddress(REQUEST request) { return serverAddress; } AddressAndPort addressAndPort = new AddressAndPort(); - fallbackAddressPortExtractor.extract(addressAndPort, request); + fallbackAddressAndPortExtractor.extract(addressAndPort, request); return addressAndPort.getAddress(); } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractor.java index 72342496e278..81e025b684c5 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractor.java @@ -8,7 +8,8 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ClientAddressAndPortExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor; import io.opentelemetry.instrumentation.api.internal.SemconvStability; import javax.annotation.Nullable; @@ -30,13 +31,12 @@ public static ClientAttributesExtractor c return new ClientAttributesExtractor<>(getter); } - private final InternalClientAttributesExtractor internalExtractor; + private final InternalClientAttributesExtractor internalExtractor; ClientAttributesExtractor(ClientAttributesGetter getter) { internalExtractor = new InternalClientAttributesExtractor<>( - getter, - FallbackAddressPortExtractor.noop(), + new ClientAddressAndPortExtractor<>(getter, AddressAndPortExtractor.noop()), SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv()); } @@ -52,7 +52,5 @@ public void onEnd( Context context, REQUEST request, @Nullable RESPONSE response, - @Nullable Throwable error) { - internalExtractor.onEnd(attributes, request, response); - } + @Nullable Throwable error) {} } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesGetter.java index 788854d7ec2b..89b4dad2fc65 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesGetter.java @@ -38,6 +38,8 @@ default Integer getClientPort(REQUEST request) { return null; } + // TODO deprecate + /** * Returns an {@link InetSocketAddress} object representing the immediate client socket address. * 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 ec9e0ac298da..825894041454 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 @@ -8,6 +8,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter; import io.opentelemetry.instrumentation.api.internal.SemconvStability; @@ -37,6 +38,11 @@ public static NetworkAttributesExtractor new InternalNetworkAttributesExtractor<>( getter, NetworkTransportFilter.alwaysTrue(), + AddressAndPortExtractor.noop(), + AddressAndPortExtractor.noop(), + /* captureLocalSocketAttributes= */ true, + // capture the old net.sock.peer.name attr for backwards compatibility + /* captureOldPeerDomainAttribute= */ true, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv()); } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesGetter.java index 0c172d253eec..e369b72f0b82 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesGetter.java @@ -5,6 +5,8 @@ package io.opentelemetry.instrumentation.api.instrumenter.network; +import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InetSocketAddressUtil; +import java.net.InetSocketAddress; import javax.annotation.Nullable; /** @@ -36,7 +38,9 @@ default String getNetworkTransport(REQUEST request, @Nullable RESPONSE response) */ @Nullable default String getNetworkType(REQUEST request, @Nullable RESPONSE response) { - return null; + return InetSocketAddressUtil.getNetworkType( + getNetworkLocalInetSocketAddress(request, response), + getNetworkPeerInetSocketAddress(request, response)); } /** @@ -59,4 +63,92 @@ default String getNetworkProtocolName(REQUEST request, @Nullable RESPONSE respon default String getNetworkProtocolVersion(REQUEST request, @Nullable RESPONSE response) { return null; } + + /** + * Returns an {@link InetSocketAddress} object representing the local socket address. + * + *

Implementing this method is equivalent to implementing both {@link + * #getNetworkLocalAddress(Object, Object)} and {@link #getNetworkLocalPort(Object, Object)}. + */ + @Nullable + default InetSocketAddress getNetworkLocalInetSocketAddress( + REQUEST request, @Nullable RESPONSE response) { + return null; + } + + /** + * Returns the local address of the network connection - IP address or Unix domain socket name. + * + *

Examples: {@code 10.1.2.80}, {@code /tmp/my.sock} + * + *

By default, this method attempts to retrieve the local address using the {@link + * #getNetworkLocalInetSocketAddress(Object, Object)} method. If this method is not implemented, + * it will simply return {@code null}. If the instrumented library does not expose {@link + * InetSocketAddress} in its API, you might want to implement this method instead of {@link + * #getNetworkLocalInetSocketAddress(Object, Object)}. + */ + @Nullable + default String getNetworkLocalAddress(REQUEST request, @Nullable RESPONSE response) { + return InetSocketAddressUtil.getIpAddress(getNetworkLocalInetSocketAddress(request, response)); + } + + /** + * Returns the local port number of the network connection. + * + *

Examples: {@code 65123} + * + *

By default, this method attempts to retrieve the local port using the {@link + * #getNetworkLocalInetSocketAddress(Object, Object)} method. If this method is not implemented, + * it will simply return {@code null}. If the instrumented library does not expose {@link + * InetSocketAddress} in its API, you might want to implement this method instead of {@link + * #getNetworkLocalInetSocketAddress(Object, Object)}. + */ + @Nullable + default Integer getNetworkLocalPort(REQUEST request, @Nullable RESPONSE response) { + return InetSocketAddressUtil.getPort(getNetworkLocalInetSocketAddress(request, response)); + } + + /** + * Returns an {@link InetSocketAddress} object representing the peer socket address. + * + *

Implementing this method is equivalent to implementing both {@link + * #getNetworkPeerAddress(Object, Object)} and {@link #getNetworkPeerPort(Object, Object)}. + */ + @Nullable + default InetSocketAddress getNetworkPeerInetSocketAddress( + REQUEST request, @Nullable RESPONSE response) { + return null; + } + + /** + * Returns the peer address of the network connection - IP address or Unix domain socket name. + * + *

Examples: {@code 10.1.2.80}, {@code /tmp/my.sock} + * + *

By default, this method attempts to retrieve the peer address using the {@link + * #getNetworkPeerInetSocketAddress(Object, Object)} method. If this method is not implemented, it + * will simply return {@code null}. If the instrumented library does not expose {@link + * InetSocketAddress} in its API, you might want to implement this method instead of {@link + * #getNetworkPeerInetSocketAddress(Object, Object)}. + */ + @Nullable + default String getNetworkPeerAddress(REQUEST request, @Nullable RESPONSE response) { + return InetSocketAddressUtil.getIpAddress(getNetworkPeerInetSocketAddress(request, response)); + } + + /** + * Returns the peer port number of the network connection. + * + *

Examples: {@code 65123} + * + *

By default, this method attempts to retrieve the peer port using the {@link + * #getNetworkPeerInetSocketAddress(Object, Object)} method. If this method is not implemented, it + * will simply return {@code null}. If the instrumented library does not expose {@link + * InetSocketAddress} in its API, you might want to implement this method instead of {@link + * #getNetworkPeerInetSocketAddress(Object, Object)}. + */ + @Nullable + default Integer getNetworkPeerPort(REQUEST request, @Nullable RESPONSE response) { + return InetSocketAddressUtil.getPort(getNetworkPeerInetSocketAddress(request, response)); + } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java index f8788d26ac6f..d6005b67aee1 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java @@ -8,8 +8,9 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ServerAddressAndPortExtractor; import io.opentelemetry.instrumentation.api.internal.SemconvStability; import javax.annotation.Nullable; @@ -45,7 +46,7 @@ ServerAttributesExtractor createForServerSide( return new ServerAttributesExtractor<>(getter, InternalServerAttributesExtractor.Mode.HOST); } - private final InternalServerAttributesExtractor internalExtractor; + private final InternalServerAttributesExtractor internalExtractor; ServerAttributesExtractor( ServerAttributesGetter getter, @@ -53,13 +54,11 @@ ServerAttributesExtractor createForServerSide( // the ServerAttributesExtractor will always emit new semconv internalExtractor = new InternalServerAttributesExtractor<>( - getter, (port, request) -> true, - FallbackAddressPortExtractor.noop(), + new ServerAddressAndPortExtractor<>(getter, AddressAndPortExtractor.noop()), SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv(), - mode, - /* captureServerSocketAttributes= */ true); + mode); } @Override @@ -73,7 +72,5 @@ public void onEnd( Context context, REQUEST request, @Nullable RESPONSE response, - @Nullable Throwable error) { - internalExtractor.onEnd(attributes, request, response); - } + @Nullable Throwable error) {} } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesGetter.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesGetter.java index 672f79a1b897..df24124d315a 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesGetter.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesGetter.java @@ -39,6 +39,8 @@ default Integer getServerPort(REQUEST request) { return null; } + // TODO deprecate + /** * Returns an {@link InetSocketAddress} object representing the server socket address. * diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/AddressAndPort.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/AddressAndPort.java index 803f9bc7d205..021de9c42121 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/AddressAndPort.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/AddressAndPort.java @@ -11,7 +11,7 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public final class AddressAndPort implements FallbackAddressPortExtractor.AddressPortSink { +public final class AddressAndPort implements AddressAndPortExtractor.AddressPortSink { @Nullable String address; @Nullable Integer port; @@ -22,7 +22,7 @@ public void setAddress(String address) { } @Override - public void setPort(int port) { + public void setPort(Integer port) { this.port = port; } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/FallbackAddressPortExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/AddressAndPortExtractor.java similarity index 64% rename from instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/FallbackAddressPortExtractor.java rename to instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/AddressAndPortExtractor.java index cc83917d53bf..8f1c96ae4d0f 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/FallbackAddressPortExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/AddressAndPortExtractor.java @@ -9,11 +9,17 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public interface FallbackAddressPortExtractor { +public interface AddressAndPortExtractor { + + default AddressAndPort extract(REQUEST request) { + AddressAndPort addressAndPort = new AddressAndPort(); + extract(addressAndPort, request); + return addressAndPort; + } void extract(AddressPortSink sink, REQUEST request); - static FallbackAddressPortExtractor noop() { + static AddressAndPortExtractor noop() { return (sink, request) -> {}; } @@ -25,6 +31,6 @@ interface AddressPortSink { void setAddress(String address); - void setPort(int port); + void setPort(Integer port); } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/ClientAddressAndPortExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/ClientAddressAndPortExtractor.java new file mode 100644 index 000000000000..a3dedd9518b6 --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/ClientAddressAndPortExtractor.java @@ -0,0 +1,38 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.network.internal; + +import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public final class ClientAddressAndPortExtractor + implements AddressAndPortExtractor { + + private final ClientAttributesGetter getter; + private final AddressAndPortExtractor fallbackAddressAndPortExtractor; + + public ClientAddressAndPortExtractor( + ClientAttributesGetter getter, + AddressAndPortExtractor fallbackAddressAndPortExtractor) { + this.getter = getter; + this.fallbackAddressAndPortExtractor = fallbackAddressAndPortExtractor; + } + + @Override + public void extract(AddressPortSink sink, REQUEST request) { + String address = getter.getClientAddress(request); + Integer port = getter.getClientPort(request); + if (address == null && port == null) { + fallbackAddressAndPortExtractor.extract(sink, request); + } else { + sink.setAddress(address); + sink.setPort(port); + } + } +} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalClientAttributesExtractor.java index 1a39f7c22139..a0d554f1b221 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalClientAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalClientAttributesExtractor.java @@ -8,35 +8,30 @@ import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter; import io.opentelemetry.semconv.SemanticAttributes; -import javax.annotation.Nullable; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public final class InternalClientAttributesExtractor { +public final class InternalClientAttributesExtractor { - private final ClientAttributesGetter getter; - private final FallbackAddressPortExtractor fallbackAddressPortExtractor; + private final AddressAndPortExtractor addressAndPortExtractor; private final boolean emitStableUrlAttributes; private final boolean emitOldHttpAttributes; public InternalClientAttributesExtractor( - ClientAttributesGetter getter, - FallbackAddressPortExtractor fallbackAddressPortExtractor, + AddressAndPortExtractor addressAndPortExtractor, boolean emitStableUrlAttributes, boolean emitOldHttpAttributes) { - this.getter = getter; - this.fallbackAddressPortExtractor = fallbackAddressPortExtractor; + this.addressAndPortExtractor = addressAndPortExtractor; this.emitStableUrlAttributes = emitStableUrlAttributes; this.emitOldHttpAttributes = emitOldHttpAttributes; } @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void onStart(AttributesBuilder attributes, REQUEST request) { - AddressAndPort clientAddressAndPort = extractClientAddressAndPort(request); + AddressAndPort clientAddressAndPort = addressAndPortExtractor.extract(request); if (emitStableUrlAttributes) { internalSet(attributes, SemanticAttributes.CLIENT_ADDRESS, clientAddressAndPort.address); @@ -48,40 +43,4 @@ public void onStart(AttributesBuilder attributes, REQUEST request) { internalSet(attributes, SemanticAttributes.HTTP_CLIENT_IP, clientAddressAndPort.address); } } - - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 - public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response) { - AddressAndPort clientAddressAndPort = extractClientAddressAndPort(request); - String clientSocketAddress = getter.getClientSocketAddress(request, response); - Integer clientSocketPort = getter.getClientSocketPort(request, response); - - if (clientSocketAddress != null && !clientSocketAddress.equals(clientAddressAndPort.address)) { - if (emitStableUrlAttributes) { - internalSet(attributes, SemanticAttributes.CLIENT_SOCKET_ADDRESS, clientSocketAddress); - } - if (emitOldHttpAttributes) { - internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_ADDR, clientSocketAddress); - } - } - if (clientSocketPort != null && clientSocketPort > 0) { - if (emitStableUrlAttributes) { - if (!clientSocketPort.equals(clientAddressAndPort.port)) { - internalSet(attributes, SemanticAttributes.CLIENT_SOCKET_PORT, (long) clientSocketPort); - } - } - if (emitOldHttpAttributes) { - internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_PORT, (long) clientSocketPort); - } - } - } - - private AddressAndPort extractClientAddressAndPort(REQUEST request) { - AddressAndPort addressAndPort = new AddressAndPort(); - addressAndPort.address = getter.getClientAddress(request); - addressAndPort.port = getter.getClientPort(request); - if (addressAndPort.address == null && addressAndPort.port == null) { - fallbackAddressPortExtractor.extract(addressAndPort, request); - } - return addressAndPort; - } } 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 3a43fd3c9e7f..2f9eac0312dc 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 @@ -8,8 +8,10 @@ import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InetSocketAddressUtil; import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import io.opentelemetry.semconv.SemanticAttributes; +import java.net.InetSocketAddress; import java.util.Locale; import javax.annotation.Nullable; @@ -21,16 +23,28 @@ public final class InternalNetworkAttributesExtractor { private final NetworkAttributesGetter getter; private final NetworkTransportFilter networkTransportFilter; + private final AddressAndPortExtractor logicalLocalAddressAndPortExtractor; + private final AddressAndPortExtractor logicalPeerAddressAndPortExtractor; + private final boolean captureLocalSocketAttributes; + private final boolean captureOldPeerDomainAttribute; private final boolean emitStableUrlAttributes; private final boolean emitOldHttpAttributes; public InternalNetworkAttributesExtractor( NetworkAttributesGetter getter, NetworkTransportFilter networkTransportFilter, + AddressAndPortExtractor logicalLocalAddressAndPortExtractor, + AddressAndPortExtractor logicalPeerAddressAndPortExtractor, + boolean captureLocalSocketAttributes, + boolean captureOldPeerDomainAttribute, boolean emitStableUrlAttributes, boolean emitOldHttpAttributes) { this.getter = getter; this.networkTransportFilter = networkTransportFilter; + this.logicalLocalAddressAndPortExtractor = logicalLocalAddressAndPortExtractor; + this.logicalPeerAddressAndPortExtractor = logicalPeerAddressAndPortExtractor; + this.captureLocalSocketAttributes = captureLocalSocketAttributes; + this.captureOldPeerDomainAttribute = captureOldPeerDomainAttribute; this.emitStableUrlAttributes = emitStableUrlAttributes; this.emitOldHttpAttributes = emitOldHttpAttributes; } @@ -59,6 +73,59 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO internalSet(attributes, SemanticAttributes.NET_PROTOCOL_NAME, protocolName); internalSet(attributes, SemanticAttributes.NET_PROTOCOL_VERSION, protocolVersion); } + + String localAddress = getter.getNetworkLocalAddress(request, response); + String logicalLocalAddress = logicalLocalAddressAndPortExtractor.extract(request).address; + if (localAddress != null && !localAddress.equals(logicalLocalAddress)) { + if (emitStableUrlAttributes && captureLocalSocketAttributes) { + internalSet(attributes, NetworkAttributes.NETWORK_LOCAL_ADDRESS, localAddress); + } + if (emitOldHttpAttributes) { + internalSet(attributes, SemanticAttributes.NET_SOCK_HOST_ADDR, localAddress); + } + + Integer localPort = getter.getNetworkLocalPort(request, response); + if (localPort != null && localPort > 0) { + if (emitStableUrlAttributes && captureLocalSocketAttributes) { + internalSet(attributes, NetworkAttributes.NETWORK_LOCAL_PORT, (long) localPort); + } + if (emitOldHttpAttributes) { + internalSet(attributes, SemanticAttributes.NET_SOCK_HOST_PORT, (long) localPort); + } + } + } + + String peerAddress = getter.getNetworkPeerAddress(request, response); + String logicalPeerAddress = logicalPeerAddressAndPortExtractor.extract(request).address; + if (peerAddress != null && !peerAddress.equals(logicalPeerAddress)) { + if (emitStableUrlAttributes) { + internalSet(attributes, NetworkAttributes.NETWORK_PEER_ADDRESS, peerAddress); + } + if (emitOldHttpAttributes) { + internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_ADDR, peerAddress); + } + + Integer peerPort = getter.getNetworkPeerPort(request, response); + if (peerPort != null && peerPort > 0) { + if (emitStableUrlAttributes) { + internalSet(attributes, NetworkAttributes.NETWORK_PEER_PORT, (long) peerPort); + } + if (emitOldHttpAttributes) { + internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_PORT, (long) peerPort); + } + } + + if (emitOldHttpAttributes && captureOldPeerDomainAttribute) { + InetSocketAddress peerSocketAddress = + getter.getNetworkPeerInetSocketAddress(request, response); + if (peerSocketAddress != null) { + String peerSocketDomain = InetSocketAddressUtil.getDomainName(peerSocketAddress); + if (peerSocketDomain != null && !peerSocketDomain.equals(logicalPeerAddress)) { + internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_NAME, peerSocketDomain); + } + } + } + } } @Nullable diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java index b00fd5c7f5d5..e0611409c435 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java @@ -9,44 +9,36 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; import io.opentelemetry.semconv.SemanticAttributes; import java.util.function.BiPredicate; -import javax.annotation.Nullable; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public final class InternalServerAttributesExtractor { +public final class InternalServerAttributesExtractor { - private final ServerAttributesGetter getter; private final BiPredicate captureServerPortCondition; - private final FallbackAddressPortExtractor fallbackAddressPortExtractor; + private final AddressAndPortExtractor addressAndPortExtractor; private final boolean emitStableUrlAttributes; private final boolean emitOldHttpAttributes; private final Mode oldSemconvMode; - private final boolean captureServerSocketAttributes; public InternalServerAttributesExtractor( - ServerAttributesGetter getter, BiPredicate captureServerPortCondition, - FallbackAddressPortExtractor fallbackAddressPortExtractor, + AddressAndPortExtractor addressAndPortExtractor, boolean emitStableUrlAttributes, boolean emitOldHttpAttributes, - Mode oldSemconvMode, - boolean captureServerSocketAttributes) { - this.getter = getter; + Mode oldSemconvMode) { this.captureServerPortCondition = captureServerPortCondition; - this.fallbackAddressPortExtractor = fallbackAddressPortExtractor; + this.addressAndPortExtractor = addressAndPortExtractor; this.emitStableUrlAttributes = emitStableUrlAttributes; this.emitOldHttpAttributes = emitOldHttpAttributes; this.oldSemconvMode = oldSemconvMode; - this.captureServerSocketAttributes = captureServerSocketAttributes; } public void onStart(AttributesBuilder attributes, REQUEST request) { - AddressAndPort serverAddressAndPort = extractServerAddressAndPort(request); + AddressAndPort serverAddressAndPort = addressAndPortExtractor.extract(request); if (emitStableUrlAttributes) { internalSet(attributes, SemanticAttributes.SERVER_ADDRESS, serverAddressAndPort.address); @@ -67,52 +59,6 @@ public void onStart(AttributesBuilder attributes, REQUEST request) { } } - public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response) { - AddressAndPort serverAddressAndPort = extractServerAddressAndPort(request); - - String serverSocketAddress = getter.getServerSocketAddress(request, response); - if (serverSocketAddress != null && !serverSocketAddress.equals(serverAddressAndPort.address)) { - if (emitStableUrlAttributes && captureServerSocketAttributes) { - internalSet(attributes, SemanticAttributes.SERVER_SOCKET_ADDRESS, serverSocketAddress); - } - if (emitOldHttpAttributes) { - internalSet(attributes, oldSemconvMode.socketAddress, serverSocketAddress); - } - } - - Integer serverSocketPort = getter.getServerSocketPort(request, response); - if (serverSocketPort != null - && serverSocketPort > 0 - && !serverSocketPort.equals(serverAddressAndPort.port)) { - if (emitStableUrlAttributes && captureServerSocketAttributes) { - internalSet(attributes, SemanticAttributes.SERVER_SOCKET_PORT, (long) serverSocketPort); - } - if (emitOldHttpAttributes) { - internalSet(attributes, oldSemconvMode.socketPort, (long) serverSocketPort); - } - } - - String serverSocketDomain = getter.getServerSocketDomain(request, response); - if (serverSocketDomain != null && !serverSocketDomain.equals(serverAddressAndPort.address)) { - if (emitStableUrlAttributes && captureServerSocketAttributes) { - internalSet(attributes, SemanticAttributes.SERVER_SOCKET_DOMAIN, serverSocketDomain); - } - if (emitOldHttpAttributes && oldSemconvMode.socketDomain != null) { - internalSet(attributes, oldSemconvMode.socketDomain, serverSocketDomain); - } - } - } - - private AddressAndPort extractServerAddressAndPort(REQUEST request) { - AddressAndPort addressAndPort = new AddressAndPort(); - addressAndPort.address = getter.getServerAddress(request); - addressAndPort.port = getter.getServerPort(request); - if (addressAndPort.address == null && addressAndPort.port == null) { - fallbackAddressPortExtractor.extract(addressAndPort, request); - } - return addressAndPort; - } - /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. @@ -122,37 +68,15 @@ private AddressAndPort extractServerAddressAndPort(REQUEST request) { "deprecation" }) // until old http semconv are dropped in 2.0 public enum Mode { - PEER( - SemanticAttributes.NET_PEER_NAME, - SemanticAttributes.NET_PEER_PORT, - SemanticAttributes.NET_SOCK_PEER_NAME, - SemanticAttributes.NET_SOCK_PEER_ADDR, - SemanticAttributes.NET_SOCK_PEER_PORT), - HOST( - SemanticAttributes.NET_HOST_NAME, - SemanticAttributes.NET_HOST_PORT, - // the old semconv does not have an attribute for this - null, - SemanticAttributes.NET_SOCK_HOST_ADDR, - SemanticAttributes.NET_SOCK_HOST_PORT); + PEER(SemanticAttributes.NET_PEER_NAME, SemanticAttributes.NET_PEER_PORT), + HOST(SemanticAttributes.NET_HOST_NAME, SemanticAttributes.NET_HOST_PORT); final AttributeKey address; final AttributeKey port; - @Nullable final AttributeKey socketDomain; - final AttributeKey socketAddress; - final AttributeKey socketPort; - Mode( - AttributeKey address, - AttributeKey port, - AttributeKey socketDomain, - AttributeKey socketAddress, - AttributeKey socketPort) { + Mode(AttributeKey address, AttributeKey port) { this.address = address; this.port = port; - this.socketDomain = socketDomain; - this.socketAddress = socketAddress; - this.socketPort = socketPort; } } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/NetworkAttributes.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/NetworkAttributes.java new file mode 100644 index 000000000000..4fa1ccd57fc8 --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/NetworkAttributes.java @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.network.internal; + +import static io.opentelemetry.api.common.AttributeKey.longKey; +import static io.opentelemetry.api.common.AttributeKey.stringKey; + +import io.opentelemetry.api.common.AttributeKey; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public final class NetworkAttributes { + + public static final AttributeKey NETWORK_LOCAL_ADDRESS = + stringKey("network.local.address"); + + public static final AttributeKey NETWORK_LOCAL_PORT = longKey("network.local.port"); + + public static final AttributeKey NETWORK_PEER_ADDRESS = stringKey("network.peer.address"); + + public static final AttributeKey NETWORK_PEER_PORT = longKey("network.peer.port"); + + private NetworkAttributes() {} +} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/ServerAddressAndPortExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/ServerAddressAndPortExtractor.java new file mode 100644 index 000000000000..41f4d3c6554e --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/ServerAddressAndPortExtractor.java @@ -0,0 +1,38 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.network.internal; + +import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public final class ServerAddressAndPortExtractor + implements AddressAndPortExtractor { + + private final ServerAttributesGetter getter; + private final AddressAndPortExtractor fallbackAddressAndPortExtractor; + + public ServerAddressAndPortExtractor( + ServerAttributesGetter getter, + AddressAndPortExtractor fallbackAddressAndPortExtractor) { + this.getter = getter; + this.fallbackAddressAndPortExtractor = fallbackAddressAndPortExtractor; + } + + @Override + public void extract(AddressPortSink sink, REQUEST request) { + String address = getter.getServerAddress(request); + Integer port = getter.getServerPort(request); + if (address == null && port == null) { + fallbackAddressAndPortExtractor.extract(sink, request); + } else { + sink.setAddress(address); + sink.setPort(port); + } + } +} diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientAddressAndPortExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedAddressAndPortExtractorTest.java similarity index 96% rename from instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientAddressAndPortExtractorTest.java rename to instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedAddressAndPortExtractorTest.java index d1ae3f0b12f3..fe755c1606b5 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientAddressAndPortExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ForwardedAddressAndPortExtractorTest.java @@ -12,7 +12,7 @@ import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.mockito.Mockito.doReturn; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; import java.util.List; import java.util.stream.Stream; import javax.annotation.Nullable; @@ -27,11 +27,11 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class ClientAddressAndPortExtractorTest { +class ForwardedAddressAndPortExtractorTest { @Mock HttpServerAttributesGetter getter; - @InjectMocks ClientAddressAndPortExtractor underTest; + @InjectMocks ForwardedAddressAndPortExtractor underTest; @ParameterizedTest @ArgumentsSource(ForwardedArgs.class) @@ -148,7 +148,7 @@ public Stream provideArguments(ExtensionContext extensionCo } } - static final class AddressAndPort implements FallbackAddressPortExtractor.AddressPortSink { + static final class AddressAndPort implements AddressAndPortExtractor.AddressPortSink { @Nullable String address = null; @Nullable Integer port = null; @@ -159,7 +159,7 @@ public void setAddress(String address) { } @Override - public void setPort(int port) { + public void setPort(Integer port) { this.port = port; } } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAddressPortExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HostAddressAndPortExtractorTest.java similarity index 90% rename from instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAddressPortExtractorTest.java rename to instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HostAddressAndPortExtractorTest.java index 10692f2be131..cee35b9e9f1b 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAddressPortExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HostAddressAndPortExtractorTest.java @@ -12,7 +12,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -20,14 +20,14 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class HttpAddressPortExtractorTest { +class HostAddressAndPortExtractorTest { private static final String REQUEST = "request"; @Mock HttpCommonAttributesGetter getter; - @Mock FallbackAddressPortExtractor.AddressPortSink sink; + @Mock AddressAndPortExtractor.AddressPortSink sink; - @InjectMocks HttpAddressPortExtractor underTest; + @InjectMocks HostAddressAndPortExtractor underTest; @Test void noHostHeader() { diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetterTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetterTest.java index c02f4c74ace5..72341c84e7be 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetterTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetterTest.java @@ -6,7 +6,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.net; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static org.assertj.core.api.Assertions.entry; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; @@ -105,10 +104,6 @@ void unresolved() { // then assertThat(startAttributes.build()).isEmpty(); - - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_SOCK_PEER_NAME, "api.github.com"), - entry(SemanticAttributes.NET_SOCK_PEER_PORT, 456L)); + assertThat(endAttributes.build()).isEmpty(); } } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java index 9c36ba973918..c06874fc80de 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java @@ -117,11 +117,7 @@ void unresolved() { // then assertThat(startAttributes.build()).isEmpty(); - - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L), - entry(SemanticAttributes.NET_SOCK_HOST_PORT, 456L)); + assertThat(endAttributes.build()).isEmpty(); } static final class Addresses { 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 5331f44cb845..79110451086c 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 @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.Map; import javax.annotation.Nullable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @SuppressWarnings("deprecation") // testing deprecated class @@ -78,7 +77,9 @@ public String getSockFamily(Map request, Map res @Override public String getServerSocketDomain(Map request, Map response) { - return response.get("sockPeerName"); + // we only support the InetSocketAddress case here; nearly no instrumentations override this + // method anyway + return null; } @Override @@ -110,7 +111,6 @@ void normal() { 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(); @@ -135,7 +135,6 @@ void normal() { entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"), entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), - entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"), entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L)); } @@ -157,9 +156,7 @@ void empty() { } @Test - @DisplayName( - "does not set those net.sock.peer.* attributes that duplicate corresponding net.peer.* attributes") - void doesNotSetDuplicates1() { + void doesNotSetDuplicateSocketAddress() { // given Map map = new HashMap<>(); map.put("netTransport", IP_TCP); @@ -185,47 +182,7 @@ void doesNotSetDuplicates1() { 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), - entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"), - entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L)); - } - - @Test - @DisplayName( - "does not set net.sock.* attributes when they duplicate related net.peer.* attributes") - void doesNotSetDuplicates2() { - // given - Map map = new HashMap<>(); - map.put("netTransport", IP_TCP); - map.put("peerName", "opentelemetry.io"); - map.put("peerPort", "42"); - map.put("sockFamily", "inet6"); - map.put("sockPeerAddr", "1:2:3:4::"); - map.put("sockPeerName", "opentelemetry.io"); - map.put("sockPeerPort", "42"); - - 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, "opentelemetry.io"), - entry(SemanticAttributes.NET_PEER_PORT, 42L)); - - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), - entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"), - entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::")); + assertThat(endAttributes.build()).containsOnly(entry(SemanticAttributes.NET_TRANSPORT, IP_TCP)); } @Test 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 ec41cf0d197a..e4d9b443dc1f 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 @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.Map; import javax.annotation.Nullable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @SuppressWarnings("deprecation") // testing deprecated class @@ -165,9 +164,7 @@ void empty() { } @Test - @DisplayName( - "does not set those net.sock.host.* attributes that duplicate corresponding net.host.* attributes") - void doesNotSetDuplicates1() { + void doesNotSetDuplicatesSocketAddress() { // given Map map = new HashMap<>(); map.put("netTransport", IP_TCP); @@ -193,42 +190,7 @@ void doesNotSetDuplicates1() { entry(SemanticAttributes.NET_HOST_NAME, "4:3:2:1::"), entry(SemanticAttributes.NET_HOST_PORT, 80L)); - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L)); - } - - @Test - @DisplayName( - "does not set net.sock.host.* attributes when they duplicate related net.host.* attributes") - void doesNotSetDuplicates2() { - // given - Map map = new HashMap<>(); - map.put("netTransport", IP_TCP); - map.put("hostName", "opentelemetry.io"); - map.put("hostPort", "80"); - map.put("sockFamily", "inet6"); - map.put("sockHostAddr", "4:3:2:1::"); - map.put("sockHostPort", "80"); - - 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, "opentelemetry.io"), - entry(SemanticAttributes.NET_HOST_PORT, 80L), - entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6")); - - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::")); + assertThat(endAttributes.build()).isEmpty(); } @Test diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorOldSemconvTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorOldSemconvTest.java index 9c3837b28094..7fcc492c775e 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorOldSemconvTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorOldSemconvTest.java @@ -37,19 +37,6 @@ public Integer getClientPort(Map request) { String value = request.get("port"); return value == null ? null : Integer.parseInt(value); } - - @Nullable - @Override - public String getClientSocketAddress(Map request, @Nullable Void response) { - return request.get("socketAddress"); - } - - @Nullable - @Override - public Integer getClientSocketPort(Map request, @Nullable Void response) { - String value = request.get("socketPort"); - return value == null ? null : Integer.parseInt(value); - } } @Test @@ -57,8 +44,6 @@ void allAttributes() { Map request = new HashMap<>(); request.put("address", "opentelemetry.io"); request.put("port", "80"); - request.put("socketAddress", "1.2.3.4"); - request.put("socketPort", "8080"); AttributesExtractor, Void> extractor = ClientAttributesExtractor.create(new TestClientAttributesGetter()); @@ -70,10 +55,7 @@ void allAttributes() { AttributesBuilder endAttributes = Attributes.builder(); extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"), - entry(SemanticAttributes.NET_SOCK_PEER_PORT, 8080L)); + assertThat(endAttributes.build()).isEmpty(); } @Test diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorOldSemconvTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorOldSemconvTest.java index 757ca7ceff3b..7ea4e0cf74a4 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorOldSemconvTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorOldSemconvTest.java @@ -48,6 +48,32 @@ public String getNetworkProtocolName(Map request, @Nullable Void public String getNetworkProtocolVersion(Map request, @Nullable Void response) { return request.get("protocolVersion"); } + + @Nullable + @Override + public String getNetworkLocalAddress(Map request, @Nullable Void response) { + return request.get("localAddress"); + } + + @Nullable + @Override + public Integer getNetworkLocalPort(Map request, @Nullable Void response) { + String value = request.get("localPort"); + return value == null ? null : Integer.parseInt(value); + } + + @Nullable + @Override + public String getNetworkPeerAddress(Map request, @Nullable Void response) { + return request.get("peerAddress"); + } + + @Nullable + @Override + public Integer getNetworkPeerPort(Map request, @Nullable Void response) { + String value = request.get("peerPort"); + return value == null ? null : Integer.parseInt(value); + } } @Test @@ -57,6 +83,10 @@ void allAttributes() { request.put("type", "IPv4"); request.put("protocolName", "Http"); request.put("protocolVersion", "1.1"); + request.put("localAddress", "1.2.3.4"); + request.put("localPort", "8080"); + request.put("peerAddress", "4.3.2.1"); + request.put("peerPort", "9090"); AttributesExtractor, Void> extractor = NetworkAttributesExtractor.create(new TestNetworkAttributesGetter()); @@ -71,7 +101,11 @@ void allAttributes() { .containsOnly( // the NetworkAttributesExtractor can't emit old net.transport & net.sock.family entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1")); + entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), + entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "1.2.3.4"), + entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L), + entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "4.3.2.1"), + entry(SemanticAttributes.NET_SOCK_PEER_PORT, 9090L)); } @Test diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorOldSemconvTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorOldSemconvTest.java index 916b875cbd30..a294ef229c5a 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorOldSemconvTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorOldSemconvTest.java @@ -37,25 +37,6 @@ public Integer getServerPort(Map request) { String port = request.get("port"); return port == null ? null : Integer.parseInt(port); } - - @Nullable - @Override - public String getServerSocketDomain(Map request, @Nullable Void response) { - return request.get("socketDomain"); - } - - @Nullable - @Override - public String getServerSocketAddress(Map request, @Nullable Void response) { - return request.get("socketAddress"); - } - - @Nullable - @Override - public Integer getServerSocketPort(Map request, @Nullable Void response) { - String port = request.get("socketPort"); - return port == null ? null : Integer.parseInt(port); - } } @Test @@ -63,9 +44,6 @@ void allAttributes_peer() { Map request = new HashMap<>(); request.put("address", "opentelemetry.io"); request.put("port", "80"); - request.put("socketDomain", "proxy.opentelemetry.io"); - request.put("socketAddress", "1.2.3.4"); - request.put("socketPort", "8080"); AttributesExtractor, Void> extractor = ServerAttributesExtractor.create(new TestServerAttributesGetter()); @@ -79,11 +57,7 @@ void allAttributes_peer() { AttributesBuilder endAttributes = Attributes.builder(); extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"), - entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"), - entry(SemanticAttributes.NET_SOCK_PEER_PORT, 8080L)); + assertThat(endAttributes.build()).isEmpty(); } @SuppressWarnings("deprecation") // need to test the old semconv too @@ -92,9 +66,6 @@ void allAttributes_host() { Map request = new HashMap<>(); request.put("address", "opentelemetry.io"); request.put("port", "80"); - request.put("socketDomain", "proxy.opentelemetry.io"); - request.put("socketAddress", "1.2.3.4"); - request.put("socketPort", "8080"); AttributesExtractor, Void> extractor = ServerAttributesExtractor.createForServerSide(new TestServerAttributesGetter()); @@ -108,10 +79,7 @@ void allAttributes_host() { AttributesBuilder endAttributes = Attributes.builder(); extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "1.2.3.4"), - entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L)); + assertThat(endAttributes.build()).isEmpty(); } @Test diff --git a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorBothSemconvTest.java b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorBothSemconvTest.java index 2bb799eaee0a..bde4b7d32f11 100644 --- a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorBothSemconvTest.java +++ b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorBothSemconvTest.java @@ -13,6 +13,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -139,10 +140,8 @@ void normal() { entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"), entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), - entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"), entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L), - entry(SemanticAttributes.SERVER_SOCKET_DOMAIN, "proxy.opentelemetry.io"), - entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1:2:3:4::"), - entry(SemanticAttributes.SERVER_SOCKET_PORT, 123L)); + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 123L)); } } diff --git a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorBothSemconvTest.java b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorBothSemconvTest.java index f1301379eedc..7d938f131653 100644 --- a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorBothSemconvTest.java +++ b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorBothSemconvTest.java @@ -13,6 +13,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -141,12 +142,12 @@ void normal() { .containsOnly( entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"), entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L), - entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "4:3:2:1::"), - entry(SemanticAttributes.SERVER_SOCKET_PORT, 8080L), + entry(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4:3:2:1::"), + entry(NetworkAttributes.NETWORK_LOCAL_PORT, 8080L), entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), entry(SemanticAttributes.NET_SOCK_PEER_PORT, 42L), - entry(SemanticAttributes.CLIENT_SOCKET_ADDRESS, "1:2:3:4::"), - entry(SemanticAttributes.CLIENT_SOCKET_PORT, 42L), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 42L), entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), entry(SemanticAttributes.NETWORK_TYPE, "ipv6"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), 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 344561a3c911..bf003138bdc7 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 @@ -19,6 +19,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.semconv.SemanticAttributes; import java.net.ConnectException; @@ -90,14 +91,29 @@ public String getNetworkType( @Override public String getNetworkProtocolName( Map request, @Nullable Map response) { - return request.get("protocolName"); + return request.get("networkProtocolName"); } @Nullable @Override public String getNetworkProtocolVersion( Map request, @Nullable Map response) { - return request.get("protocolVersion"); + return request.get("networkProtocolVersion"); + } + + @Nullable + @Override + public String getNetworkPeerAddress( + Map request, @Nullable Map response) { + return request.get("networkPeerAddress"); + } + + @Nullable + @Override + public Integer getNetworkPeerPort( + Map request, @Nullable Map response) { + String value = request.get("networkPeerPort"); + return value == null ? null : Integer.parseInt(value); } @Nullable @@ -133,8 +149,10 @@ void normal() { request.put("header.custom-request-header", "123,456"); request.put("networkTransport", "udp"); request.put("networkType", "ipv4"); - request.put("protocolName", "http"); - request.put("protocolVersion", "1.1"); + request.put("networkProtocolName", "http"); + request.put("networkProtocolVersion", "1.1"); + request.put("networkPeerAddress", "4.3.2.1"); + request.put("networkPeerPort", "456"); request.put("serverAddress", "github.com"); request.put("serverPort", "123"); @@ -179,7 +197,9 @@ void normal() { entry(SemanticAttributes.NETWORK_TRANSPORT, "udp"), entry(SemanticAttributes.NETWORK_TYPE, "ipv4"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1")); + entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 456L)); } @ParameterizedTest @@ -190,8 +210,8 @@ void skipNetworkTransportIfDefaultForProtocol( String observedTransport, @Nullable String extractedTransport) { Map request = new HashMap<>(); - request.put("protocolName", observedProtocolName); - request.put("protocolVersion", observedProtocolVersion); + request.put("networkProtocolName", observedProtocolName); + request.put("networkProtocolVersion", observedProtocolVersion); request.put("networkTransport", observedTransport); AttributesExtractor, Map> extractor = @@ -376,4 +396,55 @@ void shouldExtractErrorType_other() { assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, HttpConstants._OTHER); } + + @Test + void shouldExtractServerAddressAndPortFromHostHeader() { + Map request = new HashMap<>(); + request.put("header.host", "github.com:123"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), + entry(SemanticAttributes.SERVER_PORT, 123L)); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + } + + @Test + void shouldNotExtractDuplicatePeerAddress() { + Map request = new HashMap<>(); + request.put("networkPeerAddress", "1.2.3.4"); + request.put("networkPeerPort", "456"); + request.put("serverAddress", "1.2.3.4"); + request.put("serverPort", "123"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.SERVER_ADDRESS, "1.2.3.4"), + entry(SemanticAttributes.SERVER_PORT, 123L)); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + } } diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsStableSemconvTest.java index f77c9119dd36..843dbe562736 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsStableSemconvTest.java @@ -16,6 +16,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.semconv.SemanticAttributes; @@ -51,9 +52,8 @@ void collectsMetrics() { .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http") .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0") - .put(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4") - .put(SemanticAttributes.SERVER_SOCKET_DOMAIN, "somehost20") - .put(SemanticAttributes.SERVER_SOCKET_PORT, 8080) + .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") + .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) .build(); Context parent = diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java index 1d94a9bdc325..bffda6c5c2db 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java @@ -16,6 +16,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.semconv.SemanticAttributes; @@ -53,9 +54,8 @@ void collectsMetrics() { .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http") .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0") - .put(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4") - .put(SemanticAttributes.SERVER_SOCKET_DOMAIN, "somehost20") - .put(SemanticAttributes.SERVER_SOCKET_PORT, 8080) + .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") + .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) .build(); Context parent = 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 ba73b94a0b7a..e26dad0b9b74 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 @@ -19,6 +19,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.semconv.SemanticAttributes; import java.net.ConnectException; @@ -107,41 +108,56 @@ public String getNetworkType( @Override public String getNetworkProtocolName( Map request, Map response) { - return request.get("protocolName"); + return request.get("networkProtocolName"); } @Nullable @Override public String getNetworkProtocolVersion( Map request, Map response) { - return request.get("protocolVersion"); + return request.get("networkProtocolVersion"); } @Nullable @Override - public String getServerAddress(Map request) { - return request.get("serverAddress"); + public String getNetworkLocalAddress( + Map request, @Nullable Map response) { + return request.get("networkLocalAddress"); } @Nullable @Override - public Integer getServerPort(Map request) { - String value = request.get("serverPort"); + public Integer getNetworkLocalPort( + Map request, @Nullable Map response) { + String value = request.get("networkLocalPort"); return value == null ? null : Integer.parseInt(value); } @Nullable @Override - public String getServerSocketAddress( + public String getNetworkPeerAddress( Map request, @Nullable Map response) { - return request.get("serverSocketAddress"); + return request.get("networkPeerAddress"); } @Nullable @Override - public Integer getServerSocketPort( + public Integer getNetworkPeerPort( Map request, @Nullable Map response) { - String value = request.get("serverSocketPort"); + String value = request.get("networkPeerPort"); + return value == null ? null : Integer.parseInt(value); + } + + @Nullable + @Override + public String getServerAddress(Map request) { + return request.get("serverAddress"); + } + + @Nullable + @Override + public Integer getServerPort(Map request) { + String value = request.get("serverPort"); return value == null ? null : Integer.parseInt(value); } @@ -166,15 +182,19 @@ void normal() { request.put("header.content-length", "10"); request.put("route", "/repositories/{id}"); request.put("header.user-agent", "okhttp 3.x"); - request.put("header.host", "github.com"); + request.put("header.host", "www.github.com:456"); request.put("header.forwarded", "for=1.1.1.1;proto=https"); request.put("header.custom-request-header", "123,456"); request.put("networkTransport", "udp"); request.put("networkType", "ipv4"); - request.put("protocolName", "http"); - request.put("protocolVersion", "2.0"); - request.put("serverSocketAddress", "1.2.3.4"); - request.put("serverSocketPort", "42"); + request.put("networkProtocolName", "http"); + request.put("networkProtocolVersion", "2.0"); + request.put("networkLocalAddress", "1.2.3.4"); + request.put("networkLocalPort", "42"); + request.put("networkPeerAddress", "4.3.2.1"); + request.put("networkPeerPort", "456"); + request.put("serverAddress", "github.com"); + request.put("serverPort", "123"); Map response = new HashMap<>(); response.put("statusCode", "202"); @@ -195,6 +215,7 @@ void normal() { assertThat(startAttributes.build()) .containsOnly( entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), + entry(SemanticAttributes.SERVER_PORT, 123L), entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), entry(SemanticAttributes.URL_SCHEME, "https"), entry(SemanticAttributes.URL_PATH, "/repositories/1"), @@ -214,6 +235,8 @@ void normal() { entry(SemanticAttributes.NETWORK_TYPE, "ipv4"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 456L), entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"), entry(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 10L), entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), @@ -231,8 +254,8 @@ void skipNetworkTransportIfDefaultForProtocol( String observedTransport, @Nullable String extractedTransport) { Map request = new HashMap<>(); - request.put("protocolName", observedProtocolName); - request.put("protocolVersion", observedProtocolVersion); + request.put("networkProtocolName", observedProtocolName); + request.put("networkProtocolVersion", observedProtocolVersion); request.put("networkTransport", observedTransport); AttributesExtractor, Map> extractor = @@ -439,4 +462,55 @@ void shouldPreferUrlSchemeFromForwardedHeader() { assertThat(endAttributes.build()) .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L)); } + + @Test + void shouldExtractServerAddressAndPortFromHostHeader() { + Map request = new HashMap<>(); + request.put("header.host", "github.com:123"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), + entry(SemanticAttributes.SERVER_PORT, 123L)); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + } + + @Test + void shouldNotExtractDuplicatePeerAddress() { + Map request = new HashMap<>(); + request.put("networkPeerAddress", "1.2.3.4"); + request.put("networkPeerPort", "456"); + request.put("header.forwarded", "for=1.2.3.4:123"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.CLIENT_ADDRESS, "1.2.3.4"), + entry(SemanticAttributes.CLIENT_PORT, 123L)); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + } } diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerExperimentalMetricsStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerExperimentalMetricsStableSemconvTest.java index 32ce0239a6ce..b313794577c0 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerExperimentalMetricsStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerExperimentalMetricsStableSemconvTest.java @@ -16,6 +16,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.semconv.SemanticAttributes; @@ -53,10 +54,10 @@ void collectsMetrics() { .put(HttpAttributes.ERROR_TYPE, "500") .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100) .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) - .put(SemanticAttributes.CLIENT_SOCKET_ADDRESS, "1.2.3.4") - .put(SemanticAttributes.CLIENT_SOCKET_PORT, 8080) - .put(SemanticAttributes.SERVER_SOCKET_ADDRESS, "4.3.2.1") - .put(SemanticAttributes.SERVER_SOCKET_PORT, 9090) + .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") + .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) + .put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4.3.2.1") + .put(NetworkAttributes.NETWORK_LOCAL_PORT, 9090) .build(); SpanContext spanContext1 = diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsStableSemconvTest.java index 2ea4be9d7f29..57776bf00e87 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsStableSemconvTest.java @@ -16,6 +16,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.semconv.SemanticAttributes; @@ -55,10 +56,10 @@ void collectsMetrics() { .put(HttpAttributes.ERROR_TYPE, "500") .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100) .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) - .put(SemanticAttributes.CLIENT_SOCKET_ADDRESS, "1.2.3.4") - .put(SemanticAttributes.CLIENT_SOCKET_PORT, 8080) - .put(SemanticAttributes.SERVER_SOCKET_ADDRESS, "4.3.2.1") - .put(SemanticAttributes.SERVER_SOCKET_PORT, 9090) + .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") + .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) + .put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4.3.2.1") + .put(NetworkAttributes.NETWORK_LOCAL_PORT, 9090) .build(); SpanContext spanContext1 = diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorStableSemconvTest.java index b27fdbe9bb96..65f0c7311e8a 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorStableSemconvTest.java @@ -13,6 +13,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -74,11 +75,6 @@ public String getSockFamily(Map request, Map res return response.get("sockFamily"); } - @Override - public String getServerSocketDomain(Map request, Map response) { - return response.get("sockPeerName"); - } - @Override public String getServerSocketAddress( Map request, Map response) { @@ -108,7 +104,6 @@ void normal() { 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(); @@ -132,8 +127,7 @@ void normal() { entry(SemanticAttributes.NETWORK_TYPE, "ipv6"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), - entry(SemanticAttributes.SERVER_SOCKET_DOMAIN, "proxy.opentelemetry.io"), - entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1:2:3:4::"), - entry(SemanticAttributes.SERVER_SOCKET_PORT, 123L)); + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 123L)); } } diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorStableSemconvTest.java index c44698dae7f1..9259e911151b 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorStableSemconvTest.java @@ -13,6 +13,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -139,9 +140,9 @@ void normal() { entry(SemanticAttributes.NETWORK_TYPE, "ipv6"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), - entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "4:3:2:1::"), - entry(SemanticAttributes.SERVER_SOCKET_PORT, 8080L), - entry(SemanticAttributes.CLIENT_SOCKET_ADDRESS, "1:2:3:4::"), - entry(SemanticAttributes.CLIENT_SOCKET_PORT, 42L)); + entry(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4:3:2:1::"), + entry(NetworkAttributes.NETWORK_LOCAL_PORT, 8080L), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 42L)); } } diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorInetSocketAddressTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorInetSocketAddressTest.java deleted file mode 100644 index 70ecb02d7c00..000000000000 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorInetSocketAddressTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.network; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.semconv.SemanticAttributes; -import java.net.InetSocketAddress; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -class ClientAttributesExtractorInetSocketAddressTest { - - static class TestClientAttributesGetter - implements ClientAttributesGetter { - - @Nullable - @Override - public String getClientAddress(InetSocketAddress request) { - // covered in ClientAttributesExtractorTest - return null; - } - - @Nullable - @Override - public Integer getClientPort(InetSocketAddress request) { - // covered in ClientAttributesExtractorTest - return null; - } - - @Nullable - @Override - public InetSocketAddress getClientInetSocketAddress( - InetSocketAddress request, @Nullable Void response) { - return request; - } - } - - @Test - @SuppressWarnings("AddressSelection") - void fullAddress() { - InetSocketAddress address = new InetSocketAddress("api.github.com", 456); - assertThat(address.getAddress().getHostAddress()).isNotNull(); - - AttributesExtractor extractor = - ClientAttributesExtractor.create(new TestClientAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), address); - assertThat(startAttributes.build()).isEmpty(); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), address, null, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.CLIENT_SOCKET_ADDRESS, address.getAddress().getHostAddress()), - entry(SemanticAttributes.CLIENT_SOCKET_PORT, 456L)); - } - - @Test - void noAttributes() { - AttributesExtractor extractor = - ClientAttributesExtractor.create(new TestClientAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), null); - assertThat(startAttributes.build()).isEmpty(); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), null, null, null); - assertThat(endAttributes.build()).isEmpty(); - } -} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorTest.java index 170d70fcc6c9..aa0ef6f785ba 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorTest.java @@ -36,19 +36,6 @@ public Integer getClientPort(Map request) { String value = request.get("port"); return value == null ? null : Integer.parseInt(value); } - - @Nullable - @Override - public String getClientSocketAddress(Map request, @Nullable Void response) { - return request.get("socketAddress"); - } - - @Nullable - @Override - public Integer getClientSocketPort(Map request, @Nullable Void response) { - String value = request.get("socketPort"); - return value == null ? null : Integer.parseInt(value); - } } @Test @@ -56,8 +43,6 @@ void allAttributes() { Map request = new HashMap<>(); request.put("address", "opentelemetry.io"); request.put("port", "80"); - request.put("socketAddress", "1.2.3.4"); - request.put("socketPort", "8080"); AttributesExtractor, Void> extractor = ClientAttributesExtractor.create(new TestClientAttributesGetter()); @@ -71,10 +56,7 @@ void allAttributes() { AttributesBuilder endAttributes = Attributes.builder(); extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.CLIENT_SOCKET_ADDRESS, "1.2.3.4"), - entry(SemanticAttributes.CLIENT_SOCKET_PORT, 8080L)); + assertThat(endAttributes.build()).isEmpty(); } @Test @@ -92,10 +74,9 @@ void noAttributes() { } @Test - void doesNotSetNegativePortValues() { + void doesNotSetNegativePortValue() { Map request = new HashMap<>(); request.put("port", "-12"); - request.put("socketPort", "-42"); AttributesExtractor, Void> extractor = ClientAttributesExtractor.create(new TestClientAttributesGetter()); @@ -108,27 +89,4 @@ void doesNotSetNegativePortValues() { extractor.onEnd(endAttributes, Context.root(), request, null, null); assertThat(endAttributes.build()).isEmpty(); } - - @Test - void doesNotSetDuplicates() { - Map request = new HashMap<>(); - request.put("address", "opentelemetry.io"); - request.put("port", "80"); - request.put("socketAddress", "opentelemetry.io"); - request.put("socketPort", "80"); - - AttributesExtractor, Void> extractor = - ClientAttributesExtractor.create(new TestClientAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.CLIENT_ADDRESS, "opentelemetry.io"), - entry(SemanticAttributes.CLIENT_PORT, 80L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()).isEmpty(); - } } diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorInetSocketAddressTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorInetSocketAddressTest.java new file mode 100644 index 000000000000..7f1ceaf9e9c6 --- /dev/null +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorInetSocketAddressTest.java @@ -0,0 +1,77 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.network; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; +import io.opentelemetry.semconv.SemanticAttributes; +import java.net.InetSocketAddress; +import javax.annotation.Nullable; +import org.junit.jupiter.api.Test; + +class NetworkAttributesExtractorInetSocketAddressTest { + + static class TestNetworkAttributesGetter + implements NetworkAttributesGetter { + + @Nullable + @Override + public InetSocketAddress getNetworkLocalInetSocketAddress( + InetSocketAddress request, @Nullable InetSocketAddress response) { + return request; + } + + @Nullable + @Override + public InetSocketAddress getNetworkPeerInetSocketAddress( + InetSocketAddress request, @Nullable InetSocketAddress response) { + return response; + } + } + + @Test + void fullAddress() { + InetSocketAddress local = new InetSocketAddress("1.2.3.4", 8080); + InetSocketAddress peer = new InetSocketAddress("4.3.2.1", 9090); + + AttributesExtractor extractor = + NetworkAttributesExtractor.create(new TestNetworkAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), local); + assertThat(startAttributes.build()).isEmpty(); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), local, peer, null); + assertThat(endAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NETWORK_TYPE, "ipv4"), + entry(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "1.2.3.4"), + entry(NetworkAttributes.NETWORK_LOCAL_PORT, 8080L), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 9090L)); + } + + @Test + void noAttributes() { + AttributesExtractor extractor = + NetworkAttributesExtractor.create(new TestNetworkAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), null); + assertThat(startAttributes.build()).isEmpty(); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), null, null, null); + assertThat(endAttributes.build()).isEmpty(); + } +} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorTest.java index 4bc8edbf2c64..144973cf4254 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorTest.java @@ -13,6 +13,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -47,6 +48,32 @@ public String getNetworkProtocolName(Map request, @Nullable Void public String getNetworkProtocolVersion(Map request, @Nullable Void response) { return request.get("protocolVersion"); } + + @Nullable + @Override + public String getNetworkLocalAddress(Map request, @Nullable Void response) { + return request.get("localAddress"); + } + + @Nullable + @Override + public Integer getNetworkLocalPort(Map request, @Nullable Void response) { + String value = request.get("localPort"); + return value == null ? null : Integer.parseInt(value); + } + + @Nullable + @Override + public String getNetworkPeerAddress(Map request, @Nullable Void response) { + return request.get("peerAddress"); + } + + @Nullable + @Override + public Integer getNetworkPeerPort(Map request, @Nullable Void response) { + String value = request.get("peerPort"); + return value == null ? null : Integer.parseInt(value); + } } @Test @@ -56,6 +83,10 @@ void allAttributes() { request.put("type", "IPv4"); request.put("protocolName", "Http"); request.put("protocolVersion", "1.1"); + request.put("localAddress", "1.2.3.4"); + request.put("localPort", "8080"); + request.put("peerAddress", "4.3.2.1"); + request.put("peerPort", "9090"); AttributesExtractor, Void> extractor = NetworkAttributesExtractor.create(new TestNetworkAttributesGetter()); @@ -71,7 +102,11 @@ void allAttributes() { entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), entry(SemanticAttributes.NETWORK_TYPE, "ipv4"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1")); + entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + entry(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "1.2.3.4"), + entry(NetworkAttributes.NETWORK_LOCAL_PORT, 8080L), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 9090L)); } @Test @@ -87,4 +122,27 @@ void noAttributes() { extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null); assertThat(endAttributes.build()).isEmpty(); } + + @Test + void doesNotSetNegativePortValues() { + Map request = new HashMap<>(); + request.put("localAddress", "1.2.3.4"); + request.put("localPort", "-12"); + request.put("peerAddress", "4.3.2.1"); + request.put("peerPort", "-42"); + + AttributesExtractor, Void> extractor = + NetworkAttributesExtractor.create(new TestNetworkAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()).isEmpty(); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, null, null); + assertThat(endAttributes.build()) + .containsOnly( + entry(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "1.2.3.4"), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1")); + } } diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorInetSocketAddressTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorInetSocketAddressTest.java deleted file mode 100644 index 4926fd4a23fb..000000000000 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorInetSocketAddressTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.network; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.semconv.SemanticAttributes; -import java.net.InetSocketAddress; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -class ServerAttributesExtractorInetSocketAddressTest { - - static class TestServerAttributesGetter - implements ServerAttributesGetter { - - @Nullable - @Override - public String getServerAddress(InetSocketAddress request) { - // covered in ServerAttributesExtractorTest - return null; - } - - @Nullable - @Override - public Integer getServerPort(InetSocketAddress request) { - // covered in ServerAttributesExtractorTest - return null; - } - - @Nullable - @Override - public InetSocketAddress getServerInetSocketAddress( - InetSocketAddress request, @Nullable Void response) { - return request; - } - } - - @Test - @SuppressWarnings("AddressSelection") - void fullAddress() { - InetSocketAddress address = new InetSocketAddress("api.github.com", 456); - assertThat(address.getAddress().getHostAddress()).isNotNull(); - - AttributesExtractor extractor = - ServerAttributesExtractor.create(new TestServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), address); - assertThat(startAttributes.build()).isEmpty(); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), address, null, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_SOCKET_DOMAIN, "api.github.com"), - entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, address.getAddress().getHostAddress()), - entry(SemanticAttributes.SERVER_SOCKET_PORT, 456L)); - } - - @Test - void noAttributes() { - AttributesExtractor extractor = - ServerAttributesExtractor.create(new TestServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), null); - assertThat(startAttributes.build()).isEmpty(); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), null, null, null); - assertThat(endAttributes.build()).isEmpty(); - } -} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorTest.java index 96d43e3b91d8..a7202943e5c1 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorTest.java @@ -36,25 +36,6 @@ public Integer getServerPort(Map request) { String port = request.get("port"); return port == null ? null : Integer.parseInt(port); } - - @Nullable - @Override - public String getServerSocketDomain(Map request, @Nullable Void response) { - return request.get("socketDomain"); - } - - @Nullable - @Override - public String getServerSocketAddress(Map request, @Nullable Void response) { - return request.get("socketAddress"); - } - - @Nullable - @Override - public Integer getServerSocketPort(Map request, @Nullable Void response) { - String port = request.get("socketPort"); - return port == null ? null : Integer.parseInt(port); - } } @Test @@ -62,9 +43,6 @@ void allAttributes() { Map request = new HashMap<>(); request.put("address", "opentelemetry.io"); request.put("port", "80"); - request.put("socketDomain", "proxy.opentelemetry.io"); - request.put("socketAddress", "1.2.3.4"); - request.put("socketPort", "8080"); AttributesExtractor, Void> extractor = ServerAttributesExtractor.create(new TestServerAttributesGetter()); @@ -78,11 +56,7 @@ void allAttributes() { AttributesBuilder endAttributes = Attributes.builder(); extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_SOCKET_DOMAIN, "proxy.opentelemetry.io"), - entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4"), - entry(SemanticAttributes.SERVER_SOCKET_PORT, 8080L)); + assertThat(endAttributes.build()).isEmpty(); } @Test @@ -100,12 +74,10 @@ void noAttributes() { } @Test - void doesNotSetNegativePortValues() { + void doesNotSetNegativePortValue() { Map request = new HashMap<>(); request.put("address", "opentelemetry.io"); request.put("port", "-12"); - request.put("socketAddress", "1.2.3.4"); - request.put("socketPort", "-42"); AttributesExtractor, Void> extractor = ServerAttributesExtractor.create(new TestServerAttributesGetter()); @@ -114,34 +86,5 @@ void doesNotSetNegativePortValues() { extractor.onStart(startAttributes, Context.root(), request); assertThat(startAttributes.build()) .containsOnly(entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io")); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4")); - } - - @Test - void doesNotSetDuplicates() { - Map request = new HashMap<>(); - request.put("address", "1.2.3.4"); - request.put("port", "80"); - request.put("socketDomain", "1.2.3.4"); - request.put("socketAddress", "1.2.3.4"); - request.put("socketPort", "80"); - - AttributesExtractor, Void> extractor = - ServerAttributesExtractor.create(new TestServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_ADDRESS, "1.2.3.4"), - entry(SemanticAttributes.SERVER_PORT, 80L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()).isEmpty(); } } diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboNetworkServerAttributesGetter.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboNetworkServerAttributesGetter.java index 0d1bc51acee8..df25e545f3e9 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboNetworkServerAttributesGetter.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboNetworkServerAttributesGetter.java @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.apachedubbo.v2_7; -import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; import java.net.InetSocketAddress; import javax.annotation.Nullable; @@ -13,7 +13,7 @@ final class DubboNetworkServerAttributesGetter implements ServerAttributesGetter, - ClientAttributesGetter { + NetworkAttributesGetter { @Nullable @Override @@ -29,14 +29,14 @@ public Integer getServerPort(DubboRequest request) { @Nullable @Override - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkLocalInetSocketAddress( DubboRequest request, @Nullable Result result) { return request.localAddress(); } @Override @Nullable - public InetSocketAddress getClientInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( DubboRequest request, @Nullable Result result) { return request.remoteAddress(); } diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTelemetryBuilder.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTelemetryBuilder.java index b815eb28533b..16a009dd38ee 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTelemetryBuilder.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTelemetryBuilder.java @@ -12,7 +12,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcServerAttributesExtractor; @@ -72,7 +72,7 @@ public DubboTelemetry build() { .addAttributesExtractor(RpcServerAttributesExtractor.create(rpcAttributesGetter)) .addAttributesExtractor( ServerAttributesExtractor.createForServerSide(netServerAttributesGetter)) - .addAttributesExtractor(ClientAttributesExtractor.create(netServerAttributesGetter)) + .addAttributesExtractor(NetworkAttributesExtractor.create(netServerAttributesGetter)) .addAttributesExtractors(attributesExtractors); InstrumenterBuilder clientInstrumenterBuilder = @@ -80,6 +80,7 @@ public DubboTelemetry build() { openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor) .addAttributesExtractor(RpcClientAttributesExtractor.create(rpcAttributesGetter)) .addAttributesExtractor(ServerAttributesExtractor.create(netClientAttributesGetter)) + .addAttributesExtractor(NetworkAttributesExtractor.create(netClientAttributesGetter)) .addAttributesExtractors(attributesExtractors); if (peerService != null) { diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboClientNetworkAttributesGetter.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboClientNetworkAttributesGetter.java index 659e4ca27166..a40354f3c303 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboClientNetworkAttributesGetter.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboClientNetworkAttributesGetter.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.apachedubbo.v2_7.internal; import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; import java.net.InetSocketAddress; import javax.annotation.Nullable; @@ -16,7 +17,8 @@ * any time. */ public final class DubboClientNetworkAttributesGetter - implements ServerAttributesGetter { + implements ServerAttributesGetter, + NetworkAttributesGetter { @Nullable @Override @@ -31,7 +33,7 @@ public Integer getServerPort(DubboRequest request) { @Override @Nullable - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( DubboRequest request, @Nullable Result response) { return request.remoteAddress(); } diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy b/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy index cd9414fb0034..584f7fdab75d 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy @@ -105,6 +105,8 @@ abstract class AbstractDubboTest extends InstrumentationSpecification { "$SemanticAttributes.NET_PEER_NAME" "localhost" "$SemanticAttributes.NET_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String} + "$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long} + "$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String} } } span(2) { @@ -116,8 +118,8 @@ abstract class AbstractDubboTest extends InstrumentationSpecification { "$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService" "$SemanticAttributes.RPC_METHOD" "hello" "$SemanticAttributes.NET_SOCK_PEER_ADDR" String + "$SemanticAttributes.NET_SOCK_PEER_NAME" String "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } } } @@ -180,6 +182,8 @@ abstract class AbstractDubboTest extends InstrumentationSpecification { "$SemanticAttributes.NET_PEER_NAME" "localhost" "$SemanticAttributes.NET_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String} + "$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long} + "$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String} } } span(2) { @@ -191,8 +195,8 @@ abstract class AbstractDubboTest extends InstrumentationSpecification { "$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService" "$SemanticAttributes.RPC_METHOD" "hello" "$SemanticAttributes.NET_SOCK_PEER_ADDR" String + "$SemanticAttributes.NET_SOCK_PEER_NAME" String "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } } } diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy b/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy index 7929c63f7f9f..67fe69e60aea 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy @@ -141,6 +141,8 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification "$SemanticAttributes.NET_PEER_NAME" "localhost" "$SemanticAttributes.NET_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String} + "$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String} + "$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long} } } span(2) { @@ -152,8 +154,8 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification "$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService" "$SemanticAttributes.RPC_METHOD" "hello" "$SemanticAttributes.NET_SOCK_PEER_ADDR" String + "$SemanticAttributes.NET_SOCK_PEER_NAME" String "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } } } @@ -181,8 +183,8 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification "$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService" "$SemanticAttributes.RPC_METHOD" "hello" "$SemanticAttributes.NET_SOCK_PEER_ADDR" String + "$SemanticAttributes.NET_SOCK_PEER_NAME" String "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } } } @@ -257,6 +259,8 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification "$SemanticAttributes.NET_PEER_NAME" "localhost" "$SemanticAttributes.NET_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String} + "$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long} + "$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String} } } span(2) { @@ -268,8 +272,8 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification "$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService" "$SemanticAttributes.RPC_METHOD" "hello" "$SemanticAttributes.NET_SOCK_PEER_ADDR" String + "$SemanticAttributes.NET_SOCK_PEER_NAME" String "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } } } diff --git a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.java b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.java index dd7666092231..6caf1e1617f3 100644 --- a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.java +++ b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.java @@ -115,6 +115,9 @@ void restComponentServerAndClientCallWithJettyBackend() { val -> val.isInstanceOf(String.class)), satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + satisfies( + SemanticAttributes.NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class))), span -> span.hasName("GET /api/{module}/unit/{unitId}") diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetworkAttributesGetter.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetworkAttributesGetter.java index 0a8207d6963e..fb1f2a26e426 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetworkAttributesGetter.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetworkAttributesGetter.java @@ -6,16 +6,16 @@ package io.opentelemetry.javaagent.instrumentation.cassandra.v3_0; import com.datastax.driver.core.ExecutionInfo; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import java.net.InetSocketAddress; import javax.annotation.Nullable; final class CassandraNetworkAttributesGetter - implements ServerAttributesGetter { + implements NetworkAttributesGetter { @Override @Nullable - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( CassandraRequest request, @Nullable ExecutionInfo executionInfo) { return executionInfo == null ? null : executionInfo.getQueriedHost().getSocketAddress(); } diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSingletons.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSingletons.java index 695bdb9a501c..97bd78d9878f 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSingletons.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSingletons.java @@ -11,7 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.SqlClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import io.opentelemetry.semconv.SemanticAttributes; @@ -37,7 +37,7 @@ public final class CassandraSingletons { CommonConfig.get().isStatementSanitizationEnabled()) .build()) .addAttributesExtractor( - ServerAttributesExtractor.create(new CassandraNetworkAttributesGetter())) + NetworkAttributesExtractor.create(new CassandraNetworkAttributesGetter())) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetworkAttributesGetter.java b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetworkAttributesGetter.java index 2bf26ec44bcf..ba185cb1bbaa 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetworkAttributesGetter.java +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetworkAttributesGetter.java @@ -7,17 +7,17 @@ import com.datastax.oss.driver.api.core.cql.ExecutionInfo; import com.datastax.oss.driver.api.core.metadata.Node; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; final class CassandraNetworkAttributesGetter - implements ServerAttributesGetter { + implements NetworkAttributesGetter { @Override @Nullable - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( CassandraRequest request, @Nullable ExecutionInfo executionInfo) { if (executionInfo == null) { return null; diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSingletons.java b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSingletons.java index 2c3a8705bbcf..16d0a1a109d0 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSingletons.java +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSingletons.java @@ -11,7 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.SqlClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import io.opentelemetry.semconv.SemanticAttributes; @@ -36,7 +36,7 @@ public final class CassandraSingletons { CommonConfig.get().isStatementSanitizationEnabled()) .build()) .addAttributesExtractor( - ServerAttributesExtractor.create(new CassandraNetworkAttributesGetter())) + NetworkAttributesExtractor.create(new CassandraNetworkAttributesGetter())) .addAttributesExtractor(new CassandraAttributesExtractor()) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } diff --git a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraNetworkAttributesGetter.java b/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraNetworkAttributesGetter.java index ca7e93a2b804..33c4c1dc1a5d 100644 --- a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraNetworkAttributesGetter.java +++ b/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraNetworkAttributesGetter.java @@ -7,17 +7,17 @@ import com.datastax.oss.driver.api.core.cql.ExecutionInfo; import com.datastax.oss.driver.api.core.metadata.Node; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; final class CassandraNetworkAttributesGetter - implements ServerAttributesGetter { + implements NetworkAttributesGetter { @Override @Nullable - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( CassandraRequest request, @Nullable ExecutionInfo executionInfo) { if (executionInfo == null) { return null; diff --git a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraTelemetryBuilder.java b/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraTelemetryBuilder.java index c08e6cb20593..559b00eef4ed 100644 --- a/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraTelemetryBuilder.java +++ b/instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraTelemetryBuilder.java @@ -12,7 +12,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.SqlClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.semconv.SemanticAttributes; /** A builder of {@link CassandraTelemetry}. */ @@ -59,7 +59,7 @@ protected Instrumenter createInstrumenter( .setStatementSanitizationEnabled(statementSanitizationEnabled) .build()) .addAttributesExtractor( - ServerAttributesExtractor.create(new CassandraNetworkAttributesGetter())) + NetworkAttributesExtractor.create(new CassandraNetworkAttributesGetter())) .addAttributesExtractor(new CassandraAttributesExtractor()) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } diff --git a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseNetworkAttributesGetter.java b/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseNetworkAttributesGetter.java index 35b19adadf24..3424e2085061 100644 --- a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseNetworkAttributesGetter.java +++ b/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseNetworkAttributesGetter.java @@ -5,17 +5,17 @@ package io.opentelemetry.javaagent.instrumentation.couchbase.v2_0; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; public class CouchbaseNetworkAttributesGetter - implements ServerAttributesGetter { + implements NetworkAttributesGetter { @Nullable @Override - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( CouchbaseRequestInfo couchbaseRequest, @Nullable Void unused) { SocketAddress peerAddress = couchbaseRequest.getPeerAddress(); if (peerAddress instanceof InetSocketAddress) { diff --git a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseSingletons.java b/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseSingletons.java index 58421bd25080..647e13748c6e 100644 --- a/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseSingletons.java +++ b/instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseSingletons.java @@ -12,9 +12,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; -import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; public final class CouchbaseSingletons { @@ -33,10 +31,7 @@ public final class CouchbaseSingletons { Instrumenter.builder( GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor) .addAttributesExtractor(DbClientAttributesExtractor.create(couchbaseAttributesGetter)) - .addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter)) - .addAttributesExtractor( - PeerServiceAttributesExtractor.create( - netAttributesGetter, CommonConfig.get().getPeerServiceResolver())) + .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) .addContextCustomizer( (context, couchbaseRequest, startAttributes) -> CouchbaseRequestInfo.init(context, couchbaseRequest)); diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/Elasticsearch5TransportSingletons.java b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/Elasticsearch5TransportSingletons.java index 60308996e2aa..31c20c1056cf 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/Elasticsearch5TransportSingletons.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/Elasticsearch5TransportSingletons.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v5_0; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportNetworkAttributesGetter; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticsearchTransportInstrumenterFactory; @@ -18,7 +18,7 @@ public final class Elasticsearch5TransportSingletons { ElasticsearchTransportInstrumenterFactory.create( "io.opentelemetry.elasticsearch-transport-5.0", new Elasticsearch5TransportExperimentalAttributesExtractor(), - ServerAttributesExtractor.create(new ElasticTransportNetworkAttributesGetter())); + NetworkAttributesExtractor.create(new ElasticTransportNetworkAttributesGetter())); public static Instrumenter instrumenter() { return INSTRUMENTER; diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/test/groovy/Elasticsearch5TransportClientTest.groovy b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/test/groovy/Elasticsearch5TransportClientTest.groovy index 8fc6d8244bc9..04d3eacca5f4 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/test/groovy/Elasticsearch5TransportClientTest.groovy +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/test/groovy/Elasticsearch5TransportClientTest.groovy @@ -127,7 +127,6 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl attributes { "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.host "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "ClusterHealthAction" @@ -245,7 +244,6 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl attributes { "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.host "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "CreateIndexAction" @@ -262,7 +260,6 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl attributes { "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.host "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "GetAction" @@ -294,7 +291,6 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl attributes { "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.host "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "IndexAction" @@ -316,7 +312,6 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl attributes { "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.host "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "GetAction" diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/Elasticsearch53TransportSingletons.java b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/Elasticsearch53TransportSingletons.java index f29a445de1a9..ce299ced5ffa 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/Elasticsearch53TransportSingletons.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/Elasticsearch53TransportSingletons.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v5_3; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportNetworkAttributesGetter; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticsearchTransportInstrumenterFactory; @@ -18,7 +18,7 @@ public final class Elasticsearch53TransportSingletons { ElasticsearchTransportInstrumenterFactory.create( "io.opentelemetry.elasticsearch-transport-5.3", new Elasticsearch53TransportExperimentalAttributesExtractor(), - ServerAttributesExtractor.create(new ElasticTransportNetworkAttributesGetter())); + NetworkAttributesExtractor.create(new ElasticTransportNetworkAttributesGetter())); public static Instrumenter instrumenter() { return INSTRUMENTER; diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53TransportClientTest.groovy b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53TransportClientTest.groovy index dd36914eb301..969dbf62d6c2 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53TransportClientTest.groovy +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53TransportClientTest.groovy @@ -133,7 +133,6 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC attributes { "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.host "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "ClusterHealthAction" @@ -250,7 +249,6 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC attributes { "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.host "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "CreateIndexAction" @@ -267,7 +265,6 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC attributes { "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.host "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "GetAction" @@ -299,7 +296,6 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC attributes { "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.host "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "IndexAction" @@ -322,7 +318,6 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC attributes { "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.host "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "GetAction" diff --git a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetworkAttributesGetter.java b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetworkAttributesGetter.java index 51351b57bf90..5305465df878 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetworkAttributesGetter.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetworkAttributesGetter.java @@ -5,18 +5,18 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v6_0; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest; import java.net.InetSocketAddress; import javax.annotation.Nullable; import org.elasticsearch.action.ActionResponse; public class Elasticsearch6TransportNetworkAttributesGetter - implements ServerAttributesGetter { + implements NetworkAttributesGetter { @Override @Nullable - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( ElasticTransportRequest request, @Nullable ActionResponse response) { if (response != null && response.remoteAddress() != null) { return response.remoteAddress().address(); diff --git a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportSingletons.java b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportSingletons.java index e8123e7207bb..8de019d8d5eb 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportSingletons.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportSingletons.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v6_0; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticsearchTransportInstrumenterFactory; import org.elasticsearch.action.ActionResponse; @@ -17,7 +17,7 @@ public final class Elasticsearch6TransportSingletons { ElasticsearchTransportInstrumenterFactory.create( "io.opentelemetry.elasticsearch-transport-6.0", new Elasticsearch6TransportExperimentalAttributesExtractor(), - ServerAttributesExtractor.create(new Elasticsearch6TransportNetworkAttributesGetter())); + NetworkAttributesExtractor.create(new Elasticsearch6TransportNetworkAttributesGetter())); public static Instrumenter instrumenter() { return INSTRUMENTER; diff --git a/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetworkAttributesGetter.java b/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetworkAttributesGetter.java index 939bba50e482..39308734e8e9 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetworkAttributesGetter.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetworkAttributesGetter.java @@ -5,28 +5,16 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import javax.annotation.Nullable; import org.elasticsearch.action.ActionResponse; public class ElasticTransportNetworkAttributesGetter - implements ServerAttributesGetter { + implements NetworkAttributesGetter { @Override @Nullable - public String getServerAddress(ElasticTransportRequest request) { - return null; - } - - @Override - @Nullable - public Integer getServerPort(ElasticTransportRequest request) { - return null; - } - - @Override - @Nullable - public String getServerSocketAddress( + public String getNetworkPeerAddress( ElasticTransportRequest request, @Nullable ActionResponse response) { if (response != null && response.remoteAddress() != null) { return response.remoteAddress().getAddress(); @@ -36,17 +24,7 @@ public String getServerSocketAddress( @Nullable @Override - public String getServerSocketDomain( - ElasticTransportRequest request, @Nullable ActionResponse response) { - if (response != null && response.remoteAddress() != null) { - return response.remoteAddress().getHost(); - } - return null; - } - - @Nullable - @Override - public Integer getServerSocketPort( + public Integer getNetworkPeerPort( ElasticTransportRequest request, @Nullable ActionResponse response) { if (response != null && response.remoteAddress() != null) { return response.remoteAddress().getPort(); diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcNetworkServerAttributesGetter.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcNetworkServerAttributesGetter.java index 3fd4406d9082..d8e7ff79e659 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcNetworkServerAttributesGetter.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcNetworkServerAttributesGetter.java @@ -6,7 +6,7 @@ package io.opentelemetry.instrumentation.grpc.v1_6; import io.grpc.Status; -import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -14,7 +14,7 @@ final class GrpcNetworkServerAttributesGetter implements ServerAttributesGetter, - ClientAttributesGetter { + NetworkAttributesGetter { @Nullable @Override @@ -29,7 +29,7 @@ public Integer getServerPort(GrpcRequest grpcRequest) { @Nullable @Override - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkLocalInetSocketAddress( GrpcRequest grpcRequest, @Nullable Status status) { // TODO: later version introduces TRANSPORT_ATTR_LOCAL_ADDR, might be a good idea to use it return null; @@ -37,7 +37,7 @@ public InetSocketAddress getServerInetSocketAddress( @Override @Nullable - public InetSocketAddress getClientInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( GrpcRequest request, @Nullable Status status) { SocketAddress address = request.getPeerSocketAddress(); if (address instanceof InetSocketAddress) { diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcTelemetryBuilder.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcTelemetryBuilder.java index 1a15d94f811d..0c51ca8eeb10 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcTelemetryBuilder.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcTelemetryBuilder.java @@ -13,7 +13,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientMetrics; @@ -177,6 +177,7 @@ public GrpcTelemetry build() { .addAttributesExtractors(additionalExtractors) .addAttributesExtractor(RpcClientAttributesExtractor.create(rpcAttributesGetter)) .addAttributesExtractor(ServerAttributesExtractor.create(netClientAttributesGetter)) + .addAttributesExtractor(NetworkAttributesExtractor.create(netClientAttributesGetter)) .addAttributesExtractors(additionalClientExtractors) .addAttributesExtractor( new GrpcAttributesExtractor( @@ -188,7 +189,7 @@ public GrpcTelemetry build() { .addAttributesExtractor(RpcServerAttributesExtractor.create(rpcAttributesGetter)) .addAttributesExtractor( ServerAttributesExtractor.createForServerSide(netServerAttributesGetter)) - .addAttributesExtractor(ClientAttributesExtractor.create(netServerAttributesGetter)) + .addAttributesExtractor(NetworkAttributesExtractor.create(netServerAttributesGetter)) .addAttributesExtractor( new GrpcAttributesExtractor( GrpcRpcAttributesGetter.INSTANCE, capturedServerRequestMetadata)) diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcClientNetworkAttributesGetter.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcClientNetworkAttributesGetter.java index c2d342da7946..deb6e61da568 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcClientNetworkAttributesGetter.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcClientNetworkAttributesGetter.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.grpc.v1_6.internal; import io.grpc.Status; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; import io.opentelemetry.instrumentation.grpc.v1_6.GrpcRequest; import java.net.InetSocketAddress; @@ -17,7 +18,8 @@ * any time. */ public final class GrpcClientNetworkAttributesGetter - implements ServerAttributesGetter { + implements ServerAttributesGetter, + NetworkAttributesGetter { @Nullable @Override @@ -32,7 +34,7 @@ public Integer getServerPort(GrpcRequest grpcRequest) { @Override @Nullable - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( GrpcRequest request, @Nullable Status response) { SocketAddress address = request.getPeerSocketAddress(); if (address instanceof InetSocketAddress) { diff --git a/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.java b/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.java index fb0ea9485c8b..a19a306798f7 100644 --- a/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.java +++ b/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.java @@ -202,6 +202,9 @@ public void onCompleted() { equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> assertThat(val).isNotNull()), satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())) diff --git a/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.java b/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.java index 4d1e168106cd..0db883dfd939 100644 --- a/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.java +++ b/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.java @@ -170,6 +170,9 @@ public void sayHello( equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> assertThat(val).isNotNull()), satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())) @@ -331,6 +334,9 @@ public void sayHello( equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> assertThat(val).isNotNull()), satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())) @@ -504,6 +510,9 @@ public void onCompleted() { equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> assertThat(val).isNotNull()), satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())) @@ -647,6 +656,9 @@ public void sayHello( equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> assertThat(val).isNotNull()), satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())) @@ -793,6 +805,9 @@ public void sayHello( equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> assertThat(val).isNotNull()), satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())) @@ -1043,6 +1058,9 @@ public void onCompleted() { equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> assertThat(val).isNotNull()), satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())) @@ -1162,6 +1180,9 @@ public void onCompleted() { equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> assertThat(val).isNotNull()), satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())) @@ -1280,6 +1301,9 @@ public void onCompleted() { equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> assertThat(val).isNotNull()), satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())) @@ -1381,6 +1405,9 @@ public void sayHello( equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> assertThat(val).isNotNull()), satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())) @@ -1638,6 +1665,10 @@ static List addExtraClientAttributes(AttributeAssertion... a result.addAll(Arrays.asList(assertions)); if (Boolean.getBoolean("testLatestDeps")) { result.add(equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")); + result.add( + satisfies(SemanticAttributes.NET_SOCK_PEER_NAME, val -> assertThat(val).isNotNull())); + result.add( + satisfies(SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())); } return result; } diff --git a/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsHttpServerTest.groovy index 234c7ee9bede..1120cdf73950 100644 --- a/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsHttpServerTest.groovy @@ -285,6 +285,7 @@ abstract class AbstractJaxRsHttpServerTest extends HttpServerTest implemen "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" { it instanceof Long || it == null } "$SemanticAttributes.HTTP_SCHEME" fullUrl.getScheme() "$SemanticAttributes.HTTP_TARGET" fullUrl.getPath() + (fullUrl.getQuery() != null ? "?" + fullUrl.getQuery() : "") "$SemanticAttributes.HTTP_METHOD" method diff --git a/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetworkAttributesGetter.java b/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetworkAttributesGetter.java index 6fdf8ae2660c..edfe8d81c5d8 100644 --- a/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetworkAttributesGetter.java +++ b/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetworkAttributesGetter.java @@ -5,12 +5,15 @@ package io.opentelemetry.javaagent.instrumentation.jedis.v3_0; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; import java.net.InetSocketAddress; import java.net.Socket; import javax.annotation.Nullable; -final class JedisNetworkAttributesGetter implements ServerAttributesGetter { +final class JedisNetworkAttributesGetter + implements ServerAttributesGetter, + NetworkAttributesGetter { @Nullable @Override @@ -25,7 +28,7 @@ public Integer getServerPort(JedisRequest jedisRequest) { @Override @Nullable - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( JedisRequest jedisRequest, @Nullable Void unused) { Socket socket = jedisRequest.getConnection().getSocket(); if (socket != null && socket.getRemoteSocketAddress() instanceof InetSocketAddress) { diff --git a/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisSingletons.java b/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisSingletons.java index 2314f4905f8d..fd18d97e6ee3 100644 --- a/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisSingletons.java +++ b/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisSingletons.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; @@ -30,6 +31,7 @@ public final class JedisSingletons { DbClientSpanNameExtractor.create(dbAttributesGetter)) .addAttributesExtractor(DbClientAttributesExtractor.create(dbAttributesGetter)) .addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter)) + .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor( PeerServiceAttributesExtractor.create( netAttributesGetter, CommonConfig.get().getPeerServiceResolver())) diff --git a/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java b/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java index 74a2bd8b3d67..d01a8f8dbadf 100644 --- a/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java +++ b/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java @@ -6,12 +6,14 @@ package io.opentelemetry.javaagent.instrumentation.jedis.v3_0; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.semconv.SemanticAttributes; +import org.assertj.core.api.AbstractLongAssert; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -67,7 +69,13 @@ void setCommand() { equalTo(SemanticAttributes.DB_OPERATION, "SET"), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")))); + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> val.isIn("localhost", "127.0.0.1")), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative)))); } @Test @@ -89,7 +97,13 @@ void getCommand() { equalTo(SemanticAttributes.DB_OPERATION, "SET"), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"))), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> val.isIn("localhost", "127.0.0.1")), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -101,7 +115,13 @@ void getCommand() { equalTo(SemanticAttributes.DB_OPERATION, "GET"), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")))); + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> val.isIn("localhost", "127.0.0.1")), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative)))); } @Test @@ -123,7 +143,13 @@ void commandWithNoArguments() { equalTo(SemanticAttributes.DB_OPERATION, "SET"), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"))), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> val.isIn("localhost", "127.0.0.1")), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -135,6 +161,12 @@ void commandWithNoArguments() { equalTo(SemanticAttributes.DB_OPERATION, "RANDOMKEY"), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")))); + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> val.isIn("localhost", "127.0.0.1")), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative)))); } } diff --git a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisNetworkAttributesGetter.java b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisNetworkAttributesGetter.java index b72554bdaafa..ba0ac2321d51 100644 --- a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisNetworkAttributesGetter.java +++ b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisNetworkAttributesGetter.java @@ -5,16 +5,16 @@ package io.opentelemetry.javaagent.instrumentation.jedis.v4_0; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import java.net.InetSocketAddress; import java.net.SocketAddress; import javax.annotation.Nullable; -final class JedisNetworkAttributesGetter implements ServerAttributesGetter { +final class JedisNetworkAttributesGetter implements NetworkAttributesGetter { @Override @Nullable - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( JedisRequest jedisRequest, @Nullable Void unused) { SocketAddress socketAddress = jedisRequest.getRemoteSocketAddress(); if (socketAddress instanceof InetSocketAddress) { diff --git a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java index f03f6ec09c89..340ecb4435d8 100644 --- a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java +++ b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java @@ -10,9 +10,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; -import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; public final class JedisSingletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jedis-4.0"; @@ -29,10 +27,7 @@ public final class JedisSingletons { INSTRUMENTATION_NAME, DbClientSpanNameExtractor.create(dbAttributesGetter)) .addAttributesExtractor(DbClientAttributesExtractor.create(dbAttributesGetter)) - .addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter)) - .addAttributesExtractor( - PeerServiceAttributesExtractor.create( - netAttributesGetter, CommonConfig.get().getPeerServiceResolver())) + .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } diff --git a/instrumentation/jsf/jsf-jakarta-common/testing/src/main/groovy/BaseJsfTest.groovy b/instrumentation/jsf/jsf-jakarta-common/testing/src/main/groovy/BaseJsfTest.groovy index be571b28f9f9..e4925d6ec945 100644 --- a/instrumentation/jsf/jsf-jakarta-common/testing/src/main/groovy/BaseJsfTest.groovy +++ b/instrumentation/jsf/jsf-jakarta-common/testing/src/main/groovy/BaseJsfTest.groovy @@ -93,6 +93,7 @@ abstract class BaseJsfTest extends AgentInstrumentationSpecification implements "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long "$SemanticAttributes.HTTP_METHOD" "GET" "$SemanticAttributes.HTTP_SCHEME" "http" "$SemanticAttributes.HTTP_TARGET" "/jetty-context/" + path diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy b/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy index 516ccfd48fd9..a5e9d3546f7a 100644 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy @@ -104,6 +104,7 @@ abstract class BaseJsfTest extends AgentInstrumentationSpecification implements "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long "$SemanticAttributes.HTTP_METHOD" "GET" "$SemanticAttributes.HTTP_SCHEME" "http" "$SemanticAttributes.HTTP_TARGET" "/jetty-context/" + path diff --git a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy index 2eef5dc98cdc..07a9f0b8a8e7 100644 --- a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy +++ b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy @@ -103,6 +103,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -161,6 +162,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -216,6 +218,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -279,6 +282,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -347,6 +351,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -396,6 +401,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -477,6 +483,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -527,6 +534,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } } diff --git a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy index 214fe62a11b2..647fd85c1ab6 100644 --- a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy +++ b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy @@ -100,6 +100,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -170,6 +171,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -219,6 +221,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -316,6 +319,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -399,6 +403,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { @@ -461,6 +466,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } span(1) { diff --git a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceNetworkAttributesGetter.java b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceNetworkAttributesGetter.java index 9c7d823466c0..18de90dc66b2 100644 --- a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceNetworkAttributesGetter.java +++ b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceNetworkAttributesGetter.java @@ -5,17 +5,17 @@ package io.opentelemetry.instrumentation.lettuce.v5_1; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import io.opentelemetry.instrumentation.lettuce.v5_1.OpenTelemetryTracing.OpenTelemetryEndpoint; import java.net.InetSocketAddress; import javax.annotation.Nullable; final class LettuceNetworkAttributesGetter - implements ServerAttributesGetter { + implements NetworkAttributesGetter { @Nullable @Override - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( OpenTelemetryEndpoint openTelemetryEndpoint, @Nullable Void unused) { return openTelemetryEndpoint.address; } diff --git a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java index 3756541d395c..4bedf6eaf387 100644 --- a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java +++ b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java @@ -26,7 +26,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.db.RedisCommandSanitizer; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes.DbSystemValues; import java.net.InetSocketAddress; @@ -39,7 +39,7 @@ final class OpenTelemetryTracing implements Tracing { private static final AttributesExtractor serverAttributesExtractor = - ServerAttributesExtractor.create(new LettuceNetworkAttributesGetter()); + NetworkAttributesExtractor.create(new LettuceNetworkAttributesGetter()); private final TracerProvider tracerProvider; OpenTelemetryTracing(io.opentelemetry.api.trace.Tracer tracer, RedisCommandSanitizer sanitizer) { diff --git a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy index de637ac052a9..fea30f99cfc1 100644 --- a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy +++ b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy @@ -18,7 +18,7 @@ import io.netty.handler.codec.http.HttpHeaders import io.netty.handler.codec.http.HttpMethod import io.netty.handler.codec.http.HttpVersion import io.netty.handler.ssl.SslHandler - +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestServer @@ -96,6 +96,7 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_PEER_NAME" uri.host "$SemanticAttributes.NET_PEER_PORT" uri.port "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } + "$SemanticAttributes.NET_SOCK_PEER_PORT" {it instanceof Long || it == null } } } if (SemconvStability.emitStableHttpSemconv()) { @@ -104,7 +105,8 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } @@ -127,9 +129,8 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification { attributes { "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$SemanticAttributes.SERVER_SOCKET_DOMAIN" uri.host - "$SemanticAttributes.SERVER_SOCKET_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } @@ -174,6 +175,7 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_PEER_NAME" uri.host "$SemanticAttributes.NET_PEER_PORT" uri.port "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } + "$SemanticAttributes.NET_SOCK_PEER_PORT" {it instanceof Long || it == null } } } if (SemconvStability.emitStableHttpSemconv()) { @@ -182,7 +184,8 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } @@ -202,9 +205,8 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification { attributes { "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$SemanticAttributes.SERVER_SOCKET_DOMAIN" uri.host - "$SemanticAttributes.SERVER_SOCKET_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } diff --git a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy index b2bba7eb52b2..34469662fd2d 100644 --- a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy +++ b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy @@ -16,7 +16,7 @@ import io.netty.handler.codec.http.HttpClientCodec import io.netty.handler.codec.http.HttpHeaders import io.netty.handler.codec.http.HttpMethod import io.netty.handler.codec.http.HttpVersion - +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.InstrumentationSpecification @@ -112,6 +112,7 @@ class Netty40ConnectionSpanTest extends InstrumentationSpecification implements "$SemanticAttributes.NET_PEER_NAME" uri.host "$SemanticAttributes.NET_PEER_PORT" uri.port "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_PEER_PORT" Long } } if (SemconvStability.emitStableHttpSemconv()) { @@ -120,7 +121,8 @@ class Netty40ConnectionSpanTest extends InstrumentationSpecification implements "$SemanticAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } @@ -171,6 +173,7 @@ class Netty40ConnectionSpanTest extends InstrumentationSpecification implements "$SemanticAttributes.NET_PEER_NAME" uri.host "$SemanticAttributes.NET_PEER_PORT" uri.port "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } + "$SemanticAttributes.NET_SOCK_PEER_PORT" {it instanceof Long || it == null } } } if (SemconvStability.emitStableHttpSemconv()) { @@ -179,7 +182,8 @@ class Netty40ConnectionSpanTest extends InstrumentationSpecification implements "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == null } "$SemanticAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" { it == "127.0.0.1" || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == null } + "$NetworkAttributes.NETWORK_PEER_PORT" { it == uri.port || it == null } } } } diff --git a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy index 84860ba077a7..9f5fb181c17a 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy +++ b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy @@ -20,7 +20,7 @@ import io.netty.handler.codec.http.HttpVersion import io.netty.handler.ssl.SslContext import io.netty.handler.ssl.SslContextBuilder import io.netty.handler.ssl.SslHandler - +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.netty.v4_1.ClientHandler import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification @@ -119,6 +119,7 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_PEER_NAME" uri.host "$SemanticAttributes.NET_PEER_PORT" uri.port "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } + "$SemanticAttributes.NET_SOCK_PEER_PORT" { it instanceof Long || it == null } } } if (SemconvStability.emitStableHttpSemconv()) { @@ -127,7 +128,8 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } @@ -150,9 +152,8 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification { attributes { "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$SemanticAttributes.SERVER_SOCKET_DOMAIN" uri.host - "$SemanticAttributes.SERVER_SOCKET_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } @@ -217,6 +218,7 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_PEER_NAME" uri.host "$SemanticAttributes.NET_PEER_PORT" uri.port "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } + "$SemanticAttributes.NET_SOCK_PEER_PORT" { it instanceof Long || it == null } } } if (SemconvStability.emitStableHttpSemconv()) { @@ -225,7 +227,8 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } @@ -245,9 +248,8 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification { attributes { "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$SemanticAttributes.SERVER_SOCKET_DOMAIN" uri.host - "$SemanticAttributes.SERVER_SOCKET_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } diff --git a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy index 016ef996204b..25a1ed14eaa5 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy +++ b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy @@ -16,7 +16,7 @@ import io.netty.handler.codec.http.HttpClientCodec import io.netty.handler.codec.http.HttpHeaderNames import io.netty.handler.codec.http.HttpMethod import io.netty.handler.codec.http.HttpVersion - +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.netty.v4_1.ClientHandler import io.opentelemetry.instrumentation.test.AgentTestTrait @@ -133,6 +133,7 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements "$SemanticAttributes.NET_PEER_NAME" uri.host "$SemanticAttributes.NET_PEER_PORT" uri.port "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_PEER_PORT" Long } } if (SemconvStability.emitStableHttpSemconv()) { @@ -141,7 +142,8 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements "$SemanticAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } @@ -212,6 +214,7 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements "$SemanticAttributes.NET_PEER_NAME" uri.host "$SemanticAttributes.NET_PEER_PORT" uri.port "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } + "$SemanticAttributes.NET_SOCK_PEER_PORT" { it instanceof Long || it == null } } } if (SemconvStability.emitStableHttpSemconv()) { @@ -220,7 +223,8 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == null } "$SemanticAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_PORT" uri.port - "$SemanticAttributes.SERVER_SOCKET_ADDRESS" { it == "127.0.0.1" || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == null } + "$NetworkAttributes.NETWORK_PEER_PORT" { it == uri.port || it == null } } } } diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java index 3d34ac04a47d..17998289e9ee 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java @@ -20,6 +20,7 @@ import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestServer; import io.opentelemetry.sdk.trace.data.StatusData; import io.opentelemetry.semconv.SemanticAttributes; +import org.assertj.core.api.AbstractLongAssert; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -88,7 +89,10 @@ void testSuccessfulRequest() { equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative)), span -> span.hasName("GET").hasKind(CLIENT).hasParent(trace.getSpan(0)), span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(trace.getSpan(3)))); @@ -149,6 +153,9 @@ void testFailingRequest() { equalTo(SemanticAttributes.NET_PEER_PORT, PortUtils.UNUSABLE_PORT), satisfies( SemanticAttributes.NET_SOCK_PEER_ADDR, - val -> val.isIn(null, "127.0.0.1"))))); + val -> val.isIn(null, "127.0.0.1")), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + val -> val.isIn(null, (long) PortUtils.UNUSABLE_PORT))))); } } diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java index 4ade1ecbeb4d..357ef3d10c23 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java @@ -121,7 +121,10 @@ void testSuccessfulRequest() { equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative)), span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(trace.getSpan(1)))); } diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java index 6446c57b9672..1e7e805e19b4 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java @@ -111,7 +111,10 @@ void shouldFailSslHandshake() throws SSLException { equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, server.httpsPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative)), span -> span.hasName("SSL handshake") .hasKind(INTERNAL) @@ -165,7 +168,10 @@ void shouldSuccessfullyEstablishSslHandshake() throws SSLException { equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, server.httpsPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative)), span -> span.hasName("SSL handshake") .hasKind(INTERNAL) @@ -192,7 +198,10 @@ void shouldSuccessfullyEstablishSslHandshake() throws SSLException { AbstractLongAssert::isNotNegative), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, server.httpsPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative)), span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(trace.getSpan(4)))); } diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java index 771781fe1b34..7fbf042310d7 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java @@ -91,7 +91,10 @@ void testSuccessfulRequest() { equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative)), span -> span.hasName("GET") .hasKind(CLIENT) @@ -109,7 +112,10 @@ void testSuccessfulRequest() { AbstractLongAssert::isNotNegative), equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_PEER_PORT, + AbstractLongAssert::isNotNegative)), span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(trace.getSpan(3)))); } diff --git a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonInstrumenterFactory.java b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonInstrumenterFactory.java index ebe4a626f283..022580a34fdf 100644 --- a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonInstrumenterFactory.java +++ b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonInstrumenterFactory.java @@ -10,7 +10,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; public final class RedissonInstrumenterFactory { @@ -23,7 +23,7 @@ public static Instrumenter createInstrumenter(String inst instrumentationName, DbClientSpanNameExtractor.create(dbAttributesGetter)) .addAttributesExtractor(DbClientAttributesExtractor.create(dbAttributesGetter)) - .addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter)) + .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) .buildInstrumenter(SpanKindExtractor.alwaysClient()); } diff --git a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesGetter.java b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesGetter.java index 79ad404fc305..c27818d8b2f5 100644 --- a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesGetter.java +++ b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesGetter.java @@ -5,14 +5,14 @@ package io.opentelemetry.javaagent.instrumentation.redisson; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter; import java.net.InetSocketAddress; import javax.annotation.Nullable; -final class RedissonNetAttributesGetter implements ServerAttributesGetter { +final class RedissonNetAttributesGetter implements NetworkAttributesGetter { @Override - public InetSocketAddress getServerInetSocketAddress( + public InetSocketAddress getNetworkPeerInetSocketAddress( RedissonRequest request, @Nullable Void unused) { return request.getAddress(); } diff --git a/instrumentation/spark-2.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/sparkjava/SparkJavaBasedTest.java b/instrumentation/spark-2.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/sparkjava/SparkJavaBasedTest.java index 50abf88e4aef..03dda0edc26d 100644 --- a/instrumentation/spark-2.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/sparkjava/SparkJavaBasedTest.java +++ b/instrumentation/spark-2.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/sparkjava/SparkJavaBasedTest.java @@ -76,6 +76,9 @@ void generatesSpans() { satisfies( SemanticAttributes.NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1")))); + equalTo(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"), + satisfies( + SemanticAttributes.NET_SOCK_HOST_PORT, + val -> val.isInstanceOf(Long.class))))); } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java index c5868535a920..fddcafc72d50 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java @@ -25,6 +25,7 @@ import static io.opentelemetry.semconv.SemanticAttributes.NET_PROTOCOL_NAME; import static io.opentelemetry.semconv.SemanticAttributes.NET_PROTOCOL_VERSION; import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_HOST_ADDR; +import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_HOST_PORT; import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_ADDR; import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_PORT; import static io.opentelemetry.semconv.SemanticAttributes.NET_TRANSPORT; @@ -124,6 +125,7 @@ void basicGetTest(Parameter parameter) { equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), + satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_HOST_NAME, "localhost"), satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(HTTP_TARGET, parameter.urlPath), @@ -249,6 +251,7 @@ void getAsyncResponseTest(Parameter parameter) { equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), + satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_HOST_NAME, "localhost"), satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(HTTP_TARGET, parameter.urlPath), @@ -369,6 +372,7 @@ void createSpanDuringHandlerFunctionTest(Parameter parameter) { equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), + satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_HOST_NAME, "localhost"), satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(HTTP_TARGET, parameter.urlPath), @@ -454,6 +458,7 @@ void get404Test() { equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), + satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_HOST_NAME, "localhost"), satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(HTTP_TARGET, "/notfoundgreet"), @@ -522,6 +527,7 @@ void basicPostTest() { equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), + satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_HOST_NAME, "localhost"), satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(HTTP_TARGET, "/echo"), @@ -575,6 +581,7 @@ void getToBadEndpointTest(Parameter parameter) { equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), + satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_HOST_NAME, "localhost"), satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(HTTP_TARGET, parameter.urlPath), @@ -667,6 +674,7 @@ void redirectTest() { equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), + satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_HOST_NAME, "localhost"), satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(HTTP_TARGET, "/double-greet-redirect"), @@ -708,6 +716,7 @@ void redirectTest() { equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), + satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_HOST_NAME, "localhost"), satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(HTTP_TARGET, "/double-greet"), @@ -772,6 +781,7 @@ void multipleGetsToDelayingRoute(Parameter parameter) { equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), + satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_HOST_NAME, "localhost"), satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(HTTP_TARGET, parameter.urlPath), @@ -867,6 +877,7 @@ void cancelRequestTest() throws Exception { equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), + satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(NET_HOST_NAME, "localhost"), satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), equalTo(HTTP_TARGET, "/slow"), diff --git a/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy b/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy index e6050d7c9c2b..c1cf673d54db 100644 --- a/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy +++ b/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy @@ -7,7 +7,7 @@ import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.api.trace.Span import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.api.trace.StatusCode - +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest @@ -160,6 +160,7 @@ class UndertowServerTest extends HttpServerTest implements AgentTestTr "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } if (SemconvStability.emitStableHttpSemconv()) { @@ -176,8 +177,8 @@ class UndertowServerTest extends HttpServerTest implements AgentTestTr "$SemanticAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_PORT" uri.port - "$SemanticAttributes.CLIENT_SOCKET_ADDRESS" "127.0.0.1" - "$SemanticAttributes.CLIENT_SOCKET_PORT" Long + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } } @@ -232,6 +233,7 @@ class UndertowServerTest extends HttpServerTest implements AgentTestTr "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long } } if (SemconvStability.emitStableHttpSemconv()) { @@ -248,8 +250,8 @@ class UndertowServerTest extends HttpServerTest implements AgentTestTr "$SemanticAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_PORT" uri.port - "$SemanticAttributes.CLIENT_SOCKET_ADDRESS" "127.0.0.1" - "$SemanticAttributes.CLIENT_SOCKET_PORT" Long + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } } diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy index ff9e6bab6204..93e948b484a5 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy @@ -69,6 +69,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long "$SemanticAttributes.NET_HOST_NAME" "localhost" "$SemanticAttributes.NET_HOST_PORT" Long "$SemanticAttributes.HTTP_TARGET" "/listProducts" @@ -163,6 +164,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long "$SemanticAttributes.NET_HOST_NAME" "localhost" "$SemanticAttributes.NET_HOST_PORT" Long "$SemanticAttributes.HTTP_TARGET" "$baseUrl?$TEST_REQUEST_ID_PARAMETER=$requestId" diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy index ff9e6bab6204..93e948b484a5 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy @@ -69,6 +69,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long "$SemanticAttributes.NET_HOST_NAME" "localhost" "$SemanticAttributes.NET_HOST_PORT" Long "$SemanticAttributes.HTTP_TARGET" "/listProducts" @@ -163,6 +164,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" "$SemanticAttributes.NET_SOCK_PEER_PORT" Long "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" + "$SemanticAttributes.NET_SOCK_HOST_PORT" Long "$SemanticAttributes.NET_HOST_NAME" "localhost" "$SemanticAttributes.NET_HOST_PORT" Long "$SemanticAttributes.HTTP_TARGET" "$baseUrl?$TEST_REQUEST_ID_PARAMETER=$requestId" diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java index 5217d32fa452..82faa1bfe853 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java @@ -1040,12 +1040,11 @@ SpanDataAssert assertClientSpan( if (uri.getPort() == PortUtils.UNUSABLE_PORT || uri.getHost().equals("192.0.2.1")) { // In these cases the peer connection is not established, so the HTTP client should // not report any socket-level attributes - assertThat(attrs) - .doesNotContainKey("net.sock.family") - // TODO netty sometimes reports net.sock.peer.addr in connection error test - // .doesNotContainKey("net.sock.peer.addr") - .doesNotContainKey("net.sock.peer.name") - .doesNotContainKey("net.sock.peer.port"); + assertThat(attrs).doesNotContainKey("net.sock.family"); + // TODO netty sometimes reports net.sock.peer.* in connection error test + // .doesNotContainKey("net.sock.peer.addr") + // .doesNotContainKey("net.sock.peer.name") + // .doesNotContainKey("net.sock.peer.port"); } else { // TODO: Move to test knob rather than always treating as optional diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/SemconvStabilityUtil.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/SemconvStabilityUtil.java index 57eb82ad514c..0e7cf3ab5164 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/SemconvStabilityUtil.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/SemconvStabilityUtil.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.testing.junit.http; import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.semconv.SemanticAttributes; import java.util.HashMap; @@ -27,11 +28,8 @@ public class SemconvStabilityUtil { addKey(oldToNewMap, SemanticAttributes.NET_PEER_NAME, SemanticAttributes.SERVER_ADDRESS); addKey(oldToNewMap, SemanticAttributes.NET_PEER_PORT, SemanticAttributes.SERVER_PORT); addKey( - oldToNewMap, - SemanticAttributes.NET_SOCK_PEER_ADDR, - SemanticAttributes.CLIENT_SOCKET_ADDRESS); - addKey( - oldToNewMap, SemanticAttributes.NET_SOCK_PEER_PORT, SemanticAttributes.CLIENT_SOCKET_PORT); + oldToNewMap, SemanticAttributes.NET_SOCK_PEER_ADDR, NetworkAttributes.NETWORK_PEER_ADDRESS); + addKey(oldToNewMap, SemanticAttributes.NET_SOCK_PEER_PORT, NetworkAttributes.NETWORK_PEER_PORT); addKey(oldToNewMap, SemanticAttributes.HTTP_URL, SemanticAttributes.URL_FULL); addKey(oldToNewMap, SemanticAttributes.HTTP_METHOD, SemanticAttributes.HTTP_REQUEST_METHOD); addKey( @@ -50,10 +48,6 @@ public class SemconvStabilityUtil { addKey(oldToNewMap, SemanticAttributes.NET_HOST_PORT, SemanticAttributes.SERVER_PORT); addKey(oldToNewMap, SemanticAttributes.HTTP_CLIENT_IP, SemanticAttributes.CLIENT_ADDRESS); addKey(oldToNewMap, SemanticAttributes.HTTP_SCHEME, SemanticAttributes.URL_SCHEME); - addKey( - oldToNewMap, - SemanticAttributes.NET_SOCK_HOST_ADDR, - SemanticAttributes.SERVER_SOCKET_ADDRESS); } private SemconvStabilityUtil() {}