Factor out NetServerAttributesGetter (#5194)

* factor out NetServerAttributesGetter and favor composition over inheritance.

* Update instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesGetter.java

Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>

* errorprone and spotless

* spotless

Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
This commit is contained in:
jason plumb 2022-01-21 17:01:30 -08:00 committed by GitHub
parent 23fb0bd73b
commit fe8a132ee9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 163 additions and 122 deletions

View File

@ -10,7 +10,8 @@ import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders; import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Collections; import java.util.Collections;
@ -41,7 +42,8 @@ public class InstrumenterBenchmark {
"benchmark", "benchmark",
HttpSpanNameExtractor.create(ConstantHttpAttributesExtractor.INSTANCE)) HttpSpanNameExtractor.create(ConstantHttpAttributesExtractor.INSTANCE))
.addAttributesExtractor(ConstantHttpAttributesExtractor.INSTANCE) .addAttributesExtractor(ConstantHttpAttributesExtractor.INSTANCE)
.addAttributesExtractor(new ConstantNetAttributesExtractor()) .addAttributesExtractor(
NetServerAttributesExtractor.create(new ConstantNetAttributesGetter()))
.newInstrumenter(); .newInstrumenter();
@Benchmark @Benchmark
@ -126,8 +128,8 @@ public class InstrumenterBenchmark {
} }
} }
static class ConstantNetAttributesExtractor static class ConstantNetAttributesGetter
extends InetSocketAddressNetServerAttributesExtractor<Void, Void> { extends InetSocketAddressNetServerAttributesGetter<Void> {
private static final InetSocketAddress ADDRESS = private static final InetSocketAddress ADDRESS =
InetSocketAddress.createUnresolved("localhost", 8080); InetSocketAddress.createUnresolved("localhost", 8080);

View File

@ -16,8 +16,8 @@ import javax.annotation.Nullable;
* {@link InetSocketAddress} so this is a convenient alternative to {@link * {@link InetSocketAddress} so this is a convenient alternative to {@link
* NetServerAttributesExtractor}. There is no meaning to implement both in the same instrumentation. * NetServerAttributesExtractor}. There is no meaning to implement both in the same instrumentation.
*/ */
public abstract class InetSocketAddressNetServerAttributesExtractor<REQUEST, RESPONSE> public abstract class InetSocketAddressNetServerAttributesGetter<REQUEST>
extends NetServerAttributesExtractor<REQUEST, RESPONSE> { implements NetServerAttributesGetter<REQUEST> {
@Nullable @Nullable
public abstract InetSocketAddress getAddress(REQUEST request); public abstract InetSocketAddress getAddress(REQUEST request);

View File

@ -14,45 +14,44 @@ import javax.annotation.Nullable;
* Extractor of <a * Extractor of <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes">Network * href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes">Network
* attributes</a>. It is common to have access to {@link java.net.InetSocketAddress}, in which case * attributes</a>. It is common to have access to {@link java.net.InetSocketAddress}, in which case
* it is more convenient to use {@link InetSocketAddressNetServerAttributesExtractor}. * it is more convenient to use {@link InetSocketAddressNetServerAttributesGetter}.
*/ */
public abstract class NetServerAttributesExtractor<REQUEST, RESPONSE> public final class NetServerAttributesExtractor<REQUEST, RESPONSE>
implements AttributesExtractor<REQUEST, RESPONSE> { implements AttributesExtractor<REQUEST, RESPONSE> {
private final NetServerAttributesGetter<REQUEST> getter;
public static <REQUEST, RESPONSE> NetServerAttributesExtractor<REQUEST, RESPONSE> create(
NetServerAttributesGetter<REQUEST> getter) {
return new NetServerAttributesExtractor<>(getter);
}
private NetServerAttributesExtractor(NetServerAttributesGetter<REQUEST> getter) {
this.getter = getter;
}
@Override @Override
public final void onStart(AttributesBuilder attributes, REQUEST request) { public final void onStart(AttributesBuilder attributes, REQUEST request) {
set(attributes, SemanticAttributes.NET_TRANSPORT, transport(request)); set(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request));
String peerIp = peerIp(request); String peerIp = getter.peerIp(request);
String peerName = peerName(request); String peerName = getter.peerName(request);
if (peerName != null && !peerName.equals(peerIp)) { if (peerName != null && !peerName.equals(peerIp)) {
set(attributes, SemanticAttributes.NET_PEER_NAME, peerName); set(attributes, SemanticAttributes.NET_PEER_NAME, peerName);
} }
set(attributes, SemanticAttributes.NET_PEER_IP, peerIp); set(attributes, SemanticAttributes.NET_PEER_IP, peerIp);
Integer peerPort = peerPort(request); Integer peerPort = getter.peerPort(request);
if (peerPort != null && peerPort > 0) { if (peerPort != null && peerPort > 0) {
set(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort); set(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort);
} }
} }
@Override @Override
public final void onEnd( public void onEnd(
AttributesBuilder attributes, AttributesBuilder attributes,
REQUEST request, REQUEST request,
@Nullable RESPONSE response, @Nullable RESPONSE response,
@Nullable Throwable error) {} @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);
} }

View File

@ -0,0 +1,31 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.api.instrumenter.net;
import javax.annotation.Nullable;
/**
* An interface for getting server-based network attributes. It adapts a vendor-specific request
* type into the 4 common attributes (transport, peerName, peerPort, peerIp).
*
* <p>Instrumentation authors will create implementations of this interface for their specific
* server library/framework. It will be used by the {@link NetServerAttributesExtractor} to obtain
* the various network attributes in a type-generic way.
*/
public interface NetServerAttributesGetter<REQUEST> {
@Nullable
String transport(REQUEST request);
@Nullable
String peerName(REQUEST request);
@Nullable
Integer peerPort(REQUEST request);
@Nullable
String peerIp(REQUEST request);
}

View File

@ -30,6 +30,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttribut
import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessageOperation; import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessageOperation;
import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcAttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.SpanKey; import io.opentelemetry.instrumentation.api.internal.SpanKey;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
@ -290,7 +291,7 @@ class InstrumenterTest {
otelTesting.getOpenTelemetry(), "test", unused -> "span") otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addAttributesExtractors( .addAttributesExtractors(
mockHttpServerAttributes, mockHttpServerAttributes,
new ConstantNetPeerIpExtractor<>("2.2.2.2"), NetServerAttributesExtractor.create(new ConstantNetPeerIpGetter<>("2.2.2.2")),
new AttributesExtractor1(), new AttributesExtractor1(),
new AttributesExtractor2()) new AttributesExtractor2())
.addSpanLinksExtractor(new LinksExtractor()) .addSpanLinksExtractor(new LinksExtractor())
@ -765,12 +766,12 @@ class InstrumenterTest {
LINK_TRACE_ID, LINK_SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault())); LINK_TRACE_ID, LINK_SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault()));
} }
private static final class ConstantNetPeerIpExtractor<REQUEST, RESPONSE> private static final class ConstantNetPeerIpGetter<REQUEST>
extends NetServerAttributesExtractor<REQUEST, RESPONSE> { implements NetServerAttributesGetter<REQUEST> {
private final String peerIp; private final String peerIp;
private ConstantNetPeerIpExtractor(String peerIp) { private ConstantNetPeerIpGetter(String peerIp) {
this.peerIp = peerIp; this.peerIp = peerIp;
} }

View File

@ -17,12 +17,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class InetSocketAddressNetServerAttributesExtractorTest { class InetSocketAddressNetServerAttributesGetterTest {
private final InetSocketAddressNetServerAttributesExtractor<InetSocketAddress, InetSocketAddress> private final NetServerAttributesExtractor<InetSocketAddress, InetSocketAddress> extractor =
extractor = NetServerAttributesExtractor.create(
new InetSocketAddressNetServerAttributesExtractor< new InetSocketAddressNetServerAttributesGetter<InetSocketAddress>() {
InetSocketAddress, InetSocketAddress>() {
@Override @Override
public InetSocketAddress getAddress(InetSocketAddress request) { public InetSocketAddress getAddress(InetSocketAddress request) {
return request; return request;
@ -32,7 +31,7 @@ class InetSocketAddressNetServerAttributesExtractorTest {
public String transport(InetSocketAddress request) { public String transport(InetSocketAddress request) {
return SemanticAttributes.NetTransportValues.IP_TCP; return SemanticAttributes.NetTransportValues.IP_TCP;
} }
}; });
@Test @Test
void noInetSocketAddress() { void noInetSocketAddress() {

View File

@ -17,8 +17,8 @@ import org.junit.jupiter.api.Test;
class NetServerAttributesExtractorTest { class NetServerAttributesExtractorTest {
static class TestNetServerAttributesExtractor static class TestNetServerAttributesGetter
extends NetServerAttributesExtractor<Map<String, String>, Map<String, String>> { implements NetServerAttributesGetter<Map<String, String>> {
@Override @Override
public String transport(Map<String, String> request) { public String transport(Map<String, String> request) {
@ -55,7 +55,8 @@ class NetServerAttributesExtractorTest {
response.put("peerPort", "42"); response.put("peerPort", "42");
response.put("peerIp", "4.3.2.1"); response.put("peerIp", "4.3.2.1");
TestNetServerAttributesExtractor extractor = new TestNetServerAttributesExtractor(); NetServerAttributesExtractor<Map<String, String>, Map<String, String>> extractor =
createTestExtractor();
// when // when
AttributesBuilder startAttributes = Attributes.builder(); AttributesBuilder startAttributes = Attributes.builder();
@ -89,7 +90,8 @@ class NetServerAttributesExtractorTest {
response.put("peerPort", "42"); response.put("peerPort", "42");
response.put("peerIp", "4.3.2.1"); response.put("peerIp", "4.3.2.1");
TestNetServerAttributesExtractor extractor = new TestNetServerAttributesExtractor(); NetServerAttributesExtractor<Map<String, String>, Map<String, String>> extractor =
createTestExtractor();
// when // when
AttributesBuilder startAttributes = Attributes.builder(); AttributesBuilder startAttributes = Attributes.builder();
@ -117,7 +119,8 @@ class NetServerAttributesExtractorTest {
Map<String, String> response = new HashMap<>(); Map<String, String> response = new HashMap<>();
response.put("peerPort", "-1"); response.put("peerPort", "-1");
TestNetServerAttributesExtractor extractor = new TestNetServerAttributesExtractor(); NetServerAttributesExtractor<Map<String, String>, Map<String, String>> extractor =
createTestExtractor();
// when // when
AttributesBuilder startAttributes = Attributes.builder(); AttributesBuilder startAttributes = Attributes.builder();
@ -130,4 +133,9 @@ class NetServerAttributesExtractorTest {
assertThat(startAttributes.build()).isEmpty(); assertThat(startAttributes.build()).isEmpty();
assertThat(endAttributes.build()).isEmpty(); assertThat(endAttributes.build()).isEmpty();
} }
private static NetServerAttributesExtractor<Map<String, String>, Map<String, String>>
createTestExtractor() {
return NetServerAttributesExtractor.create(new TestNetServerAttributesGetter());
}
} }

View File

@ -7,13 +7,14 @@ package io.opentelemetry.instrumentation.apachedubbo.v2_7;
import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetClientAttributesGetter; import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetClientAttributesGetter;
import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetServerAttributesExtractor; import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcSpanNameExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.ArrayList; import java.util.ArrayList;
@ -73,7 +74,8 @@ public final class DubboTracingBuilder {
.addAttributesExtractors(rpcAttributesExtractor) .addAttributesExtractors(rpcAttributesExtractor)
.addAttributesExtractors(attributesExtractors)); .addAttributesExtractors(attributesExtractors));
serverInstrumenterBuilder.addAttributesExtractor(new DubboNetServerAttributesExtractor()); serverInstrumenterBuilder.addAttributesExtractor(
NetServerAttributesExtractor.create(new DubboNetServerAttributesGetter()));
clientInstrumenterBuilder.addAttributesExtractor(netClientAttributesExtractor); clientInstrumenterBuilder.addAttributesExtractor(netClientAttributesExtractor);
if (peerService != null) { if (peerService != null) {

View File

@ -6,13 +6,12 @@
package io.opentelemetry.instrumentation.apachedubbo.v2_7.internal; package io.opentelemetry.instrumentation.apachedubbo.v2_7.internal;
import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest; import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesGetter;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.dubbo.rpc.Result;
public final class DubboNetServerAttributesExtractor public final class DubboNetServerAttributesGetter
extends InetSocketAddressNetServerAttributesExtractor<DubboRequest, Result> { extends InetSocketAddressNetServerAttributesGetter<DubboRequest> {
@Override @Override
@Nullable @Nullable

View File

@ -6,15 +6,14 @@
package io.opentelemetry.instrumentation.armeria.v1_3; package io.opentelemetry.instrumentation.armeria.v1_3;
import com.linecorp.armeria.common.RequestContext; import com.linecorp.armeria.common.RequestContext;
import com.linecorp.armeria.common.logging.RequestLog; import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import javax.annotation.Nullable; import javax.annotation.Nullable;
final class ArmeriaNetServerAttributesExtractor final class ArmeriaNetServerAttributesGetter
extends InetSocketAddressNetServerAttributesExtractor<RequestContext, RequestLog> { extends InetSocketAddressNetServerAttributesGetter<RequestContext> {
@Override @Override
public String transport(RequestContext ctx) { public String transport(RequestContext ctx) {

View File

@ -22,6 +22,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.instrumentation.api.server.ServerSpanNaming;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.ArrayList; import java.util.ArrayList;
@ -137,7 +138,8 @@ public final class ArmeriaTracingBuilder {
.setSpanStatusExtractor( .setSpanStatusExtractor(
statusExtractorTransformer.apply( statusExtractorTransformer.apply(
HttpSpanStatusExtractor.create(serverAttributesExtractor))) HttpSpanStatusExtractor.create(serverAttributesExtractor)))
.addAttributesExtractor(new ArmeriaNetServerAttributesExtractor()) .addAttributesExtractor(
NetServerAttributesExtractor.create(new ArmeriaNetServerAttributesGetter()))
.addAttributesExtractor(serverAttributesExtractor) .addAttributesExtractor(serverAttributesExtractor)
.addRequestMetrics(HttpServerMetrics.get()) .addRequestMetrics(HttpServerMetrics.get())
.addContextCustomizer(ServerSpanNaming.get()); .addContextCustomizer(ServerSpanNaming.get());

View File

@ -5,13 +5,11 @@
package io.opentelemetry.javaagent.instrumentation.grizzly; package io.opentelemetry.javaagent.instrumentation.grizzly;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.HttpRequestPacket;
import org.glassfish.grizzly.http.HttpResponsePacket;
final class GrizzlyNetAttributesExtractor final class GrizzlyNetAttributesGetter implements NetServerAttributesGetter<HttpRequestPacket> {
extends NetServerAttributesExtractor<HttpRequestPacket, HttpResponsePacket> {
@Nullable @Nullable
@Override @Override

View File

@ -10,6 +10,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.instrumentation.api.server.ServerSpanNaming;
import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.HttpRequestPacket;
import org.glassfish.grizzly.http.HttpResponsePacket; import org.glassfish.grizzly.http.HttpResponsePacket;
@ -20,7 +21,7 @@ public final class GrizzlySingletons {
static { static {
GrizzlyHttpAttributesExtractor httpAttributesExtractor = new GrizzlyHttpAttributesExtractor(); GrizzlyHttpAttributesExtractor httpAttributesExtractor = new GrizzlyHttpAttributesExtractor();
GrizzlyNetAttributesExtractor netAttributesExtractor = new GrizzlyNetAttributesExtractor(); GrizzlyNetAttributesGetter netAttributesGetter = new GrizzlyNetAttributesGetter();
INSTRUMENTER = INSTRUMENTER =
Instrumenter.<HttpRequestPacket, HttpResponsePacket>builder( Instrumenter.<HttpRequestPacket, HttpResponsePacket>builder(
@ -29,7 +30,7 @@ public final class GrizzlySingletons {
HttpSpanNameExtractor.create(httpAttributesExtractor)) HttpSpanNameExtractor.create(httpAttributesExtractor))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor))
.addAttributesExtractor(httpAttributesExtractor) .addAttributesExtractor(httpAttributesExtractor)
.addAttributesExtractor(netAttributesExtractor) .addAttributesExtractor(NetServerAttributesExtractor.create(netAttributesGetter))
.addRequestMetrics(HttpServerMetrics.get()) .addRequestMetrics(HttpServerMetrics.get())
.addContextCustomizer( .addContextCustomizer(
(context, httpRequestPacket, startAttributes) -> GrizzlyErrorHolder.init(context)) (context, httpRequestPacket, startAttributes) -> GrizzlyErrorHolder.init(context))

View File

@ -13,8 +13,9 @@ import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.PeerServiceAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetClientAttributesGetter; import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetClientAttributesGetter;
import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetServerAttributesExtractor; import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -85,7 +86,8 @@ public final class GrpcTracingBuilder {
clientInstrumenterBuilder.addAttributesExtractor( clientInstrumenterBuilder.addAttributesExtractor(
NetClientAttributesExtractor.create(netClientAttributesExtractor)); NetClientAttributesExtractor.create(netClientAttributesExtractor));
serverInstrumenterBuilder.addAttributesExtractor(new GrpcNetServerAttributesExtractor()); serverInstrumenterBuilder.addAttributesExtractor(
NetServerAttributesExtractor.create(new GrpcNetServerAttributesGetter()));
if (peerService != null) { if (peerService != null) {
clientInstrumenterBuilder.addAttributesExtractor( clientInstrumenterBuilder.addAttributesExtractor(

View File

@ -5,16 +5,15 @@
package io.opentelemetry.instrumentation.grpc.v1_6.internal; package io.opentelemetry.instrumentation.grpc.v1_6.internal;
import io.grpc.Status; import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesExtractor;
import io.opentelemetry.instrumentation.grpc.v1_6.GrpcRequest; import io.opentelemetry.instrumentation.grpc.v1_6.GrpcRequest;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public final class GrpcNetServerAttributesExtractor public final class GrpcNetServerAttributesGetter
extends InetSocketAddressNetServerAttributesExtractor<GrpcRequest, Status> { extends InetSocketAddressNetServerAttributesGetter<GrpcRequest> {
@Override @Override
@Nullable @Nullable
public InetSocketAddress getAddress(GrpcRequest request) { public InetSocketAddress getAddress(GrpcRequest request) {

View File

@ -7,10 +7,10 @@ package io.opentelemetry.instrumentation.ktor.v1_0
import io.ktor.request.* import io.ktor.request.*
import io.ktor.response.* import io.ktor.response.*
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
internal class KtorNetServerAttributesExtractor : NetServerAttributesExtractor<ApplicationRequest, ApplicationResponse>() { internal class KtorNetServerAttributesGetter : NetServerAttributesGetter<ApplicationRequest> {
override fun transport(request: ApplicationRequest): String { override fun transport(request: ApplicationRequest): String {
return SemanticAttributes.NetTransportValues.IP_TCP return SemanticAttributes.NetTransportValues.IP_TCP
} }

View File

@ -22,6 +22,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeader
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor
import io.opentelemetry.instrumentation.api.server.ServerSpanNaming import io.opentelemetry.instrumentation.api.server.ServerSpanNaming
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -98,7 +99,7 @@ class KtorServerTracing private constructor(
with(instrumenterBuilder) { with(instrumenterBuilder) {
setSpanStatusExtractor(configuration.statusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor))) setSpanStatusExtractor(configuration.statusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor)))
addAttributesExtractor(KtorNetServerAttributesExtractor()) addAttributesExtractor(NetServerAttributesExtractor.create(KtorNetServerAttributesGetter()))
addAttributesExtractor(httpAttributesExtractor) addAttributesExtractor(httpAttributesExtractor)
addRequestMetrics(HttpServerMetrics.get()) addRequestMetrics(HttpServerMetrics.get())
addContextCustomizer(ServerSpanNaming.get()) addContextCustomizer(ServerSpanNaming.get())

View File

@ -5,12 +5,12 @@
package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher; package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class LibertyDispatcherNetAttributesExtractor public class LibertyDispatcherNetAttributesGetter
extends NetServerAttributesExtractor<LibertyRequest, LibertyResponse> { implements NetServerAttributesGetter<LibertyRequest> {
@Override @Override
public String transport(LibertyRequest libertyRequest) { public String transport(LibertyRequest libertyRequest) {

View File

@ -29,7 +29,7 @@ public final class LibertyDispatcherSingletons {
SpanStatusExtractor<LibertyRequest, LibertyResponse> spanStatusExtractor = SpanStatusExtractor<LibertyRequest, LibertyResponse> spanStatusExtractor =
HttpSpanStatusExtractor.create(httpAttributesExtractor); HttpSpanStatusExtractor.create(httpAttributesExtractor);
NetServerAttributesExtractor<LibertyRequest, LibertyResponse> netAttributesExtractor = NetServerAttributesExtractor<LibertyRequest, LibertyResponse> netAttributesExtractor =
new LibertyDispatcherNetAttributesExtractor(); NetServerAttributesExtractor.create(new LibertyDispatcherNetAttributesGetter());
INSTRUMENTER = INSTRUMENTER =
Instrumenter.<LibertyRequest, LibertyResponse>builder( Instrumenter.<LibertyRequest, LibertyResponse>builder(

View File

@ -8,16 +8,15 @@ package io.opentelemetry.javaagent.instrumentation.netty.v3_8.server;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP; import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_UDP; import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_UDP;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesGetter;
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel; import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jboss.netty.channel.socket.DatagramChannel; import org.jboss.netty.channel.socket.DatagramChannel;
import org.jboss.netty.handler.codec.http.HttpResponse;
final class NettyNetServerAttributesExtractor final class NettyNetServerAttributesGetter
extends InetSocketAddressNetServerAttributesExtractor<HttpRequestAndChannel, HttpResponse> { extends InetSocketAddressNetServerAttributesGetter<HttpRequestAndChannel> {
@Override @Override
@Nullable @Nullable

View File

@ -10,6 +10,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.instrumentation.api.server.ServerSpanNaming;
import io.opentelemetry.javaagent.instrumentation.netty.common.NettyErrorHolder; import io.opentelemetry.javaagent.instrumentation.netty.common.NettyErrorHolder;
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel; import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel;
@ -30,7 +31,8 @@ final class NettyServerSingletons {
HttpSpanNameExtractor.create(httpServerAttributesExtractor)) HttpSpanNameExtractor.create(httpServerAttributesExtractor))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpServerAttributesExtractor)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpServerAttributesExtractor))
.addAttributesExtractor(httpServerAttributesExtractor) .addAttributesExtractor(httpServerAttributesExtractor)
.addAttributesExtractor(new NettyNetServerAttributesExtractor()) .addAttributesExtractor(
NetServerAttributesExtractor.create(new NettyNetServerAttributesGetter()))
.addRequestMetrics(HttpServerMetrics.get()) .addRequestMetrics(HttpServerMetrics.get())
.addContextCustomizer( .addContextCustomizer(
(context, requestAndChannel, startAttributes) -> NettyErrorHolder.init(context)) (context, requestAndChannel, startAttributes) -> NettyErrorHolder.init(context))

View File

@ -9,15 +9,14 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_UDP; import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_UDP;
import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.DatagramChannel;
import io.netty.handler.codec.http.HttpResponse; import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesExtractor;
import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel; import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import javax.annotation.Nullable; import javax.annotation.Nullable;
final class NettyNetServerAttributesExtractor final class NettyNetServerAttributesGetter
extends InetSocketAddressNetServerAttributesExtractor<HttpRequestAndChannel, HttpResponse> { extends InetSocketAddressNetServerAttributesGetter<HttpRequestAndChannel> {
@Override @Override
@Nullable @Nullable

View File

@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.instrumentation.api.server.ServerSpanNaming;
import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel; import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel;
import io.opentelemetry.javaagent.instrumentation.netty.common.NettyErrorHolder; import io.opentelemetry.javaagent.instrumentation.netty.common.NettyErrorHolder;
@ -29,7 +30,8 @@ public final class NettyServerInstrumenterFactory {
HttpSpanNameExtractor.create(httpAttributesExtractor)) HttpSpanNameExtractor.create(httpAttributesExtractor))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor))
.addAttributesExtractor(httpAttributesExtractor) .addAttributesExtractor(httpAttributesExtractor)
.addAttributesExtractor(new NettyNetServerAttributesExtractor()) .addAttributesExtractor(
NetServerAttributesExtractor.create(new NettyNetServerAttributesGetter()))
.addRequestMetrics(HttpServerMetrics.get()) .addRequestMetrics(HttpServerMetrics.get())
.addContextCustomizer((context, request, attributes) -> NettyErrorHolder.init(context)) .addContextCustomizer((context, request, attributes) -> NettyErrorHolder.init(context))
.addContextCustomizer(ServerSpanNaming.get()) .addContextCustomizer(ServerSpanNaming.get())

View File

@ -14,8 +14,9 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.ratpack.internal.RatpackHttpNetAttributesGetter; import io.opentelemetry.instrumentation.ratpack.internal.RatpackHttpNetAttributesGetter;
import io.opentelemetry.instrumentation.ratpack.internal.RatpackNetAttributesExtractor; import io.opentelemetry.instrumentation.ratpack.internal.RatpackNetAttributesGetter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import ratpack.http.Request; import ratpack.http.Request;
@ -71,7 +72,7 @@ public final class RatpackTracingBuilder {
/** Returns a new {@link RatpackTracing} with the configuration of this builder. */ /** Returns a new {@link RatpackTracing} with the configuration of this builder. */
public RatpackTracing build() { public RatpackTracing build() {
RatpackNetAttributesExtractor netAttributes = new RatpackNetAttributesExtractor(); RatpackNetAttributesGetter netAttributes = new RatpackNetAttributesGetter();
RatpackHttpAttributesExtractor httpAttributes = RatpackHttpAttributesExtractor httpAttributes =
new RatpackHttpAttributesExtractor(capturedHttpHeaders); new RatpackHttpAttributesExtractor(capturedHttpHeaders);
@ -79,7 +80,7 @@ public final class RatpackTracingBuilder {
Instrumenter.<Request, Response>builder( Instrumenter.<Request, Response>builder(
openTelemetry, INSTRUMENTATION_NAME, HttpSpanNameExtractor.create(httpAttributes)) openTelemetry, INSTRUMENTATION_NAME, HttpSpanNameExtractor.create(httpAttributes))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributes)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributes))
.addAttributesExtractor(netAttributes) .addAttributesExtractor(NetServerAttributesExtractor.create(netAttributes))
.addAttributesExtractor(httpAttributes) .addAttributesExtractor(httpAttributes)
.addAttributesExtractors(additionalExtractors) .addAttributesExtractors(additionalExtractors)
.addRequestMetrics(HttpServerMetrics.get()) .addRequestMetrics(HttpServerMetrics.get())

View File

@ -5,14 +5,12 @@
package io.opentelemetry.instrumentation.ratpack.internal; package io.opentelemetry.instrumentation.ratpack.internal;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import ratpack.http.Request; import ratpack.http.Request;
import ratpack.http.Response;
public final class RatpackNetAttributesExtractor public final class RatpackNetAttributesGetter implements NetServerAttributesGetter<Request> {
extends NetServerAttributesExtractor<Request, Response> {
@Override @Override
@Nullable @Nullable
public String transport(Request request) { public String transport(Request request) {

View File

@ -5,13 +5,12 @@
package io.opentelemetry.instrumentation.restlet.v1_0; package io.opentelemetry.instrumentation.restlet.v1_0;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.restlet.data.Request; import org.restlet.data.Request;
import org.restlet.data.Response;
final class RestletNetAttributesExtractor extends NetServerAttributesExtractor<Request, Response> { final class RestletNetAttributesGetter implements NetServerAttributesGetter<Request> {
@Override @Override
public String transport(Request request) { public String transport(Request request) {
return SemanticAttributes.NetTransportValues.IP_TCP; return SemanticAttributes.NetTransportValues.IP_TCP;

View File

@ -68,7 +68,7 @@ public final class RestletTracingBuilder {
SpanStatusExtractor<Request, Response> spanStatusExtractor = SpanStatusExtractor<Request, Response> spanStatusExtractor =
HttpSpanStatusExtractor.create(httpAttributesExtractor); HttpSpanStatusExtractor.create(httpAttributesExtractor);
NetServerAttributesExtractor<Request, Response> netAttributesExtractor = NetServerAttributesExtractor<Request, Response> netAttributesExtractor =
new RestletNetAttributesExtractor(); NetServerAttributesExtractor.create(new RestletNetAttributesGetter());
Instrumenter<Request, Response> instrumenter = Instrumenter<Request, Response> instrumenter =
Instrumenter.<Request, Response>builder( Instrumenter.<Request, Response>builder(

View File

@ -43,7 +43,7 @@ public class RestletInstrumenterFactory {
SpanStatusExtractor<Request, Response> spanStatusExtractor = SpanStatusExtractor<Request, Response> spanStatusExtractor =
HttpSpanStatusExtractor.create(httpAttributesExtractor); HttpSpanStatusExtractor.create(httpAttributesExtractor);
NetServerAttributesExtractor<Request, Response> netAttributesExtractor = NetServerAttributesExtractor<Request, Response> netAttributesExtractor =
new RestletNetAttributesExtractor(); NetServerAttributesExtractor.create(new RestletNetAttributesGetter());
return Instrumenter.<Request, Response>builder( return Instrumenter.<Request, Response>builder(
openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor) openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor)

View File

@ -5,13 +5,12 @@
package io.opentelemetry.instrumentation.restlet.v2_0.internal; package io.opentelemetry.instrumentation.restlet.v2_0.internal;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.restlet.Request; import org.restlet.Request;
import org.restlet.Response;
final class RestletNetAttributesExtractor extends NetServerAttributesExtractor<Request, Response> { final class RestletNetAttributesGetter implements NetServerAttributesGetter<Request> {
@Override @Override
public String transport(Request request) { public String transport(Request request) {
return SemanticAttributes.NetTransportValues.IP_TCP; return SemanticAttributes.NetTransportValues.IP_TCP;

View File

@ -16,6 +16,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.instrumentation.api.server.ServerSpanNaming;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -47,8 +48,8 @@ public final class ServletInstrumenterBuilder<REQUEST, RESPONSE> {
SpanStatusExtractor<ServletRequestContext<REQUEST>, ServletResponseContext<RESPONSE>> SpanStatusExtractor<ServletRequestContext<REQUEST>, ServletResponseContext<RESPONSE>>
spanStatusExtractor = HttpSpanStatusExtractor.create(httpAttributesExtractor); spanStatusExtractor = HttpSpanStatusExtractor.create(httpAttributesExtractor);
ServletNetAttributesExtractor<REQUEST, RESPONSE> netAttributesExtractor = ServletNetAttributesGetter<REQUEST, RESPONSE> netAttributesGetter =
new ServletNetAttributesExtractor<>(accessor); new ServletNetAttributesGetter<>(accessor);
ServletErrorCauseExtractor<REQUEST, RESPONSE> errorCauseExtractor = ServletErrorCauseExtractor<REQUEST, RESPONSE> errorCauseExtractor =
new ServletErrorCauseExtractor<>(accessor); new ServletErrorCauseExtractor<>(accessor);
AttributesExtractor<ServletRequestContext<REQUEST>, ServletResponseContext<RESPONSE>> AttributesExtractor<ServletRequestContext<REQUEST>, ServletResponseContext<RESPONSE>>
@ -60,7 +61,7 @@ public final class ServletInstrumenterBuilder<REQUEST, RESPONSE> {
.setSpanStatusExtractor(spanStatusExtractor) .setSpanStatusExtractor(spanStatusExtractor)
.setErrorCauseExtractor(errorCauseExtractor) .setErrorCauseExtractor(errorCauseExtractor)
.addAttributesExtractor(httpAttributesExtractor) .addAttributesExtractor(httpAttributesExtractor)
.addAttributesExtractor(netAttributesExtractor) .addAttributesExtractor(NetServerAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(additionalAttributesExtractor) .addAttributesExtractor(additionalAttributesExtractor)
.addRequestMetrics(HttpServerMetrics.get()) .addRequestMetrics(HttpServerMetrics.get())
.addContextCustomizer(ServerSpanNaming.get()); .addContextCustomizer(ServerSpanNaming.get());

View File

@ -5,16 +5,15 @@
package io.opentelemetry.javaagent.instrumentation.servlet; package io.opentelemetry.javaagent.instrumentation.servlet;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class ServletNetAttributesExtractor<REQUEST, RESPONSE> public class ServletNetAttributesGetter<REQUEST, RESPONSE>
extends NetServerAttributesExtractor< implements NetServerAttributesGetter<ServletRequestContext<REQUEST>> {
ServletRequestContext<REQUEST>, ServletResponseContext<RESPONSE>> {
private final ServletAccessor<REQUEST, RESPONSE> accessor; private final ServletAccessor<REQUEST, RESPONSE> accessor;
public ServletNetAttributesExtractor(ServletAccessor<REQUEST, RESPONSE> accessor) { public ServletNetAttributesGetter(ServletAccessor<REQUEST, RESPONSE> accessor) {
this.accessor = accessor; this.accessor = accessor;
} }

View File

@ -5,14 +5,12 @@
package io.opentelemetry.instrumentation.spring.web; package io.opentelemetry.instrumentation.spring.web;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.springframework.http.HttpRequest; import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpResponse;
final class SpringWebNetAttributesExtractor final class SpringWebNetAttributesGetter implements NetServerAttributesGetter<HttpRequest> {
extends NetServerAttributesExtractor<HttpRequest, ClientHttpResponse> {
@Override @Override
public String transport(HttpRequest httpRequest) { public String transport(HttpRequest httpRequest) {
return SemanticAttributes.NetTransportValues.IP_TCP; return SemanticAttributes.NetTransportValues.IP_TCP;

View File

@ -13,6 +13,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeader
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.http.HttpRequest; import org.springframework.http.HttpRequest;
@ -60,7 +61,7 @@ public final class SpringWebTracingBuilder {
public SpringWebTracing build() { public SpringWebTracing build() {
SpringWebHttpAttributesExtractor httpAttributesExtractor = SpringWebHttpAttributesExtractor httpAttributesExtractor =
new SpringWebHttpAttributesExtractor(capturedHttpHeaders); new SpringWebHttpAttributesExtractor(capturedHttpHeaders);
SpringWebNetAttributesExtractor netAttributesExtractor = new SpringWebNetAttributesExtractor(); SpringWebNetAttributesGetter netAttributesGetter = new SpringWebNetAttributesGetter();
Instrumenter<HttpRequest, ClientHttpResponse> instrumenter = Instrumenter<HttpRequest, ClientHttpResponse> instrumenter =
Instrumenter.<HttpRequest, ClientHttpResponse>builder( Instrumenter.<HttpRequest, ClientHttpResponse>builder(
@ -69,7 +70,7 @@ public final class SpringWebTracingBuilder {
HttpSpanNameExtractor.create(httpAttributesExtractor)) HttpSpanNameExtractor.create(httpAttributesExtractor))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor))
.addAttributesExtractor(httpAttributesExtractor) .addAttributesExtractor(httpAttributesExtractor)
.addAttributesExtractor(netAttributesExtractor) .addAttributesExtractor(NetServerAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractors(additionalExtractors) .addAttributesExtractors(additionalExtractors)
.addRequestMetrics(HttpClientMetrics.get()) .addRequestMetrics(HttpClientMetrics.get())
.newClientInstrumenter(HttpRequestSetter.INSTANCE); .newClientInstrumenter(HttpRequestSetter.INSTANCE);

View File

@ -5,14 +5,13 @@
package io.opentelemetry.instrumentation.spring.webmvc; package io.opentelemetry.instrumentation.spring.webmvc;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
final class SpringWebMvcNetAttributesExtractor final class SpringWebMvcNetAttributesGetter
extends NetServerAttributesExtractor<HttpServletRequest, HttpServletResponse> { implements NetServerAttributesGetter<HttpServletRequest> {
@Override @Override
public String transport(HttpServletRequest request) { public String transport(HttpServletRequest request) {
return SemanticAttributes.NetTransportValues.IP_TCP; return SemanticAttributes.NetTransportValues.IP_TCP;

View File

@ -13,6 +13,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeader
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.instrumentation.api.server.ServerSpanNaming;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -71,7 +72,8 @@ public final class SpringWebMvcTracingBuilder {
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor)) .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor))
.addAttributesExtractor(httpAttributesExtractor) .addAttributesExtractor(httpAttributesExtractor)
.addAttributesExtractor(new StatusCodeExtractor()) .addAttributesExtractor(new StatusCodeExtractor())
.addAttributesExtractor(new SpringWebMvcNetAttributesExtractor()) .addAttributesExtractor(
NetServerAttributesExtractor.create(new SpringWebMvcNetAttributesGetter()))
.addAttributesExtractors(additionalExtractors) .addAttributesExtractors(additionalExtractors)
.addRequestMetrics(HttpServerMetrics.get()) .addRequestMetrics(HttpServerMetrics.get())
.addContextCustomizer(ServerSpanNaming.get()) .addContextCustomizer(ServerSpanNaming.get())

View File

@ -37,7 +37,7 @@ public final class TomcatInstrumenterFactory {
SpanStatusExtractor<Request, Response> spanStatusExtractor = SpanStatusExtractor<Request, Response> spanStatusExtractor =
HttpSpanStatusExtractor.create(httpAttributesExtractor); HttpSpanStatusExtractor.create(httpAttributesExtractor);
NetServerAttributesExtractor<Request, Response> netAttributesExtractor = NetServerAttributesExtractor<Request, Response> netAttributesExtractor =
new TomcatNetAttributesExtractor(); NetServerAttributesExtractor.create(new TomcatNetAttributesGetter());
AttributesExtractor<Request, Response> additionalAttributeExtractor = AttributesExtractor<Request, Response> additionalAttributeExtractor =
new TomcatAdditionalAttributesExtractor<>(accessor, servletEntityProvider); new TomcatAdditionalAttributesExtractor<>(accessor, servletEntityProvider);

View File

@ -5,14 +5,13 @@
package io.opentelemetry.javaagent.instrumentation.tomcat.common; package io.opentelemetry.javaagent.instrumentation.tomcat.common;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.coyote.ActionCode; import org.apache.coyote.ActionCode;
import org.apache.coyote.Request; import org.apache.coyote.Request;
import org.apache.coyote.Response;
public class TomcatNetAttributesExtractor extends NetServerAttributesExtractor<Request, Response> { public class TomcatNetAttributesGetter implements NetServerAttributesGetter<Request> {
@Override @Override
@Nullable @Nullable

View File

@ -5,14 +5,14 @@
package io.opentelemetry.javaagent.instrumentation.undertow; package io.opentelemetry.javaagent.instrumentation.undertow;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.undertow.server.HttpServerExchange; import io.undertow.server.HttpServerExchange;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class UndertowNetAttributesExtractor public class UndertowNetAttributesGetter
extends InetSocketAddressNetServerAttributesExtractor<HttpServerExchange, HttpServerExchange> { extends InetSocketAddressNetServerAttributesGetter<HttpServerExchange> {
@Override @Override
@Nullable @Nullable

View File

@ -32,7 +32,7 @@ public final class UndertowSingletons {
SpanStatusExtractor<HttpServerExchange, HttpServerExchange> spanStatusExtractor = SpanStatusExtractor<HttpServerExchange, HttpServerExchange> spanStatusExtractor =
HttpSpanStatusExtractor.create(httpAttributesExtractor); HttpSpanStatusExtractor.create(httpAttributesExtractor);
NetServerAttributesExtractor<HttpServerExchange, HttpServerExchange> netAttributesExtractor = NetServerAttributesExtractor<HttpServerExchange, HttpServerExchange> netAttributesExtractor =
new UndertowNetAttributesExtractor(); NetServerAttributesExtractor.create(new UndertowNetAttributesGetter());
INSTRUMENTER = INSTRUMENTER =
Instrumenter.<HttpServerExchange, HttpServerExchange>builder( Instrumenter.<HttpServerExchange, HttpServerExchange>builder(