Deprecate `NetServerAttributesExtractor` (#9156)

This commit is contained in:
Mateusz Rzeszutek 2023-08-11 15:04:52 +02:00 committed by GitHub
parent 16f4281d08
commit 42f07eedd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 419 additions and 73 deletions

View File

@ -10,7 +10,6 @@ import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorU
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
@ -52,7 +51,9 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
@Deprecated
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
REQUEST, RESPONSE>
netAttributesGetter) {
return builder(httpAttributesGetter, netAttributesGetter).build();
}
@ -76,7 +77,9 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
@Deprecated
public static <REQUEST, RESPONSE> HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> builder(
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
REQUEST, RESPONSE>
netAttributesGetter) {
return new HttpServerAttributesExtractorBuilder<>(httpAttributesGetter, netAttributesGetter);
}

View File

@ -10,7 +10,6 @@ import static java.util.Collections.emptyList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
@ -28,7 +27,12 @@ import java.util.function.Function;
public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> {
final HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter;
final NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter;
@SuppressWarnings("deprecation") // using the net extractor for the old->stable semconv story
final io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
REQUEST, RESPONSE>
netAttributesGetter;
final HttpAddressPortExtractor<REQUEST> addressPortExtractor;
List<String> capturedRequestHeaders = emptyList();
List<String> capturedResponseHeaders = emptyList();
@ -37,7 +41,10 @@ public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> {
HttpServerAttributesExtractorBuilder(
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
@SuppressWarnings("deprecation") // using the net extractor for the old->stable semconv story
io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
REQUEST, RESPONSE>
netAttributesGetter) {
this.httpAttributesGetter = httpAttributesGetter;
this.netAttributesGetter = netAttributesGetter;
addressPortExtractor = new HttpAddressPortExtractor<>(httpAttributesGetter);

View File

@ -5,7 +5,6 @@
package io.opentelemetry.instrumentation.api.instrumenter.http;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
@ -19,10 +18,14 @@ import javax.annotation.Nullable;
* library/framework. It will be used by the {@link HttpServerAttributesExtractor} to obtain the
* various HTTP server attributes in a type-generic way.
*/
@SuppressWarnings(
"deprecation") // implementing the NetServerAttributesGetter for the old->stable semconv story;
// will be removed in 2.0
public interface HttpServerAttributesGetter<REQUEST, RESPONSE>
extends HttpCommonAttributesGetter<REQUEST, RESPONSE>,
UrlAttributesGetter<REQUEST>,
NetServerAttributesGetter<REQUEST, RESPONSE>,
io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
REQUEST, RESPONSE>,
NetworkAttributesGetter<REQUEST, RESPONSE>,
ServerAttributesGetter<REQUEST, RESPONSE>,
ClientAttributesGetter<REQUEST, RESPONSE> {

View File

@ -21,7 +21,11 @@ import javax.annotation.Nullable;
* 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
* attributes</a>.
*
* @deprecated Make sure that your instrumentation uses the extractors from the {@code ...network}
* package instead. This class will be removed in the 2.0 release.
*/
@Deprecated
public final class NetServerAttributesExtractor<REQUEST, RESPONSE>
implements AttributesExtractor<REQUEST, RESPONSE> {

View File

@ -19,7 +19,11 @@ import javax.annotation.Nullable;
* <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.
*
* @deprecated Make sure that your instrumentation implements the getters from the {@code
* ...network} package instead. This class will be removed in the 2.0 release.
*/
@Deprecated
public interface NetServerAttributesGetter<REQUEST, RESPONSE>
extends NetworkAttributesGetter<REQUEST, RESPONSE>,
ServerAttributesGetter<REQUEST, RESPONSE>,

View File

@ -8,7 +8,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.net.internal;
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPort;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
@ -17,14 +16,19 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
@SuppressWarnings("deprecation") // this class will be removed in the 2.0 version
public final class InternalNetServerAttributesExtractor<REQUEST, RESPONSE> {
private final NetServerAttributesGetter<REQUEST, RESPONSE> getter;
private final io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
REQUEST, RESPONSE>
getter;
private final FallbackAddressPortExtractor<REQUEST> fallbackAddressPortExtractor;
private final boolean emitOldHttpAttributes;
public InternalNetServerAttributesExtractor(
NetServerAttributesGetter<REQUEST, RESPONSE> getter,
io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
REQUEST, RESPONSE>
getter,
FallbackAddressPortExtractor<REQUEST> fallbackAddressPortExtractor,
boolean emitOldHttpAttributes) {
this.getter = getter;

View File

@ -10,6 +10,7 @@ import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import javax.annotation.Nullable;
/**
@ -32,13 +33,12 @@ public final class ClientAttributesExtractor<REQUEST, RESPONSE>
private final InternalClientAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
ClientAttributesExtractor(ClientAttributesGetter<REQUEST, RESPONSE> getter) {
// the ClientAttributesExtractor will always emit new semconv
internalExtractor =
new InternalClientAttributesExtractor<>(
getter,
FallbackAddressPortExtractor.noop(),
/* emitStableUrlAttributes= */ true,
/* emitOldHttpAttributes= */ false);
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv());
}
@Override

View File

@ -10,6 +10,7 @@ import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import javax.annotation.Nullable;
/**
@ -32,13 +33,12 @@ public final class NetworkAttributesExtractor<REQUEST, RESPONSE>
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
NetworkAttributesExtractor(NetworkAttributesGetter<REQUEST, RESPONSE> getter) {
// the NetworkAttributesExtractor will always emit new semconv
internalExtractor =
new InternalNetworkAttributesExtractor<>(
getter,
NetworkTransportFilter.alwaysTrue(),
/* emitStableUrlAttributes= */ true,
/* emitOldHttpAttributes= */ false);
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv());
}
@Override

View File

@ -10,6 +10,7 @@ import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import javax.annotation.Nullable;
/**
@ -26,22 +27,38 @@ public final class ServerAttributesExtractor<REQUEST, RESPONSE>
*/
public static <REQUEST, RESPONSE> ServerAttributesExtractor<REQUEST, RESPONSE> create(
ServerAttributesGetter<REQUEST, RESPONSE> getter) {
return new ServerAttributesExtractor<>(getter);
return new ServerAttributesExtractor<>(getter, InternalServerAttributesExtractor.Mode.PEER);
}
/**
* Returns a new {@link ServerAttributesExtractor} that will use the passed {@link
* ServerAttributesGetter}.
*
* @deprecated This method will be removed in the 2.0 release. It was only introduced to ease the
* transition from using the old {@code NetServerAttributesGetter} to the new {@code
* ...network} attribute getter classes.
*/
@Deprecated
public static <REQUEST, RESPONSE>
ServerAttributesExtractor<REQUEST, RESPONSE> createForServerSide(
ServerAttributesGetter<REQUEST, RESPONSE> getter) {
return new ServerAttributesExtractor<>(getter, InternalServerAttributesExtractor.Mode.HOST);
}
private final InternalServerAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
ServerAttributesExtractor(ServerAttributesGetter<REQUEST, RESPONSE> getter) {
ServerAttributesExtractor(
ServerAttributesGetter<REQUEST, RESPONSE> getter,
InternalServerAttributesExtractor.Mode mode) {
// the ServerAttributesExtractor will always emit new semconv
internalExtractor =
new InternalServerAttributesExtractor<>(
getter,
(port, request) -> true,
FallbackAddressPortExtractor.noop(),
/* emitStableUrlAttributes= */ true,
/* emitOldHttpAttributes= */ false,
// this param does not matter when old semconv is off
InternalServerAttributesExtractor.Mode.HOST,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv(),
mode,
/* captureServerSocketAttributes= */ true);
}

View File

@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
@SuppressWarnings("deprecation") // testing deprecated class
@ExtendWith(MockitoExtension.class)
class InetSocketAddressNetServerAttributesGetterTest {

View File

@ -21,6 +21,7 @@ import javax.annotation.Nullable;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@SuppressWarnings("deprecation") // testing deprecated class
class NetServerAttributesExtractorTest {
static class TestNetServerAttributesGetter

View File

@ -0,0 +1,91 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.api.instrumenter.network;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static java.util.Collections.emptyMap;
import static org.assertj.core.api.Assertions.entry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
class ClientAttributesExtractorOldSemconvTest {
static class TestClientAttributesGetter
implements ClientAttributesGetter<Map<String, String>, Void> {
@Nullable
@Override
public String getClientAddress(Map<String, String> request) {
return request.get("address");
}
@Nullable
@Override
public Integer getClientPort(Map<String, String> request) {
String value = request.get("port");
return value == null ? null : Integer.parseInt(value);
}
@Nullable
@Override
public String getClientSocketAddress(Map<String, String> request, @Nullable Void response) {
return request.get("socketAddress");
}
@Nullable
@Override
public Integer getClientSocketPort(Map<String, String> request, @Nullable Void response) {
String value = request.get("socketPort");
return value == null ? null : Integer.parseInt(value);
}
}
@Test
void allAttributes() {
Map<String, String> request = new HashMap<>();
request.put("address", "opentelemetry.io");
request.put("port", "80");
request.put("socketAddress", "1.2.3.4");
request.put("socketPort", "8080");
AttributesExtractor<Map<String, String>, Void> extractor =
ClientAttributesExtractor.create(new TestClientAttributesGetter());
AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build())
.containsOnly(entry(SemanticAttributes.HTTP_CLIENT_IP, "opentelemetry.io"));
AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null);
assertThat(endAttributes.build())
.containsOnly(
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"),
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 8080L));
}
@Test
void noAttributes() {
AttributesExtractor<Map<String, String>, Void> extractor =
ClientAttributesExtractor.create(new TestClientAttributesGetter());
AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), emptyMap());
assertThat(startAttributes.build()).isEmpty();
AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null);
assertThat(endAttributes.build()).isEmpty();
}
}

