Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate NetClientAttributesExtractor #9165

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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.NetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor;
Expand Down Expand Up @@ -52,7 +51,9 @@ public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
@Deprecated
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
HttpClientAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
NetClientAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter<
REQUEST, RESPONSE>
netAttributesGetter) {
return builder(httpAttributesGetter, netAttributesGetter).build();
}

Expand All @@ -76,7 +77,9 @@ public static <REQUEST, RESPONSE> HttpClientAttributesExtractorBuilder<REQUEST,
@Deprecated
public static <REQUEST, RESPONSE> HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> builder(
HttpClientAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
NetClientAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter<
REQUEST, RESPONSE>
netAttributesGetter) {
return new HttpClientAttributesExtractorBuilder<>(httpAttributesGetter, netAttributesGetter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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.NetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor;
Expand All @@ -26,7 +25,12 @@
public final class HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> {

final HttpClientAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter;
final NetClientAttributesGetter<REQUEST, RESPONSE> netAttributesGetter;

@SuppressWarnings("deprecation") // using the net extractor for the old->stable semconv story
final io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter<
REQUEST, RESPONSE>
netAttributesGetter;

final HttpAddressPortExtractor<REQUEST> addressPortExtractor;
List<String> capturedRequestHeaders = emptyList();
List<String> capturedResponseHeaders = emptyList();
Expand All @@ -35,7 +39,10 @@ public final class HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> {

HttpClientAttributesExtractorBuilder(
HttpClientAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
NetClientAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
@SuppressWarnings("deprecation") // using the net extractor for the old->stable semconv story
io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter<
REQUEST, RESPONSE>
netAttributesGetter) {
this.httpAttributesGetter = httpAttributesGetter;
this.netAttributesGetter = netAttributesGetter;
addressPortExtractor = new HttpAddressPortExtractor<>(httpAttributesGetter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.instrumentation.api.instrumenter.http;

import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import javax.annotation.Nullable;
Expand All @@ -17,9 +16,13 @@
* library/framework. It will be used by the {@link HttpClientAttributesExtractor} to obtain the
* various HTTP client attributes in a type-generic way.
*/
@SuppressWarnings(
"deprecation") // implementing the NetClientAttributesGetter for the old->stable semconv story;
// will be removed in 2.0
public interface HttpClientAttributesGetter<REQUEST, RESPONSE>
extends HttpCommonAttributesGetter<REQUEST, RESPONSE>,
NetClientAttributesGetter<REQUEST, RESPONSE>,
io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter<
REQUEST, RESPONSE>,
NetworkAttributesGetter<REQUEST, RESPONSE>,
ServerAttributesGetter<REQUEST, RESPONSE> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
*
* <p>This class delegates to a type-specific {@link NetClientAttributesGetter} for individual
* attribute extraction from request/response objects.
*
* @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 NetClientAttributesExtractor<REQUEST, RESPONSE>
implements AttributesExtractor<REQUEST, RESPONSE> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
* <p>Instrumentation authors will create implementations of this interface for their specific
* library/framework. It will be used by the NetClientAttributesExtractor 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 NetClientAttributesGetter<REQUEST, RESPONSE>
extends NetworkAttributesGetter<REQUEST, RESPONSE>, ServerAttributesGetter<REQUEST, RESPONSE> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.instrumentation.api.instrumenter.net.internal;

import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -42,7 +43,12 @@ public static String getNetworkType(
return null;
}
InetAddress remoteAddress = address.getAddress();
return remoteAddress instanceof Inet6Address ? "ipv6" : "ipv4";
if (remoteAddress instanceof Inet4Address) {
return "ipv6";
} else if (remoteAddress instanceof Inet6Address) {
return "ipv6";
}
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
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;
Expand All @@ -18,14 +17,19 @@
* 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 InternalNetClientAttributesExtractor<REQUEST, RESPONSE> {

private final NetClientAttributesGetter<REQUEST, RESPONSE> getter;
private final io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter<
REQUEST, RESPONSE>
getter;
private final FallbackAddressPortExtractor<REQUEST> fallbackAddressPortExtractor;
private final boolean emitOldHttpAttributes;

public InternalNetClientAttributesExtractor(
NetClientAttributesGetter<REQUEST, RESPONSE> getter,
io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter<
REQUEST, RESPONSE>
getter,
FallbackAddressPortExtractor<REQUEST> fallbackAddressPortExtractor,
boolean emitOldHttpAttributes) {
this.getter = getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@SuppressWarnings("deprecation") // testing deprecated class
@ExtendWith(MockitoExtension.class)
class InetSocketAddressNetClientAttributesGetterTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@SuppressWarnings("deprecation") // testing deprecated class
class NetClientAttributesExtractorTest {

static class TestNetClientAttributesGetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;

@SuppressWarnings("deprecation") // testing deprecated class
class NetClientAttributesExtractorBothSemconvTest {

static class TestNetClientAttributesGetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;

@SuppressWarnings("deprecation") // testing deprecated class
class NetClientAttributesExtractorStableSemconvTest {

static class TestNetClientAttributesGetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboTelemetry;
import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetClientAttributesGetter;
import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboClientNetworkAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import org.apache.dubbo.common.extension.Activate;
Expand All @@ -26,7 +26,7 @@ public OpenTelemetryFilter() {
DubboTelemetry.builder(GlobalOpenTelemetry.get())
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
new DubboNetClientAttributesGetter(),
new DubboClientNetworkAttributesGetter(),
CommonConfig.get().getPeerServiceMapping()))
.build()
.newFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

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.DubboClientNetworkAttributesGetter;
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.network.ClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor;
Expand Down Expand Up @@ -62,7 +61,8 @@ public DubboTelemetry build() {
DubboRpcAttributesGetter rpcAttributesGetter = DubboRpcAttributesGetter.INSTANCE;
SpanNameExtractor<DubboRequest> spanNameExtractor =
RpcSpanNameExtractor.create(rpcAttributesGetter);
DubboNetClientAttributesGetter netClientAttributesGetter = new DubboNetClientAttributesGetter();
DubboClientNetworkAttributesGetter netClientAttributesGetter =
new DubboClientNetworkAttributesGetter();
DubboNetworkServerAttributesGetter netServerAttributesGetter =
new DubboNetworkServerAttributesGetter();

Expand All @@ -79,7 +79,7 @@ public DubboTelemetry build() {
Instrumenter.<DubboRequest, Result>builder(
openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor)
.addAttributesExtractor(RpcClientAttributesExtractor.create(rpcAttributesGetter))
.addAttributesExtractor(NetClientAttributesExtractor.create(netClientAttributesGetter))
.addAttributesExtractor(ServerAttributesExtractor.create(netClientAttributesGetter))
.addAttributesExtractors(attributesExtractors);

if (peerService != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.instrumentation.apachedubbo.v2_7.internal;

import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
import org.apache.dubbo.rpc.Result;
Expand All @@ -15,8 +15,8 @@
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class DubboNetClientAttributesGetter
implements NetClientAttributesGetter<DubboRequest, Result> {
public final class DubboClientNetworkAttributesGetter
implements ServerAttributesGetter<DubboRequest, Result> {

@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,12 @@
package io.opentelemetry.javaagent.instrumentation.cassandra.v3_0;

import com.datastax.driver.core.ExecutionInfo;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;

final class CassandraNetAttributesGetter
implements NetClientAttributesGetter<CassandraRequest, ExecutionInfo> {

@Nullable
@Override
public String getServerAddress(CassandraRequest request) {
return null;
}

@Nullable
@Override
public Integer getServerPort(CassandraRequest request) {
return null;
}
final class CassandraNetworkAttributesGetter
implements ServerAttributesGetter<CassandraRequest, ExecutionInfo> {

@Override
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.SqlClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;

Expand All @@ -37,7 +37,7 @@ public final class CassandraSingletons {
CommonConfig.get().isStatementSanitizationEnabled())
.build())
.addAttributesExtractor(
NetClientAttributesExtractor.create(new CassandraNetAttributesGetter()))
ServerAttributesExtractor.create(new CassandraNetworkAttributesGetter()))
.buildInstrumenter(SpanKindExtractor.alwaysClient());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,13 @@

import com.datastax.oss.driver.api.core.cql.ExecutionInfo;
import com.datastax.oss.driver.api.core.metadata.Node;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import javax.annotation.Nullable;

final class CassandraNetAttributesGetter
implements NetClientAttributesGetter<CassandraRequest, ExecutionInfo> {

@Nullable
@Override
public String getServerAddress(CassandraRequest request) {
return null;
}

@Nullable
@Override
public Integer getServerPort(CassandraRequest request) {
return null;
}
final class CassandraNetworkAttributesGetter
implements ServerAttributesGetter<CassandraRequest, ExecutionInfo> {

@Override
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.SqlClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;

Expand All @@ -36,7 +36,7 @@ public final class CassandraSingletons {
CommonConfig.get().isStatementSanitizationEnabled())
.build())
.addAttributesExtractor(
NetClientAttributesExtractor.create(new CassandraNetAttributesGetter()))
ServerAttributesExtractor.create(new CassandraNetworkAttributesGetter()))
.addAttributesExtractor(new CassandraAttributesExtractor())
.buildInstrumenter(SpanKindExtractor.alwaysClient());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,13 @@

import com.datastax.oss.driver.api.core.cql.ExecutionInfo;
import com.datastax.oss.driver.api.core.metadata.Node;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import javax.annotation.Nullable;

final class CassandraNetAttributesGetter
implements NetClientAttributesGetter<CassandraRequest, ExecutionInfo> {

@Nullable
@Override
public String getServerAddress(CassandraRequest request) {
return null;
}

@Nullable
@Override
public Integer getServerPort(CassandraRequest request) {
return null;
}
final class CassandraNetworkAttributesGetter
implements ServerAttributesGetter<CassandraRequest, ExecutionInfo> {

@Override
@Nullable
Expand Down
Loading
Loading