Skip to content

Commit

Permalink
code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk committed Jan 12, 2022
1 parent f79dc00 commit 0a7ebd5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,23 @@ public final class PeerServiceAttributesExtractor<REQUEST, RESPONSE>
Config.get().getMap("otel.instrumentation.common.peer-service-mapping", emptyMap());

private final Map<String, String> peerServiceMapping;
private final NetClientAttributesGetter<REQUEST, RESPONSE> attributesAdapter;
private final NetClientAttributesGetter<REQUEST, RESPONSE> attributesGetter;

// visible for tests
PeerServiceAttributesExtractor(
Map<String, String> peerServiceMapping,
NetClientAttributesGetter<REQUEST, RESPONSE> netAttributesAdapter) {
NetClientAttributesGetter<REQUEST, RESPONSE> attributesGetter) {
this.peerServiceMapping = peerServiceMapping;
this.attributesAdapter = netAttributesAdapter;
this.attributesGetter = attributesGetter;
}

/**
* Returns a new {@link PeerServiceAttributesExtractor} that will use the passed {@code
* netAttributesExtractor} instance to determine the value of the {@code peer.service} attribute.
*/
public static <REQUEST, RESPONSE> PeerServiceAttributesExtractor<REQUEST, RESPONSE> create(
NetClientAttributesGetter<REQUEST, RESPONSE> netAttributesAdapter) {
return new PeerServiceAttributesExtractor<>(
JAVAAGENT_PEER_SERVICE_MAPPING, netAttributesAdapter);
NetClientAttributesGetter<REQUEST, RESPONSE> attributesGetter) {
return new PeerServiceAttributesExtractor<>(JAVAAGENT_PEER_SERVICE_MAPPING, attributesGetter);
}

@Override
Expand All @@ -64,10 +63,10 @@ public void onEnd(
return;
}

String peerName = attributesAdapter.peerName(request, response);
String peerName = attributesGetter.peerName(request, response);
String peerService = mapToPeerService(peerName);
if (peerService == null) {
String peerIp = attributesAdapter.peerIp(request, response);
String peerIp = attributesGetter.peerIp(request, response);
peerService = mapToPeerService(peerIp);
}
if (peerService != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
public final class NetClientAttributesExtractor<REQUEST, RESPONSE>
implements AttributesExtractor<REQUEST, RESPONSE> {

private final NetClientAttributesGetter<REQUEST, RESPONSE> adapter;
private final NetClientAttributesGetter<REQUEST, RESPONSE> getter;

public static <REQUEST, RESPONSE> NetClientAttributesExtractor<REQUEST, RESPONSE> create(
NetClientAttributesGetter<REQUEST, RESPONSE> adapter) {
return new NetClientAttributesExtractor<>(adapter);
NetClientAttributesGetter<REQUEST, RESPONSE> getter) {
return new NetClientAttributesExtractor<>(getter);
}

private NetClientAttributesExtractor(NetClientAttributesGetter<REQUEST, RESPONSE> adapter) {
this.adapter = adapter;
private NetClientAttributesExtractor(NetClientAttributesGetter<REQUEST, RESPONSE> getter) {
this.getter = getter;
}

@Override
Expand All @@ -43,17 +43,17 @@ public void onEnd(
@Nullable RESPONSE response,
@Nullable Throwable error) {

set(attributes, SemanticAttributes.NET_TRANSPORT, adapter.transport(request, response));
set(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request, response));

String peerIp = adapter.peerIp(request, response);
String peerName = adapter.peerName(request, response);
String peerIp = getter.peerIp(request, response);
String peerName = getter.peerName(request, response);

if (peerName != null && !peerName.equals(peerIp)) {
set(attributes, SemanticAttributes.NET_PEER_NAME, peerName);
}
set(attributes, SemanticAttributes.NET_PEER_IP, peerIp);

Integer peerPort = adapter.peerPort(request, response);
Integer peerPort = getter.peerPort(request, response);
if (peerPort != null && peerPort > 0) {
set(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ public final class ApacheHttpClientSingletons {
HttpSpanStatusExtractor.create(httpAttributesExtractor);
ApacheHttpClientNetAttributesGetter netAttributesAdapter =
new ApacheHttpClientNetAttributesGetter();
NetClientAttributesExtractor<HttpMethod, HttpMethod> netAttributesExtractor =
NetClientAttributesExtractor.create(netAttributesAdapter);
INSTRUMENTER =
Instrumenter.<HttpMethod, HttpMethod>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor)
.setSpanStatusExtractor(spanStatusExtractor)
.addAttributesExtractor(httpAttributesExtractor)
.addAttributesExtractor(netAttributesExtractor)
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesAdapter))
.addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesAdapter))
.addRequestMetrics(HttpClientMetrics.get())
.newClientInstrumenter(HttpHeaderSetter.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public final class LettuceSingletons {
.addAttributesExtractor(attributesExtractor)
.newInstrumenter(SpanKindExtractor.alwaysClient());

LettuceConnectNetAttributesGetter netAttributesGetter = new LettuceConnectNetAttributesGetter();
NetClientAttributesExtractor<RedisURI, Void> netClientAttributesExtractor =
NetClientAttributesExtractor.create(new LettuceConnectNetAttributesGetter());
NetClientAttributesExtractor.create(netAttributesGetter);
CONNECT_INSTRUMENTER =
Instrumenter.<RedisURI, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, redisUri -> "CONNECT")
.addAttributesExtractor(netClientAttributesExtractor)
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(new LettuceConnectNetAttributesGetter()))
.addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(new LettuceConnectAttributesExtractor())
.newInstrumenter(SpanKindExtractor.alwaysClient());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.db.RedisCommandSanitizer;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes.DbSystemValues;
import java.net.InetSocketAddress;
Expand All @@ -34,8 +35,9 @@

final class OpenTelemetryTracing implements Tracing {

private static final LettuceNetAttributesGetter netAttributesExtractor =
new LettuceNetAttributesGetter();
private static final NetClientAttributesExtractor<OpenTelemetryEndpoint, Void>
netAttributesExtractor =
NetClientAttributesExtractor.create(new LettuceNetAttributesGetter());
private final TracerProvider tracerProvider;

OpenTelemetryTracing(io.opentelemetry.api.trace.Tracer tracer) {
Expand Down

0 comments on commit 0a7ebd5

Please sign in to comment.