View File

@ -0,0 +1,89 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.api.instrumenter.network;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static java.util.Collections.emptyMap;
import static org.assertj.core.api.Assertions.entry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
class NetworkAttributesExtractorOldSemconvTest {
static class TestNetworkAttributesGetter
implements NetworkAttributesGetter<Map<String, String>, Void> {
@Nullable
@Override
public String getNetworkTransport(Map<String, String> request, @Nullable Void response) {
return request.get("transport");
}
@Nullable
@Override
public String getNetworkType(Map<String, String> request, @Nullable Void response) {
return request.get("type");
}
@Nullable
@Override
public String getNetworkProtocolName(Map<String, String> request, @Nullable Void response) {
return request.get("protocolName");
}
@Nullable
@Override
public String getNetworkProtocolVersion(Map<String, String> request, @Nullable Void response) {
return request.get("protocolVersion");
}
}
@Test
void allAttributes() {
Map<String, String> request = new HashMap<>();
request.put("transport", "TcP");
request.put("type", "IPv4");
request.put("protocolName", "Http");
request.put("protocolVersion", "1.1");
AttributesExtractor<Map<String, String>, Void> extractor =
NetworkAttributesExtractor.create(new TestNetworkAttributesGetter());
AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()).isEmpty();
AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null);
assertThat(endAttributes.build())
.containsOnly(
// the NetworkAttributesExtractor can't emit old net.transport & net.sock.family
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"));
}
@Test
void noAttributes() {
AttributesExtractor<Map<String, String>, Void> extractor =
NetworkAttributesExtractor.create(new TestNetworkAttributesGetter());
AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), emptyMap());
assertThat(startAttributes.build()).isEmpty();
AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null);
assertThat(endAttributes.build()).isEmpty();
}
}

