Skip to content

Commit

Permalink
Add peer.service to apache-httpclient-5.0, jedis-1.4, lettuce-4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed May 25, 2021
1 parent 7d429e1 commit 486af3f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.javaagent.instrumentation.api.instrumenter.PeerServiceAttributesExtractor;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.HttpResponse;

Expand All @@ -28,13 +29,16 @@ public final class ApacheHttpClientInstrumenters {
HttpSpanNameExtractor.create(httpAttributesExtractor);
SpanStatusExtractor<? super ClassicHttpRequest, ? super HttpResponse> spanStatusExtractor =
HttpSpanStatusExtractor.create(httpAttributesExtractor);
ApacheHttpClientNetAttributesExtractor netAttributesExtractor =
new ApacheHttpClientNetAttributesExtractor();

INSTRUMENTER =
Instrumenter.<ClassicHttpRequest, HttpResponse>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor)
.setSpanStatusExtractor(spanStatusExtractor)
.addAttributesExtractor(httpAttributesExtractor)
.addAttributesExtractor(new ApacheHttpClientNetAttributesExtractor())
.addAttributesExtractor(netAttributesExtractor)
.addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesExtractor))
.newClientInstrumenter(new HttpHeaderSetter());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ final class ApacheHttpClientNetAttributesExtractor
LoggerFactory.getLogger(ApacheHttpClientNetAttributesExtractor.class);

@Override
protected String transport(ClassicHttpRequest request) {
public String transport(ClassicHttpRequest request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
}

@Override
protected @Nullable String peerName(ClassicHttpRequest request, @Nullable HttpResponse response) {
public @Nullable String peerName(ClassicHttpRequest request, @Nullable HttpResponse response) {
return request.getAuthority().getHostName();
}

@Override
protected Integer peerPort(ClassicHttpRequest request, @Nullable HttpResponse response) {
public Integer peerPort(ClassicHttpRequest request, @Nullable HttpResponse response) {
int port = request.getAuthority().getPort();
if (port != -1) {
return port;
Expand All @@ -51,7 +51,7 @@ protected Integer peerPort(ClassicHttpRequest request, @Nullable HttpResponse re
}

@Override
protected @Nullable String peerIp(ClassicHttpRequest request, @Nullable HttpResponse response) {
public @Nullable String peerIp(ClassicHttpRequest request, @Nullable HttpResponse response) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.DbAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.DbSpanNameExtractor;
import io.opentelemetry.javaagent.instrumentation.api.instrumenter.PeerServiceAttributesExtractor;

public final class JedisInstrumenters {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.javaagent.jedis-1.4";
Expand All @@ -20,12 +21,14 @@ public final class JedisInstrumenters {
static {
DbAttributesExtractor<JedisRequest> attributesExtractor = new JedisDbAttributesExtractor();
SpanNameExtractor<JedisRequest> spanName = DbSpanNameExtractor.create(attributesExtractor);
JedisNetAttributesExtractor netAttributesExtractor = new JedisNetAttributesExtractor();

INSTRUMENTER =
Instrumenter.<JedisRequest, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanName)
.addAttributesExtractor(attributesExtractor)
.addAttributesExtractor(new JedisNetAttributesExtractor())
.addAttributesExtractor(netAttributesExtractor)
.addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesExtractor))
.newInstrumenter(SpanKindExtractor.alwaysClient());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ final class JedisNetAttributesExtractor extends NetAttributesExtractor<JedisRequ

@Override
@Nullable
protected String transport(JedisRequest request) {
public String transport(JedisRequest request) {
return null;
}

@Override
protected String peerName(JedisRequest request, @Nullable Void response) {
public String peerName(JedisRequest request, @Nullable Void response) {
return request.getConnection().getHost();
}

@Override
protected Integer peerPort(JedisRequest request, @Nullable Void response) {
public Integer peerPort(JedisRequest request, @Nullable Void response) {
return request.getConnection().getPort();
}

@Override
@Nullable
protected String peerIp(JedisRequest request, @Nullable Void response) {
public String peerIp(JedisRequest request, @Nullable Void response) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.DbAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.DbSpanNameExtractor;
import io.opentelemetry.javaagent.instrumentation.api.instrumenter.PeerServiceAttributesExtractor;

public final class LettuceInstrumenters {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.javaagent.jedis-1.4";
Expand All @@ -33,10 +34,12 @@ public final class LettuceInstrumenters {
.addAttributesExtractor(attributesExtractor)
.newInstrumenter(SpanKindExtractor.alwaysClient());

LettuceNetAttributesExtractor netAttributesExtractor = new LettuceNetAttributesExtractor();
CONNECT_INSTRUMENTER =
Instrumenter.<RedisURI, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, redisUri -> "CONNECT")
.addAttributesExtractor(new LettuceNetAttributesExtractor())
.addAttributesExtractor(netAttributesExtractor)
.addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesExtractor))
.addAttributesExtractor(new LettuceConnectAttributesExtractor())
.newInstrumenter(SpanKindExtractor.alwaysClient());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ final class LettuceNetAttributesExtractor extends NetAttributesExtractor<RedisUR

@Override
@Nullable
protected String transport(RedisURI redisUri) {
public String transport(RedisURI redisUri) {
return null;
}

@Override
protected String peerName(RedisURI redisUri, @Nullable Void ignored) {
public String peerName(RedisURI redisUri, @Nullable Void ignored) {
return redisUri.getHost();
}

@Override
protected Integer peerPort(RedisURI redisUri, @Nullable Void ignored) {
public Integer peerPort(RedisURI redisUri, @Nullable Void ignored) {
return redisUri.getPort();
}

@Override
@Nullable
protected String peerIp(RedisURI redisUri, @Nullable Void ignored) {
public String peerIp(RedisURI redisUri, @Nullable Void ignored) {
return null;
}
}

0 comments on commit 486af3f

Please sign in to comment.