diff --git a/benchmark/src/jmh/java/io/opentelemetry/benchmark/InstrumenterBenchmark.java b/benchmark/src/jmh/java/io/opentelemetry/benchmark/InstrumenterBenchmark.java index 0e924d92bd10..633157993bc5 100644 --- a/benchmark/src/jmh/java/io/opentelemetry/benchmark/InstrumenterBenchmark.java +++ b/benchmark/src/jmh/java/io/opentelemetry/benchmark/InstrumenterBenchmark.java @@ -11,7 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import java.util.Collections; @@ -120,13 +120,13 @@ protected List responseHeader(Void unused, Void unused2, String name) { } static class ConstantNetAttributesExtractor - extends InetSocketAddressNetAttributesExtractor { + extends InetSocketAddressNetServerAttributesExtractor { private static final InetSocketAddress ADDRESS = InetSocketAddress.createUnresolved("localhost", 8080); @Override - public @Nullable InetSocketAddress getAddress(Void unused, @Nullable Void unused2) { + public @Nullable InetSocketAddress getAddress(Void unused) { return ADDRESS; } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java index 6b7c666e5d9f..1ef45851d4f4 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java @@ -9,7 +9,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.instrumentation.api.instrumenter.db.DbAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -22,7 +22,7 @@ * * @see DbAttributesExtractor * @see HttpClientAttributesExtractor - * @see NetAttributesExtractor + * @see NetServerAttributesExtractor */ public abstract class AttributesExtractor { /** @@ -51,4 +51,13 @@ protected static void set( attributes.put(key, value); } } + + /** + * Returns an {@link AttributesExtractor} implementation that always extracts the provided + * constant value. + */ + public static AttributesExtractor constant( + AttributeKey attributeKey, T attributeValue) { + return new ConstantAttributesExtractor<>(attributeKey, attributeValue); + } } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/ConstantAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/ConstantAttributesExtractor.java new file mode 100644 index 000000000000..cf438866c966 --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/ConstantAttributesExtractor.java @@ -0,0 +1,34 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.AttributesBuilder; +import org.checkerframework.checker.nullness.qual.Nullable; + +final class ConstantAttributesExtractor + extends AttributesExtractor { + + private final AttributeKey attributeKey; + private final T attributeValue; + + ConstantAttributesExtractor(AttributeKey attributeKey, T attributeValue) { + this.attributeKey = attributeKey; + this.attributeValue = attributeValue; + } + + @Override + protected void onStart(AttributesBuilder attributes, REQUEST request) { + attributes.put(attributeKey, attributeValue); + } + + @Override + protected void onEnd( + AttributesBuilder attributes, + REQUEST request, + @Nullable RESPONSE response, + @Nullable Throwable error) {} +} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractor.java index d3bd6f73d62f..3059762af343 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractor.java @@ -7,7 +7,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.instrumentation.api.config.Config; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.Map; import org.checkerframework.checker.nullness.qual.Nullable; @@ -27,14 +27,14 @@ public final class PeerServiceAttributesExtractor Config.get().getMap("otel.instrumentation.common.peer-service-mapping"); private final Map peerServiceMapping; - private final NetAttributesExtractor netAttributesExtractor; + private final NetClientAttributesExtractor netClientAttributesExtractor; // visible for tests PeerServiceAttributesExtractor( Map peerServiceMapping, - NetAttributesExtractor netAttributesExtractor) { + NetClientAttributesExtractor netClientAttributesExtractor) { this.peerServiceMapping = peerServiceMapping; - this.netAttributesExtractor = netAttributesExtractor; + this.netClientAttributesExtractor = netClientAttributesExtractor; } /** @@ -42,15 +42,13 @@ public final class PeerServiceAttributesExtractor * netAttributesExtractor} instance to determine the value of the {@code peer.service} attribute. */ public static PeerServiceAttributesExtractor create( - NetAttributesExtractor netAttributesExtractor) { + NetClientAttributesExtractor netAttributesExtractor) { return new PeerServiceAttributesExtractor<>( JAVAAGENT_PEER_SERVICE_MAPPING, netAttributesExtractor); } @Override - protected void onStart(AttributesBuilder attributes, REQUEST request) { - onEnd(attributes, request, null, null); - } + protected void onStart(AttributesBuilder attributes, REQUEST request) {} @Override protected void onEnd( @@ -58,10 +56,10 @@ protected void onEnd( REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) { - String peerName = netAttributesExtractor.peerName(request, response); + String peerName = netClientAttributesExtractor.peerName(request, response); String peerService = mapToPeerService(peerName); if (peerService == null) { - String peerIp = netAttributesExtractor.peerIp(request, response); + String peerIp = netClientAttributesExtractor.peerIp(request, response); peerService = mapToPeerService(peerIp); } if (peerService != null) { diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesExtractor.java similarity index 78% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractor.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesExtractor.java index 2047b0239e67..176e9e114015 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesExtractor.java @@ -13,17 +13,12 @@ * Extractor of Network * attributes from a {@link InetSocketAddress}. Most network libraries will provide access to a - * {@link InetSocketAddress} so this is a convenient alternative to {@link NetAttributesExtractor}. - * There is no meaning to implement both in the same instrumentation. + * {@link InetSocketAddress} so this is a convenient alternative to {@link + * NetClientAttributesExtractor}. There is no meaning to implement both in the same instrumentation. */ -public abstract class InetSocketAddressNetAttributesExtractor - extends NetAttributesExtractor { +public abstract class InetSocketAddressNetClientAttributesExtractor + extends NetClientAttributesExtractor { - /** - * This method will be called twice: both when the request starts ({@code response} is always null - * then) and when the response ends. This way it is possible to capture net attributes in both - * phases of processing. - */ @Nullable public abstract InetSocketAddress getAddress(REQUEST request, @Nullable RESPONSE response); diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesExtractor.java new file mode 100644 index 000000000000..d3733b1df615 --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesExtractor.java @@ -0,0 +1,61 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.net; + +import java.net.InetAddress; +import java.net.InetSocketAddress; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * Extractor of Network + * attributes from a {@link InetSocketAddress}. Most network libraries will provide access to a + * {@link InetSocketAddress} so this is a convenient alternative to {@link + * NetServerAttributesExtractor}. There is no meaning to implement both in the same instrumentation. + */ +public abstract class InetSocketAddressNetServerAttributesExtractor + extends NetServerAttributesExtractor { + + @Nullable + public abstract InetSocketAddress getAddress(REQUEST request); + + @Override + @Nullable + public final String peerName(REQUEST request) { + InetSocketAddress address = getAddress(request); + if (address == null) { + return null; + } + if (address.getAddress() != null) { + return address.getAddress().getHostName(); + } + return address.getHostString(); + } + + @Override + @Nullable + public final Integer peerPort(REQUEST request) { + InetSocketAddress address = getAddress(request); + if (address == null) { + return null; + } + return address.getPort(); + } + + @Override + @Nullable + public final String peerIp(REQUEST request) { + InetSocketAddress address = getAddress(request); + if (address == null) { + return null; + } + InetAddress remoteAddress = address.getAddress(); + if (remoteAddress != null) { + return remoteAddress.getHostAddress(); + } + return null; + } +} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java similarity index 57% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractor.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java index 1a19303c5587..c3b1373ebbbd 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java @@ -14,28 +14,13 @@ * Extractor of Network * attributes. It is common to have access to {@link java.net.InetSocketAddress}, in which case - * it is more convenient to use {@link InetSocketAddressNetAttributesExtractor}. + * it is more convenient to use {@link InetSocketAddressNetClientAttributesExtractor}. */ -public abstract class NetAttributesExtractor +public abstract class NetClientAttributesExtractor extends AttributesExtractor { @Override - protected final void onStart(AttributesBuilder attributes, REQUEST request) { - set(attributes, SemanticAttributes.NET_TRANSPORT, transport(request)); - - String peerIp = peerIp(request, null); - String peerName = peerName(request, null); - - if (peerName != null && !peerName.equals(peerIp)) { - set(attributes, SemanticAttributes.NET_PEER_NAME, peerName); - } - set(attributes, SemanticAttributes.NET_PEER_IP, peerIp); - - Integer peerPort = peerPort(request, null); - if (peerPort != null) { - set(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort); - } - } + protected final void onStart(AttributesBuilder attributes, REQUEST request) {} @Override protected final void onEnd( @@ -44,6 +29,8 @@ protected final void onEnd( @Nullable RESPONSE response, @Nullable Throwable error) { + set(attributes, SemanticAttributes.NET_TRANSPORT, transport(request, response)); + String peerIp = peerIp(request, response); String peerName = peerName(request, response); @@ -59,29 +46,14 @@ protected final void onEnd( } @Nullable - public abstract String transport(REQUEST request); + public abstract String transport(REQUEST request, @Nullable RESPONSE response); - /** - * This method will be called twice: both when the request starts ({@code response} is always null - * then) and when the response ends. This way it is possible to capture net attributes in both - * phases of processing. - */ @Nullable public abstract String peerName(REQUEST request, @Nullable RESPONSE response); - /** - * This method will be called twice: both when the request starts ({@code response} is always null - * then) and when the response ends. This way it is possible to capture net attributes in both - * phases of processing. - */ @Nullable public abstract Integer peerPort(REQUEST request, @Nullable RESPONSE response); - /** - * This method will be called twice: both when the request starts ({@code response} is always null - * then) and when the response ends. This way it is possible to capture net attributes in both - * phases of processing. - */ @Nullable public abstract String peerIp(REQUEST request, @Nullable RESPONSE response); } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java new file mode 100644 index 000000000000..62d610919a2c --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java @@ -0,0 +1,58 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.net; + +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * Extractor of Network + * attributes. It is common to have access to {@link java.net.InetSocketAddress}, in which case + * it is more convenient to use {@link InetSocketAddressNetServerAttributesExtractor}. + */ +public abstract class NetServerAttributesExtractor + extends AttributesExtractor { + + @Override + protected final void onStart(AttributesBuilder attributes, REQUEST request) { + set(attributes, SemanticAttributes.NET_TRANSPORT, transport(request)); + + String peerIp = peerIp(request); + String peerName = peerName(request); + + if (peerName != null && !peerName.equals(peerIp)) { + set(attributes, SemanticAttributes.NET_PEER_NAME, peerName); + } + set(attributes, SemanticAttributes.NET_PEER_IP, peerIp); + + Integer peerPort = peerPort(request); + if (peerPort != null) { + set(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort); + } + } + + @Override + protected final void onEnd( + AttributesBuilder attributes, + REQUEST request, + @Nullable RESPONSE response, + @Nullable Throwable error) {} + + @Nullable + public abstract String transport(REQUEST request); + + @Nullable + public abstract String peerName(REQUEST request); + + @Nullable + public abstract Integer peerPort(REQUEST request); + + @Nullable + public abstract String peerIp(REQUEST request); +} diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java index 788b4b375c49..f93f579e3edc 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java @@ -27,7 +27,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessageOperation; import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcAttributesExtractor; import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension; @@ -154,7 +154,7 @@ public String get(Map carrier, String key) { MessagingAttributesExtractor, Map> mockMessagingAttributes; @Mock RpcAttributesExtractor, Map> mockRpcAttributes; - @Mock NetAttributesExtractor, Map> mockNetAttributes; + @Mock NetServerAttributesExtractor, Map> mockNetAttributes; @Test void server() { @@ -668,7 +668,7 @@ private static LinkData expectedSpanLink() { } private static final class ConstantNetPeerIpExtractor - extends NetAttributesExtractor { + extends NetServerAttributesExtractor { private final String peerIp; @@ -682,17 +682,17 @@ public String transport(REQUEST request) { } @Override - public String peerName(REQUEST request, RESPONSE response) { + public String peerName(REQUEST request) { return null; } @Override - public Integer peerPort(REQUEST request, RESPONSE response) { + public Integer peerPort(REQUEST request) { return null; } @Override - public String peerIp(REQUEST request, RESPONSE response) { + public String peerIp(REQUEST request) { return peerIp; } } diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractorTest.java index cddb025ba2fc..04a238451432 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractorTest.java @@ -14,7 +14,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -25,7 +25,7 @@ @ExtendWith(MockitoExtension.class) class PeerServiceAttributesExtractorTest { - @Mock NetAttributesExtractor netAttributesExtractor; + @Mock NetClientAttributesExtractor netAttributesExtractor; @Test void shouldNotSetAnyValueIfNetExtractorReturnsNulls() { @@ -105,8 +105,7 @@ void shouldSetPeerNameIfItMatches() { underTest.onEnd(endAttributes, "request", "response", null); // then - assertThat(startAttributes.build()) - .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); + assertThat(startAttributes.build()).isEmpty(); assertThat(endAttributes.build()) .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); } @@ -131,8 +130,7 @@ void shouldSetPeerIpIfItMatchesAndNameDoesNot() { underTest.onEnd(endAttributes, "request", "response", null); // then - assertThat(startAttributes.build()) - .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "someOtherService")); + assertThat(startAttributes.build()).isEmpty(); assertThat(endAttributes.build()) .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "someOtherService")); } diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesExtractorTest.java new file mode 100644 index 000000000000..f33a1ae77406 --- /dev/null +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesExtractorTest.java @@ -0,0 +1,99 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +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; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.net.InetSocketAddress; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class InetSocketAddressNetClientAttributesExtractorTest { + + private final InetSocketAddressNetClientAttributesExtractor + extractor = + new InetSocketAddressNetClientAttributesExtractor< + InetSocketAddress, InetSocketAddress>() { + @Override + public InetSocketAddress getAddress( + InetSocketAddress request, InetSocketAddress response) { + return response; + } + + @Override + public String transport(InetSocketAddress request, InetSocketAddress response) { + return SemanticAttributes.NetTransportValues.IP_TCP; + } + }; + + @Test + void noInetSocketAddress() { + AttributesBuilder attributes = Attributes.builder(); + extractor.onEnd(attributes, null, null, null); + assertThat(attributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP)); + } + + @Test + void fullAddress() { + // given + InetSocketAddress request = new InetSocketAddress("github.com", 123); + assertThat(request.getAddress().getHostAddress()).isNotNull(); + + InetSocketAddress response = new InetSocketAddress("api.github.com", 456); + assertThat(request.getAddress().getHostAddress()).isNotNull(); + + // when + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, request); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, request, response, null); + + // then + assertThat(startAttributes.build()).isEmpty(); + + assertThat(endAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP), + entry(SemanticAttributes.NET_PEER_IP, response.getAddress().getHostAddress()), + entry(SemanticAttributes.NET_PEER_NAME, "api.github.com"), + entry(SemanticAttributes.NET_PEER_PORT, 456L)); + } + + @Test + void unresolved() { + // given + InetSocketAddress request = InetSocketAddress.createUnresolved("github.com", 123); + assertThat(request.getAddress()).isNull(); + + InetSocketAddress response = InetSocketAddress.createUnresolved("api.github.com", 456); + assertThat(request.getAddress()).isNull(); + + // when + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, request); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, request, response, null); + + // then + assertThat(startAttributes.build()).isEmpty(); + + assertThat(endAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP), + entry(SemanticAttributes.NET_PEER_NAME, "api.github.com"), + entry(SemanticAttributes.NET_PEER_PORT, 456L)); + } +} diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesExtractorTest.java similarity index 58% rename from instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractorTest.java rename to instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesExtractorTest.java index 407273e0a27d..e5600bd4eb2b 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesExtractorTest.java @@ -17,19 +17,19 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class InetSocketAddressNetAttributesExtractorTest { +class InetSocketAddressNetServerAttributesExtractorTest { - private final InetSocketAddressNetAttributesExtractor + private final InetSocketAddressNetServerAttributesExtractor extractor = - new InetSocketAddressNetAttributesExtractor() { + new InetSocketAddressNetServerAttributesExtractor< + InetSocketAddress, InetSocketAddress>() { @Override - public InetSocketAddress getAddress( - InetSocketAddress request, InetSocketAddress response) { - return response != null ? response : request; + public InetSocketAddress getAddress(InetSocketAddress request) { + return request; } @Override - public String transport(InetSocketAddress inetSocketAddress) { + public String transport(InetSocketAddress request) { return SemanticAttributes.NetTransportValues.IP_TCP; } }; @@ -38,7 +38,6 @@ public String transport(InetSocketAddress inetSocketAddress) { void noInetSocketAddress() { AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, null); - extractor.onEnd(attributes, null, null, null); assertThat(attributes.build()) .containsOnly( entry(SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP)); @@ -47,43 +46,45 @@ void noInetSocketAddress() { @Test void fullAddress() { // given - InetSocketAddress address = new InetSocketAddress("github.com", 123); - assertThat(address.getAddress().getHostAddress()).isNotNull(); + InetSocketAddress request = new InetSocketAddress("github.com", 123); + assertThat(request.getAddress().getHostAddress()).isNotNull(); + + InetSocketAddress response = new InetSocketAddress("api.github.com", 456); + assertThat(request.getAddress().getHostAddress()).isNotNull(); // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, address); + extractor.onStart(startAttributes, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, null, address, null); + extractor.onEnd(endAttributes, request, response, null); // then assertThat(startAttributes.build()) .containsOnly( entry(SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP), - entry(SemanticAttributes.NET_PEER_IP, address.getAddress().getHostAddress()), + entry(SemanticAttributes.NET_PEER_IP, request.getAddress().getHostAddress()), entry(SemanticAttributes.NET_PEER_NAME, "github.com"), entry(SemanticAttributes.NET_PEER_PORT, 123L)); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_PEER_IP, address.getAddress().getHostAddress()), - entry(SemanticAttributes.NET_PEER_NAME, "github.com"), - entry(SemanticAttributes.NET_PEER_PORT, 123L)); + assertThat(endAttributes.build()).isEmpty(); } @Test void unresolved() { // given - InetSocketAddress address = InetSocketAddress.createUnresolved("github.com", 123); - assertThat(address.getAddress()).isNull(); + InetSocketAddress request = InetSocketAddress.createUnresolved("github.com", 123); + assertThat(request.getAddress()).isNull(); + + InetSocketAddress response = InetSocketAddress.createUnresolved("api.github.com", 456); + assertThat(request.getAddress()).isNull(); // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, address); + extractor.onStart(startAttributes, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, null, address, null); + extractor.onEnd(endAttributes, request, response, null); // then assertThat(startAttributes.build()) @@ -92,9 +93,6 @@ void unresolved() { entry(SemanticAttributes.NET_PEER_NAME, "github.com"), entry(SemanticAttributes.NET_PEER_PORT, 123L)); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_PEER_NAME, "github.com"), - entry(SemanticAttributes.NET_PEER_PORT, 123L)); + assertThat(endAttributes.build()).isEmpty(); } } diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java similarity index 73% rename from instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractorTest.java rename to instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java index f7db8ba52615..ff7a86d45401 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java @@ -15,14 +15,14 @@ import java.util.Map; import org.junit.jupiter.api.Test; -class NetAttributesExtractorTest { +class NetClientAttributesExtractorTest { - static class TestNetAttributesExtractor - extends NetAttributesExtractor, Map> { + static class TestNetClientAttributesExtractor + extends NetClientAttributesExtractor, Map> { @Override - public String transport(Map request) { - return request.get("transport"); + public String transport(Map request, Map response) { + return response.get("transport"); } @Override @@ -30,7 +30,7 @@ public String peerName(Map request, Map response if (response != null) { return response.get("peerName"); } - return request.get("peerName"); + return null; } @Override @@ -38,7 +38,7 @@ public Integer peerPort(Map request, Map respons if (response != null) { return Integer.valueOf(response.get("peerPort")); } - return Integer.valueOf(request.get("peerPort")); + return null; } @Override @@ -46,7 +46,7 @@ public String peerIp(Map request, Map response) if (response != null) { return response.get("peerIp"); } - return request.get("peerIp"); + return null; } } @@ -64,7 +64,7 @@ void normal() { response.put("peerPort", "42"); response.put("peerIp", "4.3.2.1"); - TestNetAttributesExtractor extractor = new TestNetAttributesExtractor(); + TestNetClientAttributesExtractor extractor = new TestNetClientAttributesExtractor(); // when AttributesBuilder startAttributes = Attributes.builder(); @@ -74,12 +74,7 @@ void normal() { extractor.onEnd(endAttributes, request, response, null); // then - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_TRANSPORT, "TCP"), - entry(SemanticAttributes.NET_PEER_NAME, "github.com"), - entry(SemanticAttributes.NET_PEER_PORT, 123L), - entry(SemanticAttributes.NET_PEER_IP, "1.2.3.4")); + assertThat(startAttributes.build()).isEmpty(); assertThat(endAttributes.build()) .containsOnly( @@ -102,7 +97,7 @@ public void doesNotSetDuplicateAttributes() { response.put("peerPort", "42"); response.put("peerIp", "4.3.2.1"); - TestNetAttributesExtractor extractor = new TestNetAttributesExtractor(); + TestNetClientAttributesExtractor extractor = new TestNetClientAttributesExtractor(); // when AttributesBuilder startAttributes = Attributes.builder(); @@ -112,11 +107,7 @@ public void doesNotSetDuplicateAttributes() { extractor.onEnd(endAttributes, request, response, null); // then - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_TRANSPORT, "TCP"), - entry(SemanticAttributes.NET_PEER_PORT, 123L), - entry(SemanticAttributes.NET_PEER_IP, "1.2.3.4")); + assertThat(startAttributes.build()).isEmpty(); assertThat(endAttributes.build()) .containsOnly( diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java new file mode 100644 index 000000000000..f87aacdae79b --- /dev/null +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java @@ -0,0 +1,110 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +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; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Test; + +class NetServerAttributesExtractorTest { + + static class TestNetServerAttributesExtractor + extends NetServerAttributesExtractor, Map> { + + @Override + public String transport(Map request) { + return request.get("transport"); + } + + @Override + public String peerName(Map request) { + return request.get("peerName"); + } + + @Override + public Integer peerPort(Map request) { + return Integer.valueOf(request.get("peerPort")); + } + + @Override + public String peerIp(Map request) { + return request.get("peerIp"); + } + } + + @Test + void normal() { + // given + Map request = new HashMap<>(); + request.put("transport", "TCP"); + request.put("peerName", "github.com"); + request.put("peerPort", "123"); + request.put("peerIp", "1.2.3.4"); + + Map response = new HashMap<>(); + response.put("peerName", "opentelemetry.io"); + response.put("peerPort", "42"); + response.put("peerIp", "4.3.2.1"); + + TestNetServerAttributesExtractor extractor = new TestNetServerAttributesExtractor(); + + // when + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, request); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, request, response, null); + + // then + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_TRANSPORT, "TCP"), + entry(SemanticAttributes.NET_PEER_NAME, "github.com"), + entry(SemanticAttributes.NET_PEER_PORT, 123L), + entry(SemanticAttributes.NET_PEER_IP, "1.2.3.4")); + + assertThat(endAttributes.build()).isEmpty(); + } + + @Test + public void doesNotSetDuplicateAttributes() { + // given + Map request = new HashMap<>(); + request.put("transport", "TCP"); + request.put("peerName", "1.2.3.4"); + request.put("peerIp", "1.2.3.4"); + request.put("peerPort", "123"); + + Map response = new HashMap<>(); + response.put("peerName", "4.3.2.1"); + response.put("peerPort", "42"); + response.put("peerIp", "4.3.2.1"); + + TestNetServerAttributesExtractor extractor = new TestNetServerAttributesExtractor(); + + // when + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, request); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, request, response, null); + + // then + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_TRANSPORT, "TCP"), + entry(SemanticAttributes.NET_PEER_PORT, 123L), + entry(SemanticAttributes.NET_PEER_IP, "1.2.3.4")); + + assertThat(endAttributes.build()).isEmpty(); + } +} diff --git a/instrumentation/apache-dubbo-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/OpenTelemetryFilter.java b/instrumentation/apache-dubbo-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/OpenTelemetryFilter.java index 91240ede5ebc..b14b6e574d83 100644 --- a/instrumentation/apache-dubbo-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/OpenTelemetryFilter.java +++ b/instrumentation/apache-dubbo-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/OpenTelemetryFilter.java @@ -7,8 +7,6 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboTracing; -import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; @@ -21,12 +19,7 @@ public class OpenTelemetryFilter implements Filter { private final Filter delegate; public OpenTelemetryFilter() { - DubboNetAttributesExtractor netAttributesExtractor = new DubboNetAttributesExtractor(); - delegate = - DubboTracing.newBuilder(GlobalOpenTelemetry.get()) - .addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesExtractor)) - .build() - .newFilter(); + delegate = DubboTracing.create(GlobalOpenTelemetry.get()).newFilter(); } @Override diff --git a/instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTracingBuilder.java b/instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTracingBuilder.java index 1ca734a805fe..035c3234ee84 100644 --- a/instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTracingBuilder.java +++ b/instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTracingBuilder.java @@ -6,15 +6,20 @@ package io.opentelemetry.instrumentation.apachedubbo.v2_7; import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetAttributesExtractor; +import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetClientAttributesExtractor; +import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcSpanNameExtractor; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; import org.apache.dubbo.rpc.Result; +import org.checkerframework.checker.nullness.qual.Nullable; /** A builder of {@link DubboTracing}. */ public final class DubboTracingBuilder { @@ -22,6 +27,7 @@ public final class DubboTracingBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.apache-dubbo-2.7"; private final OpenTelemetry openTelemetry; + @Nullable private String peerService; private final List> attributesExtractors = new ArrayList<>(); @@ -29,6 +35,11 @@ public final class DubboTracingBuilder { this.openTelemetry = openTelemetry; } + /** Sets the {@code peer.service} attribute for http client spans. */ + public void setPeerService(String peerService) { + this.peerService = peerService; + } + /** * Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented * items. @@ -42,19 +53,37 @@ public DubboTracingBuilder addAttributesExtractor( /** Returns a new {@link DubboTracing} with the settings of this {@link DubboTracingBuilder}. */ public DubboTracing build() { DubboRpcAttributesExtractor rpcAttributesExtractor = new DubboRpcAttributesExtractor(); - DubboNetAttributesExtractor netAttributesExtractor = new DubboNetAttributesExtractor(); SpanNameExtractor spanNameExtractor = RpcSpanNameExtractor.create(rpcAttributesExtractor); - InstrumenterBuilder builder = - Instrumenter.newBuilder( - openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor) - .addAttributesExtractor(rpcAttributesExtractor) - .addAttributesExtractor(netAttributesExtractor) - .addAttributesExtractors(attributesExtractors); + DubboNetClientAttributesExtractor netClientAttributesExtractor = + new DubboNetClientAttributesExtractor(); + + InstrumenterBuilder serverInstrumenterBuilder = + Instrumenter.newBuilder(openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor); + InstrumenterBuilder clientInstrumenterBuilder = + Instrumenter.newBuilder(openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor); + + Stream.of(serverInstrumenterBuilder, clientInstrumenterBuilder) + .forEach( + instrumenter -> + instrumenter + .addAttributesExtractors(rpcAttributesExtractor) + .addAttributesExtractors(attributesExtractors)); + + serverInstrumenterBuilder.addAttributesExtractor(new DubboNetServerAttributesExtractor()); + clientInstrumenterBuilder.addAttributesExtractor(netClientAttributesExtractor); + + if (peerService != null) { + clientInstrumenterBuilder.addAttributesExtractor( + AttributesExtractor.constant(SemanticAttributes.PEER_SERVICE, peerService)); + } else { + clientInstrumenterBuilder.addAttributesExtractor( + PeerServiceAttributesExtractor.create(netClientAttributesExtractor)); + } return new DubboTracing( - builder.newServerInstrumenter(new DubboHeadersGetter()), - builder.newClientInstrumenter(new DubboHeadersSetter())); + serverInstrumenterBuilder.newServerInstrumenter(new DubboHeadersGetter()), + clientInstrumenterBuilder.newClientInstrumenter(new DubboHeadersSetter())); } } diff --git a/instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetClientAttributesExtractor.java b/instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetClientAttributesExtractor.java new file mode 100644 index 000000000000..f045e5d666d1 --- /dev/null +++ b/instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetClientAttributesExtractor.java @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.apachedubbo.v2_7.internal; + +import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesExtractor; +import java.net.InetSocketAddress; +import org.apache.dubbo.rpc.Result; +import org.checkerframework.checker.nullness.qual.Nullable; + +public final class DubboNetClientAttributesExtractor + extends InetSocketAddressNetClientAttributesExtractor { + + @Override + public @Nullable InetSocketAddress getAddress(DubboRequest request, @Nullable Result response) { + return request.context().getRemoteAddress(); + } + + @Override + public @Nullable String transport(DubboRequest request, @Nullable Result response) { + return null; + } +} diff --git a/instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetAttributesExtractor.java b/instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetServerAttributesExtractor.java similarity index 76% rename from instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetAttributesExtractor.java rename to instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetServerAttributesExtractor.java index 2c42ab5c4081..53c194733de3 100644 --- a/instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetAttributesExtractor.java +++ b/instrumentation/apache-dubbo-2.7/library/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/DubboNetServerAttributesExtractor.java @@ -6,16 +6,16 @@ package io.opentelemetry.instrumentation.apachedubbo.v2_7.internal; import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesExtractor; import java.net.InetSocketAddress; import org.apache.dubbo.rpc.Result; import org.checkerframework.checker.nullness.qual.Nullable; -public final class DubboNetAttributesExtractor - extends InetSocketAddressNetAttributesExtractor { +public final class DubboNetServerAttributesExtractor + extends InetSocketAddressNetServerAttributesExtractor { @Override - public @Nullable InetSocketAddress getAddress(DubboRequest request, @Nullable Result result) { + public @Nullable InetSocketAddress getAddress(DubboRequest request) { return request.context().getRemoteAddress(); } diff --git a/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesExtractor.java b/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesExtractor.java index 7233ae17c35b..30ac42a7220d 100644 --- a/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesExtractor.java +++ b/instrumentation/apache-httpasyncclient-4.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpasyncclient/ApacheHttpAsyncClientNetAttributesExtractor.java @@ -5,16 +5,16 @@ package io.opentelemetry.javaagent.instrumentation.apachehttpasyncclient; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.apache.http.HttpResponse; import org.checkerframework.checker.nullness.qual.Nullable; final class ApacheHttpAsyncClientNetAttributesExtractor - extends NetAttributesExtractor { + extends NetClientAttributesExtractor { @Override - public String transport(ApacheHttpClientRequest request) { + public String transport(ApacheHttpClientRequest request, @Nullable HttpResponse response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesExtractor.java b/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesExtractor.java index d8c1ce772d0a..798930eeaac8 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesExtractor.java +++ b/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientNetAttributesExtractor.java @@ -5,17 +5,17 @@ package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v2_0; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.apache.commons.httpclient.HostConfiguration; import org.apache.commons.httpclient.HttpMethod; import org.checkerframework.checker.nullness.qual.Nullable; final class ApacheHttpClientNetAttributesExtractor - extends NetAttributesExtractor { + extends NetClientAttributesExtractor { @Override - public String transport(HttpMethod request) { + public String transport(HttpMethod request, @Nullable HttpMethod response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesExtractor.java b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesExtractor.java index 31684c16739c..1621c8f203ba 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesExtractor.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesExtractor.java @@ -5,16 +5,16 @@ package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.apache.http.HttpResponse; import org.checkerframework.checker.nullness.qual.Nullable; final class ApacheHttpClientNetAttributesExtractor - extends NetAttributesExtractor { + extends NetClientAttributesExtractor { @Override - public String transport(ApacheHttpClientRequest request) { + public String transport(ApacheHttpClientRequest request, @Nullable HttpResponse response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesExtractor.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesExtractor.java index 69458f393cef..80aac6144d3c 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesExtractor.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientNetAttributesExtractor.java @@ -5,16 +5,16 @@ package io.opentelemetry.instrumentation.apachehttpclient.v4_3; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.apache.http.HttpResponse; import org.checkerframework.checker.nullness.qual.Nullable; final class ApacheHttpClientNetAttributesExtractor - extends NetAttributesExtractor { + extends NetClientAttributesExtractor { @Override - public String transport(ApacheHttpClientRequest request) { + public String transport(ApacheHttpClientRequest request, @Nullable HttpResponse response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesExtractor.java b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesExtractor.java index 951330a4a47b..0def37bf300d 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesExtractor.java +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientNetAttributesExtractor.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.HttpResponse; @@ -14,13 +14,13 @@ import org.slf4j.LoggerFactory; final class ApacheHttpClientNetAttributesExtractor - extends NetAttributesExtractor { + extends NetClientAttributesExtractor { private static final Logger logger = LoggerFactory.getLogger(ApacheHttpClientNetAttributesExtractor.class); @Override - public String transport(ClassicHttpRequest request) { + public String transport(ClassicHttpRequest request, @Nullable HttpResponse response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java b/instrumentation/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java index 8bb0397f4d60..76caf37d9439 100644 --- a/instrumentation/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java +++ b/instrumentation/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java @@ -6,13 +6,9 @@ package io.opentelemetry.javaagent.instrumentation.armeria.v1_3; import com.linecorp.armeria.client.HttpClient; -import com.linecorp.armeria.common.RequestContext; -import com.linecorp.armeria.common.logging.RequestLog; import com.linecorp.armeria.server.HttpService; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaTracing; -import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaNetAttributesExtractor; import java.util.function.Function; // Holds singleton references to decorators to match against during suppression. @@ -23,13 +19,7 @@ public final class ArmeriaSingletons { public static final Function SERVER_DECORATOR; static { - PeerServiceAttributesExtractor peerServiceAttributesExtractor = - PeerServiceAttributesExtractor.create(new ArmeriaNetAttributesExtractor()); - - ArmeriaTracing tracing = - ArmeriaTracing.newBuilder(GlobalOpenTelemetry.get()) - .addAttributeExtractor(peerServiceAttributesExtractor) - .build(); + ArmeriaTracing tracing = ArmeriaTracing.create(GlobalOpenTelemetry.get()); CLIENT_DECORATOR = tracing.newClientDecorator(); SERVER_DECORATOR = tracing.newServiceDecorator(); diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java index c188b92bf49e..75827bc6fe7e 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java @@ -14,23 +14,28 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaNetAttributesExtractor; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaNetClientAttributesExtractor; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaNetServerAttributesExtractor; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.ArrayList; import java.util.List; import java.util.function.Function; import java.util.stream.Stream; +import org.checkerframework.checker.nullness.qual.Nullable; public final class ArmeriaTracingBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.armeria-1.3"; private final OpenTelemetry openTelemetry; + @Nullable private String peerService; private CapturedHttpHeaders capturedHttpClientHeaders = CapturedHttpHeaders.client(Config.get()); private CapturedHttpHeaders capturedHttpServerHeaders = CapturedHttpHeaders.server(Config.get()); @@ -65,6 +70,11 @@ public ArmeriaTracingBuilder addAttributeExtractor( return this; } + /** Sets the {@code peer.service} attribute for http client spans. */ + public void setPeerService(String peerService) { + this.peerService = peerService; + } + /** * Configure the HTTP client instrumentation to capture chosen HTTP request and response headers * as span attributes. @@ -92,18 +102,16 @@ public ArmeriaTracingBuilder captureHttpServerHeaders( } public ArmeriaTracing build() { - ArmeriaHttpClientAttributesExtractor clientAttributesExtractor = + ArmeriaHttpClientAttributesExtractor httpClientAttributesExtractor = new ArmeriaHttpClientAttributesExtractor(capturedHttpClientHeaders); ArmeriaHttpServerAttributesExtractor serverAttributesExtractor = new ArmeriaHttpServerAttributesExtractor(capturedHttpServerHeaders); - ArmeriaNetAttributesExtractor netAttributesExtractor = new ArmeriaNetAttributesExtractor(); - InstrumenterBuilder clientInstrumenterBuilder = Instrumenter.newBuilder( openTelemetry, INSTRUMENTATION_NAME, - HttpSpanNameExtractor.create(clientAttributesExtractor)); + HttpSpanNameExtractor.create(httpClientAttributesExtractor)); InstrumenterBuilder serverInstrumenterBuilder = Instrumenter.newBuilder( openTelemetry, @@ -111,25 +119,34 @@ public ArmeriaTracing build() { HttpSpanNameExtractor.create(serverAttributesExtractor)); Stream.of(clientInstrumenterBuilder, serverInstrumenterBuilder) - .forEach( - instrumenter -> - instrumenter - .addAttributesExtractor(netAttributesExtractor) - .addAttributesExtractors(additionalExtractors)); + .forEach(instrumenter -> instrumenter.addAttributesExtractors(additionalExtractors)); + + ArmeriaNetClientAttributesExtractor netClientAttributesExtractor = + new ArmeriaNetClientAttributesExtractor(); clientInstrumenterBuilder .setSpanStatusExtractor( statusExtractorTransformer.apply( - HttpSpanStatusExtractor.create(clientAttributesExtractor))) - .addAttributesExtractor(clientAttributesExtractor) + HttpSpanStatusExtractor.create(httpClientAttributesExtractor))) + .addAttributesExtractor(netClientAttributesExtractor) + .addAttributesExtractor(httpClientAttributesExtractor) .addRequestMetrics(HttpClientMetrics.get()); serverInstrumenterBuilder .setSpanStatusExtractor( statusExtractorTransformer.apply( HttpSpanStatusExtractor.create(serverAttributesExtractor))) + .addAttributesExtractor(new ArmeriaNetServerAttributesExtractor()) .addAttributesExtractor(serverAttributesExtractor) .addRequestMetrics(HttpServerMetrics.get()); + if (peerService != null) { + clientInstrumenterBuilder.addAttributesExtractor( + AttributesExtractor.constant(SemanticAttributes.PEER_SERVICE, peerService)); + } else { + clientInstrumenterBuilder.addAttributesExtractor( + PeerServiceAttributesExtractor.create(netClientAttributesExtractor)); + } + return new ArmeriaTracing( clientInstrumenterBuilder.newClientInstrumenter(new ClientRequestContextSetter()), serverInstrumenterBuilder.newServerInstrumenter(new RequestContextGetter())); diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetAttributesExtractor.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetClientAttributesExtractor.java similarity index 76% rename from instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetAttributesExtractor.java rename to instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetClientAttributesExtractor.java index d7ae326e66ae..b8068547e6ff 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetAttributesExtractor.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetClientAttributesExtractor.java @@ -7,17 +7,17 @@ import com.linecorp.armeria.common.RequestContext; import com.linecorp.armeria.common.logging.RequestLog; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import java.net.SocketAddress; import org.checkerframework.checker.nullness.qual.Nullable; -public final class ArmeriaNetAttributesExtractor - extends InetSocketAddressNetAttributesExtractor { +public final class ArmeriaNetClientAttributesExtractor + extends InetSocketAddressNetClientAttributesExtractor { @Override - public String transport(RequestContext ctx) { + public String transport(RequestContext ctx, @Nullable RequestLog requestLog) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetServerAttributesExtractor.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetServerAttributesExtractor.java new file mode 100644 index 000000000000..91d1dc9acfb9 --- /dev/null +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaNetServerAttributesExtractor.java @@ -0,0 +1,33 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3.internal; + +import com.linecorp.armeria.common.RequestContext; +import com.linecorp.armeria.common.logging.RequestLog; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesExtractor; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import org.checkerframework.checker.nullness.qual.Nullable; + +public final class ArmeriaNetServerAttributesExtractor + extends InetSocketAddressNetServerAttributesExtractor { + + @Override + public String transport(RequestContext ctx) { + return SemanticAttributes.NetTransportValues.IP_TCP; + } + + @Override + @Nullable + public InetSocketAddress getAddress(RequestContext ctx) { + SocketAddress address = ctx.remoteAddress(); + if (address instanceof InetSocketAddress) { + return (InetSocketAddress) address; + } + return null; + } +} diff --git a/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesExtractor.java b/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesExtractor.java index b4dc9a99f2f4..a55d55329df6 100644 --- a/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesExtractor.java +++ b/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientNetAttributesExtractor.java @@ -7,15 +7,15 @@ import com.ning.http.client.Request; import com.ning.http.client.Response; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; final class AsyncHttpClientNetAttributesExtractor - extends NetAttributesExtractor { + extends NetClientAttributesExtractor { @Override - public String transport(Request request) { + public String transport(Request request, @Nullable Response response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesExtractor.java b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesExtractor.java index 7af67b2d8d66..2112422c20c5 100644 --- a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesExtractor.java +++ b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientNetAttributesExtractor.java @@ -5,23 +5,23 @@ package io.opentelemetry.javaagent.instrumentation.asynchttpclient.v2_0; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import org.asynchttpclient.Response; import org.checkerframework.checker.nullness.qual.Nullable; final class AsyncHttpClientNetAttributesExtractor - extends InetSocketAddressNetAttributesExtractor { + extends InetSocketAddressNetClientAttributesExtractor { @Override - public String transport(RequestContext requestContext) { + public String transport(RequestContext request, @Nullable Response response) { return SemanticAttributes.NetTransportValues.IP_TCP; } @Override public @Nullable InetSocketAddress getAddress( - RequestContext requestContext, @Nullable Response response) { + RequestContext request, @Nullable Response response) { if (response != null && response.getRemoteAddress() instanceof InetSocketAddress) { return (InetSocketAddress) response.getRemoteAddress(); } diff --git a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientSingletons.java b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientSingletons.java index 83eab50cc7c2..03f4b19adcfe 100644 --- a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientSingletons.java +++ b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientSingletons.java @@ -14,7 +14,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import org.asynchttpclient.Response; public final class AsyncHttpClientSingletons { @@ -29,7 +29,7 @@ public final class AsyncHttpClientSingletons { HttpSpanNameExtractor.create(httpAttributesExtractor); SpanStatusExtractor spanStatusExtractor = HttpSpanStatusExtractor.create(httpAttributesExtractor); - NetAttributesExtractor netAttributesExtractor = + NetClientAttributesExtractor netAttributesExtractor = new AsyncHttpClientNetAttributesExtractor(); INSTRUMENTER = diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetAttributesExtractor.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetAttributesExtractor.java index 191fbe1a65ad..d3b3d22a0ec9 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetAttributesExtractor.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraNetAttributesExtractor.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.net.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesExtractor; import java.net.InetSocketAddress; import org.checkerframework.checker.nullness.qual.Nullable; final class CassandraNetAttributesExtractor - extends InetSocketAddressNetAttributesExtractor { + extends InetSocketAddressNetClientAttributesExtractor { @Override @Nullable - public String transport(CassandraRequest request) { + public String transport(CassandraRequest request, @Nullable ExecutionInfo executionInfo) { return null; } diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetAttributesExtractor.java b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetAttributesExtractor.java index 73f0193f4e0b..89accdb0c179 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetAttributesExtractor.java +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraNetAttributesExtractor.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.net.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesExtractor; import java.net.InetSocketAddress; import java.net.SocketAddress; import org.checkerframework.checker.nullness.qual.Nullable; final class CassandraNetAttributesExtractor - extends InetSocketAddressNetAttributesExtractor { + extends InetSocketAddressNetClientAttributesExtractor { @Override @Nullable - public String transport(CassandraRequest request) { + public String transport(CassandraRequest request, @Nullable ExecutionInfo executionInfo) { return null; } diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestAttributesExtractor.java b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestAttributesExtractor.java index 08ac57fb0a3c..00aace1c117b 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestAttributesExtractor.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestAttributesExtractor.java @@ -12,27 +12,27 @@ final class ElasticsearchRestAttributesExtractor extends DbAttributesExtractor { @Override - protected String system(String s) { + protected String system(String operation) { return SemanticAttributes.DbSystemValues.ELASTICSEARCH; } @Override - protected @Nullable String user(String s) { + protected @Nullable String user(String operation) { return null; } @Override - protected @Nullable String name(String s) { + protected @Nullable String name(String operation) { return null; } @Override - protected @Nullable String connectionString(String s) { + protected @Nullable String connectionString(String operation) { return null; } @Override - protected @Nullable String statement(String s) { + protected @Nullable String statement(String operation) { return null; } diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestInstrumenterFactory.java b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestInstrumenterFactory.java index ba32b2852023..77cebc4532a4 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestInstrumenterFactory.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestInstrumenterFactory.java @@ -19,8 +19,8 @@ public static Instrumenter create(String instrumentationName) ElasticsearchRestAttributesExtractor attributesExtractor = new ElasticsearchRestAttributesExtractor(); SpanNameExtractor spanNameExtractor = DbSpanNameExtractor.create(attributesExtractor); - ElasticsearchRestNetAttributesExtractor netAttributesExtractor = - new ElasticsearchRestNetAttributesExtractor(); + ElasticsearchRestNetResponseAttributesExtractor netAttributesExtractor = + new ElasticsearchRestNetResponseAttributesExtractor(); return Instrumenter.newBuilder( GlobalOpenTelemetry.get(), instrumentationName, spanNameExtractor) diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetAttributesExtractor.java b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetResponseAttributesExtractor.java similarity index 65% rename from instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetAttributesExtractor.java rename to instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetResponseAttributesExtractor.java index bda81598bd65..1ec6330c184a 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetAttributesExtractor.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetResponseAttributesExtractor.java @@ -5,20 +5,20 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.rest; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; import org.elasticsearch.client.Response; -final class ElasticsearchRestNetAttributesExtractor - extends NetAttributesExtractor { +final class ElasticsearchRestNetResponseAttributesExtractor + extends NetClientAttributesExtractor { @Override - public String transport(String s) { + public String transport(String operation, Response response) { return SemanticAttributes.NetTransportValues.IP_TCP; } @Override - public @Nullable String peerName(String s, @Nullable Response response) { + public @Nullable String peerName(String operation, @Nullable Response response) { if (response != null) { return response.getHost().getHostName(); } @@ -26,7 +26,7 @@ public String transport(String s) { } @Override - public @Nullable Integer peerPort(String s, @Nullable Response response) { + public @Nullable Integer peerPort(String operation, @Nullable Response response) { if (response != null) { return response.getHost().getPort(); } @@ -34,7 +34,7 @@ public String transport(String s) { } @Override - public @Nullable String peerIp(String s, @Nullable Response response) { + public @Nullable String peerIp(String operation, @Nullable Response response) { if (response != null && response.getHost().getAddress() != null) { return response.getHost().getAddress().getHostAddress(); } 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 bde95679c6ad..758330b64933 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.javaagent.instrumentation.elasticsearch.transport.ElasticTransportNetAttributesExtractor; +import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportNetResponseAttributesExtractor; 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 Elasticsearch5TransportSingletons { ElasticsearchTransportInstrumenterFactory.create( "io.opentelemetry.elasticsearch-transport-5.0", new Elasticsearch5TransportExperimentalAttributesExtractor(), - new ElasticTransportNetAttributesExtractor()); + new ElasticTransportNetResponseAttributesExtractor()); public static Instrumenter instrumenter() { return INSTRUMENTER; 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 e4244824eff9..8b0183eaa1b1 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.javaagent.instrumentation.elasticsearch.transport.ElasticTransportNetAttributesExtractor; +import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportNetResponseAttributesExtractor; 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 Elasticsearch53TransportSingletons { ElasticsearchTransportInstrumenterFactory.create( "io.opentelemetry.elasticsearch-transport-5.3", new Elasticsearch53TransportExperimentalAttributesExtractor(), - new ElasticTransportNetAttributesExtractor()); + new ElasticTransportNetResponseAttributesExtractor()); public static Instrumenter instrumenter() { return INSTRUMENTER; diff --git a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetAttributesExtractor.java b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetAttributesExtractor.java index 324e4be35ad6..393d2ff4e963 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetAttributesExtractor.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportNetAttributesExtractor.java @@ -5,22 +5,23 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v6_0; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesExtractor; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest; import java.net.InetSocketAddress; import org.checkerframework.checker.nullness.qual.Nullable; import org.elasticsearch.action.ActionResponse; public class Elasticsearch6TransportNetAttributesExtractor - extends InetSocketAddressNetAttributesExtractor { + extends InetSocketAddressNetClientAttributesExtractor { @Override - public @Nullable String transport(ElasticTransportRequest elasticTransportRequest) { + public @Nullable String transport( + ElasticTransportRequest request, @Nullable ActionResponse response) { return null; } @Override public @Nullable InetSocketAddress getAddress( - ElasticTransportRequest elasticTransportRequest, @Nullable ActionResponse response) { + ElasticTransportRequest request, @Nullable ActionResponse response) { if (response != null && response.remoteAddress() != null) { return response.remoteAddress().address(); } diff --git a/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetAttributesExtractor.java b/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetResponseAttributesExtractor.java similarity index 64% rename from instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetAttributesExtractor.java rename to instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetResponseAttributesExtractor.java index ec60e438038c..b06f8def120d 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetAttributesExtractor.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticTransportNetResponseAttributesExtractor.java @@ -5,20 +5,21 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import org.checkerframework.checker.nullness.qual.Nullable; import org.elasticsearch.action.ActionResponse; -public class ElasticTransportNetAttributesExtractor - extends NetAttributesExtractor { +public class ElasticTransportNetResponseAttributesExtractor + extends NetClientAttributesExtractor { @Override - public @Nullable String transport(ElasticTransportRequest elasticTransportRequest) { + public @Nullable String transport( + ElasticTransportRequest request, @Nullable ActionResponse response) { return null; } @Override public @Nullable String peerName( - ElasticTransportRequest elasticTransportRequest, @Nullable ActionResponse response) { + ElasticTransportRequest request, @Nullable ActionResponse response) { if (response != null && response.remoteAddress() != null) { return response.remoteAddress().getHost(); } @@ -27,7 +28,7 @@ public class ElasticTransportNetAttributesExtractor @Override public @Nullable Integer peerPort( - ElasticTransportRequest elasticTransportRequest, @Nullable ActionResponse response) { + ElasticTransportRequest request, @Nullable ActionResponse response) { if (response != null && response.remoteAddress() != null) { return response.remoteAddress().getPort(); } @@ -36,7 +37,7 @@ public class ElasticTransportNetAttributesExtractor @Override public @Nullable String peerIp( - ElasticTransportRequest elasticTransportRequest, @Nullable ActionResponse response) { + ElasticTransportRequest request, @Nullable ActionResponse response) { if (response != null && response.remoteAddress() != null) { return response.remoteAddress().getAddress(); } diff --git a/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportInstrumenterFactory.java b/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportInstrumenterFactory.java index e80a8f585dfc..100604898874 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportInstrumenterFactory.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportInstrumenterFactory.java @@ -12,7 +12,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbSpanNameExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; import org.elasticsearch.action.ActionResponse; public final class ElasticsearchTransportInstrumenterFactory { @@ -23,7 +22,7 @@ public final class ElasticsearchTransportInstrumenterFactory { public static Instrumenter create( String instrumentationName, AttributesExtractor experimentalAttributesExtractor, - NetAttributesExtractor netAttributesExtractor) { + AttributesExtractor netAttributesExtractor) { ElasticsearchTransportAttributesExtractor attributesExtractor = new ElasticsearchTransportAttributesExtractor(); diff --git a/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientNetAttributesExtractor.java b/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientNetAttributesExtractor.java index a69f7f96436e..6bf848c05ca4 100644 --- a/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientNetAttributesExtractor.java +++ b/instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpClientNetAttributesExtractor.java @@ -7,15 +7,15 @@ import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpResponse; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; final class GoogleHttpClientNetAttributesExtractor - extends NetAttributesExtractor { + extends NetClientAttributesExtractor { @Override - public String transport(HttpRequest request) { + public String transport(HttpRequest request, @Nullable HttpResponse response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/grpc-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grpc/v1_6/GrpcSingletons.java b/instrumentation/grpc-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grpc/v1_6/GrpcSingletons.java index 90cb1d9b7d68..6b0e78c411a4 100644 --- a/instrumentation/grpc-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grpc/v1_6/GrpcSingletons.java +++ b/instrumentation/grpc-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grpc/v1_6/GrpcSingletons.java @@ -8,14 +8,10 @@ import io.grpc.ClientInterceptor; import io.grpc.Context; import io.grpc.ServerInterceptor; -import io.grpc.Status; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.config.Config; -import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; -import io.opentelemetry.instrumentation.grpc.v1_6.GrpcRequest; import io.opentelemetry.instrumentation.grpc.v1_6.GrpcTracing; import io.opentelemetry.instrumentation.grpc.v1_6.internal.ContextStorageBridge; -import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetAttributesExtractor; // Holds singleton references. public final class GrpcSingletons { @@ -29,13 +25,10 @@ public final class GrpcSingletons { static { boolean experimentalSpanAttributes = Config.get().getBoolean("otel.instrumentation.grpc.experimental-span-attributes", false); - PeerServiceAttributesExtractor peerServiceAttributesExtractor = - PeerServiceAttributesExtractor.create(new GrpcNetAttributesExtractor()); GrpcTracing tracing = GrpcTracing.newBuilder(GlobalOpenTelemetry.get()) .setCaptureExperimentalSpanAttributes(experimentalSpanAttributes) - .addAttributeExtractor(peerServiceAttributesExtractor) .build(); CLIENT_INTERCEPTOR = tracing.newClientInterceptor(); diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcTracingBuilder.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcTracingBuilder.java index e0a696396fba..9aff5327884d 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcTracingBuilder.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcTracingBuilder.java @@ -10,10 +10,15 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetAttributesExtractor; +import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetClientAttributesExtractor; +import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetServerAttributesExtractor; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; +import org.checkerframework.checker.nullness.qual.Nullable; /** A builder of {@link GrpcTracing}. */ public final class GrpcTracingBuilder { @@ -21,6 +26,7 @@ public final class GrpcTracingBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.grpc-1.6"; private final OpenTelemetry openTelemetry; + @Nullable private String peerService; private final List> additionalExtractors = new ArrayList<>(); @@ -41,6 +47,11 @@ public GrpcTracingBuilder addAttributeExtractor( return this; } + /** Sets the {@code peer.service} attribute for http client spans. */ + public void setPeerService(String peerService) { + this.peerService = peerService; + } + /** * Sets whether experimental attributes should be set to spans. These attributes may be changed or * removed in the future, so only enable this if you know you do not require attributes filled by @@ -54,20 +65,39 @@ public GrpcTracingBuilder setCaptureExperimentalSpanAttributes( /** Returns a new {@link GrpcTracing} with the settings of this {@link GrpcTracingBuilder}. */ public GrpcTracing build() { - InstrumenterBuilder instrumenterBuilder = + InstrumenterBuilder clientInstrumenterBuilder = Instrumenter.newBuilder(openTelemetry, INSTRUMENTATION_NAME, new GrpcSpanNameExtractor()); - instrumenterBuilder - .setSpanStatusExtractor(new GrpcSpanStatusExtractor()) - .addAttributesExtractors( - new GrpcNetAttributesExtractor(), - new GrpcRpcAttributesExtractor(), - new GrpcAttributesExtractor()) - .addAttributesExtractors(additionalExtractors); + InstrumenterBuilder serverInstrumenterBuilder = + Instrumenter.newBuilder(openTelemetry, INSTRUMENTATION_NAME, new GrpcSpanNameExtractor()); + + Stream.of(clientInstrumenterBuilder, serverInstrumenterBuilder) + .forEach( + instrumenter -> + instrumenter + .setSpanStatusExtractor(new GrpcSpanStatusExtractor()) + .addAttributesExtractors( + new GrpcRpcAttributesExtractor(), new GrpcAttributesExtractor()) + .addAttributesExtractors(additionalExtractors)); + + GrpcNetClientAttributesExtractor netClientAttributesExtractor = + new GrpcNetClientAttributesExtractor(); + + clientInstrumenterBuilder.addAttributesExtractor(netClientAttributesExtractor); + serverInstrumenterBuilder.addAttributesExtractor(new GrpcNetServerAttributesExtractor()); + + if (peerService != null) { + clientInstrumenterBuilder.addAttributesExtractor( + AttributesExtractor.constant(SemanticAttributes.PEER_SERVICE, peerService)); + } else { + clientInstrumenterBuilder.addAttributesExtractor( + PeerServiceAttributesExtractor.create(netClientAttributesExtractor)); + } + return new GrpcTracing( - instrumenterBuilder.newServerInstrumenter(GrpcExtractAdapter.GETTER), + serverInstrumenterBuilder.newServerInstrumenter(GrpcExtractAdapter.GETTER), // gRPC client interceptors require two phases, one to set up request and one to execute. // So we go ahead and inject manually in this instrumentation. - instrumenterBuilder.newInstrumenter(SpanKindExtractor.alwaysClient()), + clientInstrumenterBuilder.newInstrumenter(SpanKindExtractor.alwaysClient()), openTelemetry.getPropagators(), captureExperimentalSpanAttributes); } diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetClientAttributesExtractor.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetClientAttributesExtractor.java new file mode 100644 index 000000000000..687d47823dfd --- /dev/null +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetClientAttributesExtractor.java @@ -0,0 +1,32 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.grpc.v1_6.internal; + +import io.grpc.Status; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesExtractor; +import io.opentelemetry.instrumentation.grpc.v1_6.GrpcRequest; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import org.checkerframework.checker.nullness.qual.Nullable; + +public final class GrpcNetClientAttributesExtractor + extends InetSocketAddressNetClientAttributesExtractor { + @Override + @Nullable + public InetSocketAddress getAddress(GrpcRequest request, @Nullable Status response) { + SocketAddress address = request.getRemoteAddress(); + if (address instanceof InetSocketAddress) { + return (InetSocketAddress) address; + } + return null; + } + + @Override + public String transport(GrpcRequest request, @Nullable Status response) { + return SemanticAttributes.NetTransportValues.IP_TCP; + } +} diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetAttributesExtractor.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetServerAttributesExtractor.java similarity index 76% rename from instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetAttributesExtractor.java rename to instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetServerAttributesExtractor.java index 4f5b35f4b008..46e4530003fe 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetAttributesExtractor.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/internal/GrpcNetServerAttributesExtractor.java @@ -6,18 +6,18 @@ package io.opentelemetry.instrumentation.grpc.v1_6.internal; import io.grpc.Status; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesExtractor; import io.opentelemetry.instrumentation.grpc.v1_6.GrpcRequest; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import java.net.SocketAddress; import org.checkerframework.checker.nullness.qual.Nullable; -public final class GrpcNetAttributesExtractor - extends InetSocketAddressNetAttributesExtractor { +public final class GrpcNetServerAttributesExtractor + extends InetSocketAddressNetServerAttributesExtractor { @Override @Nullable - public InetSocketAddress getAddress(GrpcRequest request, @Nullable Status status) { + public InetSocketAddress getAddress(GrpcRequest request) { SocketAddress address = request.getRemoteAddress(); if (address instanceof InetSocketAddress) { return (InetSocketAddress) address; diff --git a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesExtractor.java b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesExtractor.java index e9e8cc73da72..4db163268098 100644 --- a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesExtractor.java +++ b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlNetAttributesExtractor.java @@ -5,29 +5,30 @@ package io.opentelemetry.javaagent.instrumentation.httpurlconnection; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.HttpURLConnection; import org.checkerframework.checker.nullness.qual.Nullable; -class HttpUrlNetAttributesExtractor extends NetAttributesExtractor { +class HttpUrlNetAttributesExtractor + extends NetClientAttributesExtractor { @Override - public @Nullable String transport(HttpURLConnection connection) { + public @Nullable String transport(HttpURLConnection connection, @Nullable Integer status) { return SemanticAttributes.NetTransportValues.IP_TCP; } @Override - public String peerName(HttpURLConnection connection, @Nullable Integer statusCode) { + public String peerName(HttpURLConnection connection, @Nullable Integer status) { return connection.getURL().getHost(); } @Override - public Integer peerPort(HttpURLConnection connection, @Nullable Integer statusCode) { + public Integer peerPort(HttpURLConnection connection, @Nullable Integer status) { return connection.getURL().getPort(); } @Override - public @Nullable String peerIp(HttpURLConnection connection, @Nullable Integer statusCode) { + public @Nullable String peerIp(HttpURLConnection connection, @Nullable Integer status) { return null; } } diff --git a/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpNetAttributesExtractor.java b/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpNetAttributesExtractor.java index 5d78c2647918..f3de1a2f9b34 100644 --- a/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpNetAttributesExtractor.java +++ b/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/JdkHttpNetAttributesExtractor.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.httpclient; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.http.HttpRequest; import java.net.http.HttpResponse; @@ -14,24 +14,22 @@ import org.slf4j.LoggerFactory; public class JdkHttpNetAttributesExtractor - extends NetAttributesExtractor> { + extends NetClientAttributesExtractor> { private static final Logger logger = LoggerFactory.getLogger(JdkHttpNetAttributesExtractor.class); @Override - public String transport(HttpRequest httpRequest) { + public String transport(HttpRequest httpRequest, @Nullable HttpResponse response) { return SemanticAttributes.NetTransportValues.IP_TCP; } @Override - public @Nullable String peerName( - HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + public @Nullable String peerName(HttpRequest httpRequest, @Nullable HttpResponse response) { return httpRequest.uri().getHost(); } @Override - public @Nullable Integer peerPort( - HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + public @Nullable Integer peerPort(HttpRequest httpRequest, @Nullable HttpResponse response) { int port = httpRequest.uri().getPort(); if (port != -1) { return port; @@ -52,7 +50,7 @@ public String transport(HttpRequest httpRequest) { } @Override - public @Nullable String peerIp(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) { + public @Nullable String peerIp(HttpRequest httpRequest, @Nullable HttpResponse response) { return null; } } diff --git a/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientNetAttributesExtractor.java b/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientNetAttributesExtractor.java index eb80e0166a7f..f06b882123be 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientNetAttributesExtractor.java +++ b/instrumentation/jaxrs-client/jaxrs-client-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v1_1/JaxRsClientNetAttributesExtractor.java @@ -7,15 +7,15 @@ import com.sun.jersey.api.client.ClientRequest; import com.sun.jersey.api.client.ClientResponse; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; final class JaxRsClientNetAttributesExtractor - extends NetAttributesExtractor { + extends NetClientAttributesExtractor { @Override - public String transport(ClientRequest request) { + public String transport(ClientRequest request, @Nullable ClientResponse response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/JaxRsClientNetAttributesExtractor.java b/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/JaxRsClientNetAttributesExtractor.java index de96a7087640..46d70a4b8076 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/JaxRsClientNetAttributesExtractor.java +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/JaxRsClientNetAttributesExtractor.java @@ -5,17 +5,17 @@ package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientResponseContext; import org.checkerframework.checker.nullness.qual.Nullable; final class JaxRsClientNetAttributesExtractor - extends NetAttributesExtractor { + extends NetClientAttributesExtractor { @Override - public String transport(ClientRequestContext request) { + public String transport(ClientRequestContext request, @Nullable ClientResponseContext response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ResteasyClientNetAttributesExtractor.java b/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ResteasyClientNetAttributesExtractor.java index 62c9115968b8..3531a1de7504 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ResteasyClientNetAttributesExtractor.java +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ResteasyClientNetAttributesExtractor.java @@ -5,17 +5,17 @@ package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.ws.rs.core.Response; import org.checkerframework.checker.nullness.qual.Nullable; import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation; final class ResteasyClientNetAttributesExtractor - extends NetAttributesExtractor { + extends NetClientAttributesExtractor { @Override - public String transport(ClientInvocation request) { + public String transport(ClientInvocation request, @Nullable Response response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetAttributesExtractor.java b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetAttributesExtractor.java index c0b9bd67525c..1fa982490273 100644 --- a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetAttributesExtractor.java +++ b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcNetAttributesExtractor.java @@ -5,14 +5,15 @@ package io.opentelemetry.instrumentation.jdbc.internal; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import org.checkerframework.checker.nullness.qual.Nullable; -public final class JdbcNetAttributesExtractor extends NetAttributesExtractor { +public final class JdbcNetAttributesExtractor + extends NetClientAttributesExtractor { @Nullable @Override - public String transport(DbRequest request) { + public String transport(DbRequest request, @Nullable Void unused) { return null; } diff --git a/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisNetAttributesExtractor.java b/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisNetAttributesExtractor.java index 0647d9dedc2c..378bd7c08c88 100644 --- a/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisNetAttributesExtractor.java +++ b/instrumentation/jedis/jedis-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisNetAttributesExtractor.java @@ -5,14 +5,14 @@ package io.opentelemetry.javaagent.instrumentation.jedis.v1_4; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import org.checkerframework.checker.nullness.qual.Nullable; -final class JedisNetAttributesExtractor extends NetAttributesExtractor { +final class JedisNetAttributesExtractor extends NetClientAttributesExtractor { @Override @Nullable - public String transport(JedisRequest request) { + public String transport(JedisRequest request, @Nullable Void unused) { return null; } diff --git a/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetAttributesExtractor.java b/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetAttributesExtractor.java index 5927492ad0d7..64b9a7b3a575 100644 --- a/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetAttributesExtractor.java +++ b/instrumentation/jedis/jedis-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/JedisNetAttributesExtractor.java @@ -5,14 +5,14 @@ package io.opentelemetry.javaagent.instrumentation.jedis.v3_0; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import java.net.Socket; import org.checkerframework.checker.nullness.qual.Nullable; final class JedisNetAttributesExtractor - extends InetSocketAddressNetAttributesExtractor { + extends InetSocketAddressNetClientAttributesExtractor { @Override public @Nullable InetSocketAddress getAddress(JedisRequest jedisRequest, @Nullable Void unused) { @@ -24,7 +24,7 @@ final class JedisNetAttributesExtractor } @Override - public String transport(JedisRequest jedisRequest) { + public String transport(JedisRequest jedisRequest, @Nullable Void unused) { return SemanticAttributes.NetTransportValues.IP_TCP; } } diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesExtractor.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesExtractor.java index 1cddd2826b95..111c6ea11edb 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesExtractor.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientNetAttributesExtractor.java @@ -5,17 +5,17 @@ package io.opentelemetry.instrumentation.jetty.httpclient.v9_2.internal; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.api.Response; public class JettyHttpClientNetAttributesExtractor - extends NetAttributesExtractor { + extends NetClientAttributesExtractor { @Override - public String transport(Request request) { + public String transport(Request request, @Nullable Response response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesNetAttributesExtractor.java b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesNetAttributesExtractor.java index 185700820451..f0419bd4e910 100644 --- a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesNetAttributesExtractor.java +++ b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesNetAttributesExtractor.java @@ -6,29 +6,30 @@ package io.opentelemetry.javaagent.instrumentation.kubernetesclient; import io.kubernetes.client.openapi.ApiResponse; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import okhttp3.Request; import org.checkerframework.checker.nullness.qual.Nullable; -class KubernetesNetAttributesExtractor extends NetAttributesExtractor> { +class KubernetesNetAttributesExtractor + extends NetClientAttributesExtractor> { @Override - public String transport(Request request) { + public String transport(Request request, @Nullable ApiResponse response) { return SemanticAttributes.NetTransportValues.IP_TCP; } @Override - public String peerName(Request request, @Nullable ApiResponse apiResponse) { + public String peerName(Request request, @Nullable ApiResponse response) { return request.url().host(); } @Override - public Integer peerPort(Request request, @Nullable ApiResponse apiResponse) { + public Integer peerPort(Request request, @Nullable ApiResponse response) { return request.url().port(); } @Override - public @Nullable String peerIp(Request request, @Nullable ApiResponse apiResponse) { + public @Nullable String peerIp(Request request, @Nullable ApiResponse response) { return null; } } diff --git a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectNetAttributesExtractor.java b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectNetAttributesExtractor.java index d5731f9d5067..f43c0c56007a 100644 --- a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectNetAttributesExtractor.java +++ b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectNetAttributesExtractor.java @@ -6,14 +6,15 @@ package io.opentelemetry.javaagent.instrumentation.lettuce.v4_0; import com.lambdaworks.redis.RedisURI; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import org.checkerframework.checker.nullness.qual.Nullable; -final class LettuceConnectNetAttributesExtractor extends NetAttributesExtractor { +final class LettuceConnectNetAttributesExtractor + extends NetClientAttributesExtractor { @Override @Nullable - public String transport(RedisURI redisUri) { + public String transport(RedisURI redisUri, @Nullable Void unused) { return null; } diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectNetAttributesExtractor.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectNetAttributesExtractor.java index 6dcbbb3f359b..3293311da4b0 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectNetAttributesExtractor.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectNetAttributesExtractor.java @@ -6,14 +6,15 @@ package io.opentelemetry.javaagent.instrumentation.lettuce.v5_0; import io.lettuce.core.RedisURI; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import org.checkerframework.checker.nullness.qual.Nullable; -final class LettuceConnectNetAttributesExtractor extends NetAttributesExtractor { +final class LettuceConnectNetAttributesExtractor + extends NetClientAttributesExtractor { @Override @Nullable - public String transport(RedisURI redisUri) { + public String transport(RedisURI redisUri, @Nullable Void unused) { return null; } diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherLinkInstrumentation.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherLinkInstrumentation.java index 7103e3eaa567..bd2636aef70c 100644 --- a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherLinkInstrumentation.java +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherLinkInstrumentation.java @@ -81,7 +81,6 @@ public static void stopSpan( scope.close(); LibertyResponse response = new LibertyResponse(httpDispatcherLink, statusCode); - request.setCompleted(); Throwable t = failure != null ? failure : throwable; instrumenter().end(context, request, response, t); diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesExtractor.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesExtractor.java index a92444eabe39..8ea1a1cfc7ef 100644 --- a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesExtractor.java +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesExtractor.java @@ -5,12 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; public class LibertyDispatcherNetAttributesExtractor - extends NetAttributesExtractor { + extends NetServerAttributesExtractor { @Override public String transport(LibertyRequest libertyRequest) { @@ -18,32 +18,17 @@ public String transport(LibertyRequest libertyRequest) { } @Override - public @Nullable String peerName( - LibertyRequest libertyRequest, @Nullable LibertyResponse libertyResponse) { - // condition limits calling peerName to onStart because in onEnd it may throw a NPE - if (!libertyRequest.isCompleted()) { - return libertyRequest.peerName(); - } - return null; + public @Nullable String peerName(LibertyRequest libertyRequest) { + return libertyRequest.peerName(); } @Override - public @Nullable Integer peerPort( - LibertyRequest libertyRequest, @Nullable LibertyResponse libertyResponse) { - // condition limits calling getServerPort to onStart because in onEnd it may throw a NPE - if (!libertyRequest.isCompleted()) { - return libertyRequest.getServerPort(); - } - return null; + public @Nullable Integer peerPort(LibertyRequest libertyRequest) { + return libertyRequest.getServerPort(); } @Override - public @Nullable String peerIp( - LibertyRequest libertyRequest, @Nullable LibertyResponse libertyResponse) { - // condition limits calling peerIp to onStart because in onEnd it may throw a NPE - if (!libertyRequest.isCompleted()) { - return libertyRequest.peerIp(); - } - return null; + public @Nullable String peerIp(LibertyRequest libertyRequest) { + return libertyRequest.peerIp(); } } diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java index 217d553ca298..0256958dfeca 100644 --- a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java @@ -9,14 +9,13 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming; public final class LibertyDispatcherSingletons { @@ -31,7 +30,7 @@ public final class LibertyDispatcherSingletons { HttpSpanNameExtractor.create(httpAttributesExtractor); SpanStatusExtractor spanStatusExtractor = HttpSpanStatusExtractor.create(httpAttributesExtractor); - NetAttributesExtractor netAttributesExtractor = + NetServerAttributesExtractor netAttributesExtractor = new LibertyDispatcherNetAttributesExtractor(); INSTRUMENTER = @@ -40,7 +39,6 @@ public final class LibertyDispatcherSingletons { .setSpanStatusExtractor(spanStatusExtractor) .addAttributesExtractor(httpAttributesExtractor) .addAttributesExtractor(netAttributesExtractor) - .addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesExtractor)) .addContextCustomizer( (context, request, attributes) -> ServerSpanNaming.init(context, CONTAINER)) .addRequestMetrics(HttpServerMetrics.get()) diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java index 08200c1d49d0..21c418827afe 100644 --- a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java @@ -15,7 +15,6 @@ public class LibertyRequest { private final HttpDispatcherLink httpDispatcherLink; private final HttpRequestMessage httpRequestMessage; - private boolean completed; public LibertyRequest( HttpDispatcherLink httpDispatcherLink, HttpRequestMessage httpRequestMessage) { @@ -79,12 +78,4 @@ public String peerName() { public String getProtocol() { return httpRequestMessage.getVersion(); } - - public boolean isCompleted() { - return completed; - } - - public void setCompleted() { - completed = true; - } } diff --git a/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesExtractor.java b/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesExtractor.java index 311629264205..ef86b564307b 100644 --- a/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesExtractor.java +++ b/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2NetAttributesExtractor.java @@ -7,13 +7,14 @@ import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; -public final class OkHttp2NetAttributesExtractor extends NetAttributesExtractor { +public final class OkHttp2NetAttributesExtractor + extends NetClientAttributesExtractor { @Override - public String transport(Request request) { + public String transport(Request request, @Nullable Response response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Singletons.java b/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Singletons.java index 46bd076ee34c..b0a73b6fa1d3 100644 --- a/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Singletons.java +++ b/instrumentation/okhttp/okhttp-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Singletons.java @@ -20,7 +20,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; public final class OkHttp2Singletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.okhttp-2.2"; @@ -35,7 +35,7 @@ public final class OkHttp2Singletons { HttpSpanNameExtractor.create(httpAttributesExtractor); SpanStatusExtractor spanStatusExtractor = HttpSpanStatusExtractor.create(httpAttributesExtractor); - NetAttributesExtractor netAttributesExtractor = + NetClientAttributesExtractor netAttributesExtractor = new OkHttp2NetAttributesExtractor(); OpenTelemetry openTelemetry = GlobalOpenTelemetry.get(); diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesExtractor.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesExtractor.java index 929ac8d79213..e0d7273895cb 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesExtractor.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpNetAttributesExtractor.java @@ -5,15 +5,16 @@ package io.opentelemetry.instrumentation.okhttp.v3_0.internal; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import okhttp3.Request; import okhttp3.Response; import org.checkerframework.checker.nullness.qual.Nullable; -public final class OkHttpNetAttributesExtractor extends NetAttributesExtractor { +public final class OkHttpNetAttributesExtractor + extends NetClientAttributesExtractor { @Override - public String transport(Request request) { + public String transport(Request request, @Nullable Response response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientNetAttributesExtractor.java b/instrumentation/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientNetAttributesExtractor.java index 6c50ae237ced..832da2e0897d 100644 --- a/instrumentation/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientNetAttributesExtractor.java +++ b/instrumentation/play-ws/play-ws-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientNetAttributesExtractor.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.playws; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import org.checkerframework.checker.nullness.qual.Nullable; @@ -13,10 +13,10 @@ import play.shaded.ahc.org.asynchttpclient.Response; final class PlayWsClientNetAttributesExtractor - extends InetSocketAddressNetAttributesExtractor { + extends InetSocketAddressNetClientAttributesExtractor { @Override - public String transport(Request request) { + public String transport(Request request, @Nullable Response response) { return SemanticAttributes.NetTransportValues.IP_TCP; } diff --git a/instrumentation/ratpack-1.4/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetAttributesExtractor.java b/instrumentation/ratpack-1.4/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetAttributesExtractor.java index f43f19e01124..542af94905c3 100644 --- a/instrumentation/ratpack-1.4/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetAttributesExtractor.java +++ b/instrumentation/ratpack-1.4/library/src/main/java/io/opentelemetry/instrumentation/ratpack/internal/RatpackNetAttributesExtractor.java @@ -5,13 +5,14 @@ package io.opentelemetry.instrumentation.ratpack.internal; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; import ratpack.http.Request; import ratpack.http.Response; -public final class RatpackNetAttributesExtractor extends NetAttributesExtractor { +public final class RatpackNetAttributesExtractor + extends NetServerAttributesExtractor { @Override @Nullable public String transport(Request request) { @@ -20,18 +21,18 @@ public String transport(Request request) { @Override @Nullable - public String peerName(Request request, @Nullable Response response) { + public String peerName(Request request) { return null; } @Override - public Integer peerPort(Request request, @Nullable Response response) { + public Integer peerPort(Request request) { return request.getRemoteAddress().getPort(); } @Override @Nullable - public String peerIp(Request request, @Nullable Response response) { + public String peerIp(Request request) { return null; } } diff --git a/instrumentation/redisson-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesExtractor.java b/instrumentation/redisson-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesExtractor.java index 4faf9ade5fcc..5e13851b4b7b 100644 --- a/instrumentation/redisson-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesExtractor.java +++ b/instrumentation/redisson-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonNetAttributesExtractor.java @@ -5,12 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.redisson; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesExtractor; import java.net.InetSocketAddress; import org.checkerframework.checker.nullness.qual.Nullable; final class RedissonNetAttributesExtractor - extends InetSocketAddressNetAttributesExtractor { + extends InetSocketAddressNetClientAttributesExtractor { @Override public InetSocketAddress getAddress(RedissonRequest request, @Nullable Void unused) { @@ -19,7 +19,7 @@ public InetSocketAddress getAddress(RedissonRequest request, @Nullable Void unus @Nullable @Override - public String transport(RedissonRequest request) { + public String transport(RedissonRequest request, @Nullable Void unused) { return null; } } diff --git a/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletNetAttributesExtractor.java b/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletNetAttributesExtractor.java index cc4a6f1ff277..eecc64cdfd2b 100644 --- a/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletNetAttributesExtractor.java +++ b/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletNetAttributesExtractor.java @@ -5,30 +5,30 @@ package io.opentelemetry.instrumentation.restlet.v1_0; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; import org.restlet.data.Request; import org.restlet.data.Response; -final class RestletNetAttributesExtractor extends NetAttributesExtractor { +final class RestletNetAttributesExtractor extends NetServerAttributesExtractor { @Override public String transport(Request request) { return SemanticAttributes.NetTransportValues.IP_TCP; } @Override - public @Nullable String peerName(Request request, @Nullable Response response) { + public @Nullable String peerName(Request request) { return null; } @Override - public Integer peerPort(Request request, @Nullable Response response) { + public Integer peerPort(Request request) { return request.getClientInfo().getPort(); } @Override - public @Nullable String peerIp(Request request, @Nullable Response response) { + public @Nullable String peerIp(Request request) { return request.getClientInfo().getAddress(); } } diff --git a/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletTracingBuilder.java b/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletTracingBuilder.java index 9044bca3ca8a..26b3a171f1b5 100644 --- a/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletTracingBuilder.java +++ b/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/RestletTracingBuilder.java @@ -14,7 +14,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import java.util.ArrayList; import java.util.List; import org.restlet.data.Request; @@ -66,7 +66,7 @@ public RestletTracing build() { HttpSpanNameExtractor.create(httpAttributesExtractor); SpanStatusExtractor spanStatusExtractor = HttpSpanStatusExtractor.create(httpAttributesExtractor); - NetAttributesExtractor netAttributesExtractor = + NetServerAttributesExtractor netAttributesExtractor = new RestletNetAttributesExtractor(); Instrumenter instrumenter = diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java index d51cb3e0e04a..986223b05ebb 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java @@ -10,7 +10,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.ContextCustomizer; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; @@ -73,7 +72,6 @@ public Instrumenter, ServletResponseContext> contextCustomizer : diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesExtractor.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesExtractor.java index f5f03cf15b52..ad40d42efdc9 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesExtractor.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesExtractor.java @@ -5,12 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.servlet; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.servlet.ServletAccessor; import org.checkerframework.checker.nullness.qual.Nullable; public class ServletNetAttributesExtractor - extends NetAttributesExtractor< + extends NetServerAttributesExtractor< ServletRequestContext, ServletResponseContext> { private final ServletAccessor accessor; @@ -25,24 +25,18 @@ public ServletNetAttributesExtractor(ServletAccessor accessor } @Override - public @Nullable String peerName( - ServletRequestContext requestContext, - @Nullable ServletResponseContext responseContext) { + public @Nullable String peerName(ServletRequestContext requestContext) { // return accessor.getRequestRemoteHost(requestContext.request()); return null; } @Override - public @Nullable Integer peerPort( - ServletRequestContext requestContext, - @Nullable ServletResponseContext responseContext) { + public @Nullable Integer peerPort(ServletRequestContext requestContext) { return accessor.getRequestRemotePort(requestContext.request()); } @Override - public @Nullable String peerIp( - ServletRequestContext requestContext, - @Nullable ServletResponseContext responseContext) { + public @Nullable String peerIp(ServletRequestContext requestContext) { return accessor.getRequestRemoteAddr(requestContext.request()); } } diff --git a/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebNetAttributesExtractor.java b/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebNetAttributesExtractor.java index 09141a106c18..7226c714355e 100644 --- a/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebNetAttributesExtractor.java +++ b/instrumentation/spring/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/SpringWebNetAttributesExtractor.java @@ -5,34 +5,31 @@ package io.opentelemetry.instrumentation.spring.web; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpResponse; final class SpringWebNetAttributesExtractor - extends NetAttributesExtractor { + extends NetServerAttributesExtractor { @Override public String transport(HttpRequest httpRequest) { return SemanticAttributes.NetTransportValues.IP_TCP; } @Override - public @Nullable String peerName( - HttpRequest httpRequest, @Nullable ClientHttpResponse clientHttpResponse) { + public @Nullable String peerName(HttpRequest httpRequest) { return httpRequest.getURI().getHost(); } @Override - public Integer peerPort( - HttpRequest httpRequest, @Nullable ClientHttpResponse clientHttpResponse) { + public Integer peerPort(HttpRequest httpRequest) { return httpRequest.getURI().getPort(); } @Override - public @Nullable String peerIp( - HttpRequest httpRequest, @Nullable ClientHttpResponse clientHttpResponse) { + public @Nullable String peerIp(HttpRequest httpRequest) { return null; } } diff --git a/instrumentation/spring/spring-webmvc-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/SpringWebMvcNetAttributesExtractor.java b/instrumentation/spring/spring-webmvc-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/SpringWebMvcNetAttributesExtractor.java index 5cc7c8bf0ba0..561482b5992d 100644 --- a/instrumentation/spring/spring-webmvc-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/SpringWebMvcNetAttributesExtractor.java +++ b/instrumentation/spring/spring-webmvc-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/SpringWebMvcNetAttributesExtractor.java @@ -5,33 +5,31 @@ package io.opentelemetry.instrumentation.spring.webmvc; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.checkerframework.checker.nullness.qual.Nullable; final class SpringWebMvcNetAttributesExtractor - extends NetAttributesExtractor { + extends NetServerAttributesExtractor { @Override public String transport(HttpServletRequest request) { return SemanticAttributes.NetTransportValues.IP_TCP; } @Override - public @Nullable String peerName( - HttpServletRequest request, @Nullable HttpServletResponse response) { + public @Nullable String peerName(HttpServletRequest request) { return request.getRemoteHost(); } @Override - public Integer peerPort(HttpServletRequest request, @Nullable HttpServletResponse response) { + public Integer peerPort(HttpServletRequest request) { return request.getRemotePort(); } @Override - public @Nullable String peerIp( - HttpServletRequest request, @Nullable HttpServletResponse response) { + public @Nullable String peerIp(HttpServletRequest request) { return request.getRemoteAddr(); } } diff --git a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterBuilder.java b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterBuilder.java index ffe2b015f1dc..17d49a875fe2 100644 --- a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterBuilder.java +++ b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterBuilder.java @@ -10,14 +10,13 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.servlet.AppServerBridge; import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming; import io.opentelemetry.instrumentation.servlet.ServletAccessor; @@ -39,7 +38,7 @@ public static Instrumenter newInstrumente HttpSpanNameExtractor.create(httpAttributesExtractor); SpanStatusExtractor spanStatusExtractor = HttpSpanStatusExtractor.create(httpAttributesExtractor); - NetAttributesExtractor netAttributesExtractor = + NetServerAttributesExtractor netAttributesExtractor = new TomcatNetAttributesExtractor(); AttributesExtractor additionalAttributeExtractor = new TomcatAdditionalAttributesExtractor<>(accessor, servletEntityProvider); @@ -50,7 +49,6 @@ public static Instrumenter newInstrumente .setErrorCauseExtractor(new ServletErrorCauseExtractor<>(accessor)) .addAttributesExtractor(httpAttributesExtractor) .addAttributesExtractor(netAttributesExtractor) - .addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesExtractor)) .addAttributesExtractor(additionalAttributeExtractor) .addContextCustomizer( (context, request, attributes) -> { diff --git a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesExtractor.java b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesExtractor.java index 4552f2d58284..366ea499083b 100644 --- a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesExtractor.java +++ b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesExtractor.java @@ -5,13 +5,13 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.common; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import org.apache.coyote.ActionCode; import org.apache.coyote.Request; import org.apache.coyote.Response; import org.checkerframework.checker.nullness.qual.Nullable; -public class TomcatNetAttributesExtractor extends NetAttributesExtractor { +public class TomcatNetAttributesExtractor extends NetServerAttributesExtractor { @Override public @Nullable String transport(Request request) { @@ -20,7 +20,7 @@ public class TomcatNetAttributesExtractor extends NetAttributesExtractor { + extends InetSocketAddressNetServerAttributesExtractor { @Override - public @Nullable InetSocketAddress getAddress( - HttpServerExchange exchange, @Nullable HttpServerExchange unused) { + public @Nullable InetSocketAddress getAddress(HttpServerExchange exchange) { return exchange.getConnection().getPeerAddress(InetSocketAddress.class); } diff --git a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java index 8801f55d24cd..d928f18f42b6 100644 --- a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java +++ b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java @@ -9,14 +9,13 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.servlet.AppServerBridge; import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming; import io.opentelemetry.javaagent.bootstrap.undertow.UndertowActiveHandlers; @@ -34,7 +33,7 @@ public final class UndertowSingletons { HttpSpanNameExtractor.create(httpAttributesExtractor); SpanStatusExtractor spanStatusExtractor = HttpSpanStatusExtractor.create(httpAttributesExtractor); - NetAttributesExtractor netAttributesExtractor = + NetServerAttributesExtractor netAttributesExtractor = new UndertowNetAttributesExtractor(); INSTRUMENTER = @@ -43,7 +42,6 @@ public final class UndertowSingletons { .setSpanStatusExtractor(spanStatusExtractor) .addAttributesExtractor(httpAttributesExtractor) .addAttributesExtractor(netAttributesExtractor) - .addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesExtractor)) .addContextCustomizer( (context, request, attributes) -> { context = ServerSpanNaming.init(context, CONTAINER);