View File

@ -0,0 +1,129 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.api.instrumenter.network;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static java.util.Collections.emptyMap;
import static org.assertj.core.api.Assertions.entry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
class ServerAttributesExtractorOldSemconvTest {
static class TestServerAttributesGetter
implements ServerAttributesGetter<Map<String, String>, Void> {
@Nullable
@Override
public String getServerAddress(Map<String, String> request) {
return request.get("address");
}
@Nullable
@Override
public Integer getServerPort(Map<String, String> request) {
String port = request.get("port");
return port == null ? null : Integer.parseInt(port);
}
@Nullable
@Override
public String getServerSocketDomain(Map<String, String> request, @Nullable Void response) {
return request.get("socketDomain");
}
@Nullable
@Override
public String getServerSocketAddress(Map<String, String> request, @Nullable Void response) {
return request.get("socketAddress");
}
@Nullable
@Override
public Integer getServerSocketPort(Map<String, String> request, @Nullable Void response) {
String port = request.get("socketPort");
return port == null ? null : Integer.parseInt(port);
}
}
@Test
void allAttributes_peer() {
Map<String, String> request = new HashMap<>();
request.put("address", "opentelemetry.io");
request.put("port", "80");
request.put("socketDomain", "proxy.opentelemetry.io");
request.put("socketAddress", "1.2.3.4");
request.put("socketPort", "8080");
AttributesExtractor<Map<String, String>, Void> extractor =
ServerAttributesExtractor.create(new TestServerAttributesGetter());
AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build())
.containsOnly(
entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"),
entry(SemanticAttributes.NET_PEER_PORT, 80L));
AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null);
assertThat(endAttributes.build())
.containsOnly(
entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"),
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"),
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 8080L));
}
@SuppressWarnings("deprecation") // need to test the old semconv too
@Test
void allAttributes_host() {
Map<String, String> request = new HashMap<>();
request.put("address", "opentelemetry.io");
request.put("port", "80");
request.put("socketDomain", "proxy.opentelemetry.io");
request.put("socketAddress", "1.2.3.4");
request.put("socketPort", "8080");
AttributesExtractor<Map<String, String>, Void> extractor =
ServerAttributesExtractor.createForServerSide(new TestServerAttributesGetter());
AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build())
.containsOnly(
entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"),
entry(SemanticAttributes.NET_HOST_PORT, 80L));
AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null);
assertThat(endAttributes.build())
.containsOnly(
entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "1.2.3.4"),
entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L));
}
@Test
void noAttributes() {
AttributesExtractor<Map<String, String>, Void> extractor =
ServerAttributesExtractor.create(new TestServerAttributesGetter());
AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), emptyMap());
assertThat(startAttributes.build()).isEmpty();
AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null);
assertThat(endAttributes.build()).isEmpty();
}
}

