Skip to content

Commit

Permalink
fix tests, part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Oct 16, 2023
1 parent 7b8a70b commit e978372
Show file tree
Hide file tree
Showing 32 changed files with 89 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public static <REQUEST, RESPONSE> NetworkAttributesExtractor<REQUEST, RESPONSE>
AddressAndPortExtractor.noop(),
AddressAndPortExtractor.noop(),
/* captureLocalSocketAttributes= */ true,
/* captureOldPeerDomainAttribute= */ false,
// capture the old net.sock.peer.name attr for backwards compatibility
/* captureOldPeerDomainAttribute= */ true,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

package io.opentelemetry.instrumentation.apachedubbo.v2_7;

import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
import org.apache.dubbo.rpc.Result;

final class DubboNetworkServerAttributesGetter
implements ServerAttributesGetter<DubboRequest, Result>,
ClientAttributesGetter<DubboRequest, Result> {
NetworkAttributesGetter<DubboRequest, Result> {

@Nullable
@Override
Expand All @@ -29,14 +29,14 @@ public Integer getServerPort(DubboRequest request) {

@Nullable
@Override
public InetSocketAddress getServerInetSocketAddress(
public InetSocketAddress getNetworkLocalInetSocketAddress(
DubboRequest request, @Nullable Result result) {
return request.localAddress();
}

@Override
@Nullable
public InetSocketAddress getClientInetSocketAddress(
public InetSocketAddress getNetworkPeerInetSocketAddress(
DubboRequest request, @Nullable Result result) {
return request.remoteAddress();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcServerAttributesExtractor;
Expand Down Expand Up @@ -72,14 +72,15 @@ public DubboTelemetry build() {
.addAttributesExtractor(RpcServerAttributesExtractor.create(rpcAttributesGetter))
.addAttributesExtractor(
ServerAttributesExtractor.createForServerSide(netServerAttributesGetter))
.addAttributesExtractor(ClientAttributesExtractor.create(netServerAttributesGetter))
.addAttributesExtractor(NetworkAttributesExtractor.create(netServerAttributesGetter))
.addAttributesExtractors(attributesExtractors);

InstrumenterBuilder<DubboRequest, Result> clientInstrumenterBuilder =
Instrumenter.<DubboRequest, Result>builder(
openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor)
.addAttributesExtractor(RpcClientAttributesExtractor.create(rpcAttributesGetter))
.addAttributesExtractor(ServerAttributesExtractor.create(netClientAttributesGetter))
.addAttributesExtractor(NetworkAttributesExtractor.create(netClientAttributesGetter))
.addAttributesExtractors(attributesExtractors);

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

import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
Expand All @@ -16,7 +17,8 @@
* any time.
*/
public final class DubboClientNetworkAttributesGetter
implements ServerAttributesGetter<DubboRequest, Result> {
implements ServerAttributesGetter<DubboRequest, Result>,
NetworkAttributesGetter<DubboRequest, Result> {

@Nullable
@Override
Expand All @@ -31,7 +33,7 @@ public Integer getServerPort(DubboRequest request) {

@Override
@Nullable
public InetSocketAddress getServerInetSocketAddress(
public InetSocketAddress getNetworkPeerInetSocketAddress(
DubboRequest request, @Nullable Result response) {
return request.remoteAddress();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ void restComponentServerAndClientCallWithJettyBackend() {
val -> val.isInstanceOf(String.class)),
satisfies(
SemanticAttributes.NET_SOCK_PEER_PORT,
val -> val.isInstanceOf(Long.class)),
satisfies(
SemanticAttributes.NET_SOCK_HOST_PORT,
val -> val.isInstanceOf(Long.class))),
span ->
span.hasName("GET /api/{module}/unit/{unitId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
package io.opentelemetry.javaagent.instrumentation.cassandra.v3_0;

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

final class CassandraNetworkAttributesGetter
implements ServerAttributesGetter<CassandraRequest, ExecutionInfo> {
implements NetworkAttributesGetter<CassandraRequest, ExecutionInfo> {

@Override
@Nullable
public InetSocketAddress getServerInetSocketAddress(
public InetSocketAddress getNetworkPeerInetSocketAddress(
CassandraRequest request, @Nullable ExecutionInfo executionInfo) {
return executionInfo == null ? null : executionInfo.getQueriedHost().getSocketAddress();
}
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.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.opentelemetry.semconv.SemanticAttributes;

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

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

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

final class CassandraNetworkAttributesGetter
implements ServerAttributesGetter<CassandraRequest, ExecutionInfo> {
implements NetworkAttributesGetter<CassandraRequest, ExecutionInfo> {

@Override
@Nullable
public InetSocketAddress getServerInetSocketAddress(
public InetSocketAddress getNetworkPeerInetSocketAddress(
CassandraRequest request, @Nullable ExecutionInfo executionInfo) {
if (executionInfo == null) {
return null;
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.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.opentelemetry.semconv.SemanticAttributes;

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

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

final class CassandraNetworkAttributesGetter
implements ServerAttributesGetter<CassandraRequest, ExecutionInfo> {
implements NetworkAttributesGetter<CassandraRequest, ExecutionInfo> {

@Override
@Nullable
public InetSocketAddress getServerInetSocketAddress(
public InetSocketAddress getNetworkPeerInetSocketAddress(
CassandraRequest request, @Nullable ExecutionInfo executionInfo) {
if (executionInfo == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.SqlClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor;
import io.opentelemetry.semconv.SemanticAttributes;

/** A builder of {@link CassandraTelemetry}. */
Expand Down Expand Up @@ -59,7 +59,7 @@ protected Instrumenter<CassandraRequest, ExecutionInfo> createInstrumenter(
.setStatementSanitizationEnabled(statementSanitizationEnabled)
.build())
.addAttributesExtractor(
ServerAttributesExtractor.create(new CassandraNetworkAttributesGetter()))
NetworkAttributesExtractor.create(new CassandraNetworkAttributesGetter()))
.addAttributesExtractor(new CassandraAttributesExtractor())
.buildInstrumenter(SpanKindExtractor.alwaysClient());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

package io.opentelemetry.javaagent.instrumentation.couchbase.v2_0;

import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import javax.annotation.Nullable;

public class CouchbaseNetworkAttributesGetter
implements ServerAttributesGetter<CouchbaseRequestInfo, Void> {
implements NetworkAttributesGetter<CouchbaseRequestInfo, Void> {

@Nullable
@Override
public InetSocketAddress getServerInetSocketAddress(
public InetSocketAddress getNetworkPeerInetSocketAddress(
CouchbaseRequestInfo couchbaseRequest, @Nullable Void unused) {
SocketAddress peerAddress = couchbaseRequest.getPeerAddress();
if (peerAddress instanceof InetSocketAddress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig;

public final class CouchbaseSingletons {
Expand All @@ -33,10 +31,7 @@ public final class CouchbaseSingletons {
Instrumenter.<CouchbaseRequestInfo, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor)
.addAttributesExtractor(DbClientAttributesExtractor.create(couchbaseAttributesGetter))
.addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceResolver()))
.addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter))
.addContextCustomizer(
(context, couchbaseRequest, startAttributes) ->
CouchbaseRequestInfo.init(context, couchbaseRequest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v5_0;

import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor;
import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportNetworkAttributesGetter;
import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest;
import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticsearchTransportInstrumenterFactory;
Expand All @@ -18,7 +18,7 @@ public final class Elasticsearch5TransportSingletons {
ElasticsearchTransportInstrumenterFactory.create(
"io.opentelemetry.elasticsearch-transport-5.0",
new Elasticsearch5TransportExperimentalAttributesExtractor(),
ServerAttributesExtractor.create(new ElasticTransportNetworkAttributesGetter()));
NetworkAttributesExtractor.create(new ElasticTransportNetworkAttributesGetter()));

public static Instrumenter<ElasticTransportRequest, ActionResponse> instrumenter() {
return INSTRUMENTER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v5_3;

import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor;
import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportNetworkAttributesGetter;
import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest;
import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticsearchTransportInstrumenterFactory;
Expand All @@ -18,7 +18,7 @@ public final class Elasticsearch53TransportSingletons {
ElasticsearchTransportInstrumenterFactory.create(
"io.opentelemetry.elasticsearch-transport-5.3",
new Elasticsearch53TransportExperimentalAttributesExtractor(),
ServerAttributesExtractor.create(new ElasticTransportNetworkAttributesGetter()));
NetworkAttributesExtractor.create(new ElasticTransportNetworkAttributesGetter()));

public static Instrumenter<ElasticTransportRequest, ActionResponse> instrumenter() {
return INSTRUMENTER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v6_0;

import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
import org.elasticsearch.action.ActionResponse;

public class Elasticsearch6TransportNetworkAttributesGetter
implements ServerAttributesGetter<ElasticTransportRequest, ActionResponse> {
implements NetworkAttributesGetter<ElasticTransportRequest, ActionResponse> {

@Override
@Nullable
public InetSocketAddress getServerInetSocketAddress(
public InetSocketAddress getNetworkPeerInetSocketAddress(
ElasticTransportRequest request, @Nullable ActionResponse response) {
if (response != null && response.remoteAddress() != null) {
return response.remoteAddress().address();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v6_0;

import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor;
import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest;
import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticsearchTransportInstrumenterFactory;
import org.elasticsearch.action.ActionResponse;
Expand All @@ -17,7 +17,7 @@ public final class Elasticsearch6TransportSingletons {
ElasticsearchTransportInstrumenterFactory.create(
"io.opentelemetry.elasticsearch-transport-6.0",
new Elasticsearch6TransportExperimentalAttributesExtractor(),
ServerAttributesExtractor.create(new Elasticsearch6TransportNetworkAttributesGetter()));
NetworkAttributesExtractor.create(new Elasticsearch6TransportNetworkAttributesGetter()));

public static Instrumenter<ElasticTransportRequest, ActionResponse> instrumenter() {
return INSTRUMENTER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,16 @@

package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport;

import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
import javax.annotation.Nullable;
import org.elasticsearch.action.ActionResponse;

public class ElasticTransportNetworkAttributesGetter
implements ServerAttributesGetter<ElasticTransportRequest, ActionResponse> {
implements NetworkAttributesGetter<ElasticTransportRequest, ActionResponse> {

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

@Override
@Nullable
public Integer getServerPort(ElasticTransportRequest request) {
return null;
}

@Override
@Nullable
public String getServerSocketAddress(
public String getNetworkPeerAddress(
ElasticTransportRequest request, @Nullable ActionResponse response) {
if (response != null && response.remoteAddress() != null) {
return response.remoteAddress().getAddress();
Expand All @@ -36,17 +24,7 @@ public String getServerSocketAddress(

@Nullable
@Override
public String getServerSocketDomain(
ElasticTransportRequest request, @Nullable ActionResponse response) {
if (response != null && response.remoteAddress() != null) {
return response.remoteAddress().getHost();
}
return null;
}

@Nullable
@Override
public Integer getServerSocketPort(
public Integer getNetworkPeerPort(
ElasticTransportRequest request, @Nullable ActionResponse response) {
if (response != null && response.remoteAddress() != null) {
return response.remoteAddress().getPort();
Expand Down
Loading

0 comments on commit e978372

Please sign in to comment.