View File

@ -20,6 +20,7 @@ import java.util.Map;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
@SuppressWarnings("deprecation") // testing deprecated class
class NetServerAttributesExtractorBothSemconvTest {
static class TestNetServerAttributesGetter

View File

@ -19,6 +19,7 @@ import java.util.Map;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
@SuppressWarnings("deprecation") // testing deprecated class
class NetServerAttributesExtractorStableSemconvTest {
static class TestNetServerAttributesGetter

View File

@ -3,20 +3,17 @@
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.apachedubbo.v2_7.internal;
package io.opentelemetry.instrumentation.apachedubbo.v2_7;
import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
import org.apache.dubbo.rpc.Result;
/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class DubboNetServerAttributesGetter
implements NetServerAttributesGetter<DubboRequest, Result> {
final class DubboNetworkServerAttributesGetter
implements ServerAttributesGetter<DubboRequest, Result>,
ClientAttributesGetter<DubboRequest, Result> {
@Nullable
@Override
@ -30,17 +27,17 @@ public final class DubboNetServerAttributesGetter
return null;
}
@Override
@Nullable
public InetSocketAddress getClientInetSocketAddress(
DubboRequest request, @Nullable Result result) {
return request.remoteAddress();
}
@Nullable
@Override
public InetSocketAddress getServerInetSocketAddress(
DubboRequest request, @Nullable Result result) {
return request.localAddress();
}
@Override
@Nullable
public InetSocketAddress getClientInetSocketAddress(
DubboRequest request, @Nullable Result result) {
return request.remoteAddress();
}
}

View File

@ -8,13 +8,13 @@ package io.opentelemetry.instrumentation.apachedubbo.v2_7;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetClientAttributesGetter;
import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetServerAttributesGetter;
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.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcSpanNameExtractor;
@ -57,18 +57,22 @@ public final class DubboTelemetryBuilder {
/**
* Returns a new {@link DubboTelemetry} with the settings of this {@link DubboTelemetryBuilder}.
*/
@SuppressWarnings("deprecation") // using createForServerSide() for the old->stable semconv story
public DubboTelemetry build() {
DubboRpcAttributesGetter rpcAttributesGetter = DubboRpcAttributesGetter.INSTANCE;
SpanNameExtractor<DubboRequest> spanNameExtractor =
RpcSpanNameExtractor.create(rpcAttributesGetter);
DubboNetClientAttributesGetter netClientAttributesGetter = new DubboNetClientAttributesGetter();
DubboNetworkServerAttributesGetter netServerAttributesGetter =
new DubboNetworkServerAttributesGetter();
InstrumenterBuilder<DubboRequest, Result> serverInstrumenterBuilder =
Instrumenter.<DubboRequest, Result>builder(
openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor)
.addAttributesExtractor(RpcServerAttributesExtractor.create(rpcAttributesGetter))
.addAttributesExtractor(
NetServerAttributesExtractor.create(new DubboNetServerAttributesGetter()))
ServerAttributesExtractor.createForServerSide(netServerAttributesGetter))
.addAttributesExtractor(ClientAttributesExtractor.create(netServerAttributesGetter))
.addAttributesExtractors(attributesExtractors);
InstrumenterBuilder<DubboRequest, Result> clientInstrumenterBuilder =

View File

@ -3,21 +3,18 @@
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.grpc.v1_6.internal;
package io.opentelemetry.instrumentation.grpc.v1_6;
import io.grpc.Status;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.instrumentation.grpc.v1_6.GrpcRequest;
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import javax.annotation.Nullable;
/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class GrpcNetServerAttributesGetter
implements NetServerAttributesGetter<GrpcRequest, Status> {
final class GrpcNetworkServerAttributesGetter
implements ServerAttributesGetter<GrpcRequest, Status>,
ClientAttributesGetter<GrpcRequest, Status> {
@Nullable
@Override
@ -30,6 +27,14 @@ public final class GrpcNetServerAttributesGetter
return grpcRequest.getLogicalPort();
}
@Nullable
@Override
public InetSocketAddress getServerInetSocketAddress(
GrpcRequest grpcRequest, @Nullable Status status) {
// TODO: later version introduces TRANSPORT_ATTR_LOCAL_ADDR, might be a good idea to use it
return null;
}
@Override
@Nullable
public InetSocketAddress getClientInetSocketAddress(
@ -40,12 +45,4 @@ public final class GrpcNetServerAttributesGetter
}
return null;
}
@Nullable
@Override
public InetSocketAddress getServerInetSocketAddress(
GrpcRequest grpcRequest, @Nullable Status status) {
// TODO: later version introduces TRANSPORT_ATTR_LOCAL_ADDR, might be a good idea to use it
return null;
}
}

View File

@ -14,13 +14,13 @@ import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcServerMetrics;
import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetClientAttributesGetter;
import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.ArrayList;
import java.util.Collections;
@ -149,6 +149,7 @@ public final class GrpcTelemetryBuilder {
}
/** Returns a new {@link GrpcTelemetry} with the settings of this {@link GrpcTelemetryBuilder}. */
@SuppressWarnings("deprecation") // using createForServerSide() for the old->stable semconv story
public GrpcTelemetry build() {
SpanNameExtractor<GrpcRequest> originalSpanNameExtractor = new GrpcSpanNameExtractor();
@ -175,6 +176,8 @@ public final class GrpcTelemetryBuilder {
.addAttributesExtractors(additionalExtractors));
GrpcNetClientAttributesGetter netClientAttributesGetter = new GrpcNetClientAttributesGetter();
GrpcNetworkServerAttributesGetter netServerAttributesGetter =
new GrpcNetworkServerAttributesGetter();
GrpcRpcAttributesGetter rpcAttributesGetter = GrpcRpcAttributesGetter.INSTANCE;
clientInstrumenterBuilder
@ -188,7 +191,8 @@ public final class GrpcTelemetryBuilder {
serverInstrumenterBuilder
.addAttributesExtractor(RpcServerAttributesExtractor.create(rpcAttributesGetter))
.addAttributesExtractor(
NetServerAttributesExtractor.create(new GrpcNetServerAttributesGetter()))
ServerAttributesExtractor.createForServerSide(netServerAttributesGetter))
.addAttributesExtractor(ClientAttributesExtractor.create(netServerAttributesGetter))
.addAttributesExtractor(
new GrpcAttributesExtractor(
GrpcRpcAttributesGetter.INSTANCE, capturedServerRequestMetadata))

View File

@ -10,11 +10,6 @@ import javax.annotation.Nullable;
public final class PulsarNetClientAttributesGetter
implements NetClientAttributesGetter<BasePulsarRequest, Void> {
@Nullable
@Override
public String getTransport(BasePulsarRequest request, @Nullable Void unused) {
return null;
}
@Nullable
@Override

View File

@ -12,12 +12,6 @@ public enum VertxSqlClientNetAttributesGetter
implements NetClientAttributesGetter<VertxSqlClientRequest, Void> {
INSTANCE;
@Nullable
@Override
public String getTransport(VertxSqlClientRequest request, @Nullable Void unused) {
return null;
}
@Nullable
@Override
public String getServerAddress(VertxSqlClientRequest request) {