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

Replace (client|server).socket.(address|port) attributes with network.(peer|local).(address|port) #9676

Merged
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 @@ -5,15 +5,14 @@

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

import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor;
import java.util.Locale;

final class ClientAddressAndPortExtractor<REQUEST>
implements FallbackAddressPortExtractor<REQUEST> {
final class ForwardedAddressAndPortExtractor<REQUEST> implements AddressAndPortExtractor<REQUEST> {

private final HttpServerAttributesGetter<REQUEST, ?> getter;

ClientAddressAndPortExtractor(HttpServerAttributesGetter<REQUEST, ?> getter) {
ForwardedAddressAndPortExtractor(HttpServerAttributesGetter<REQUEST, ?> getter) {
this.getter = getter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpCommonAttributesExtractor.firstHeaderValue;
import static java.util.logging.Level.FINE;

import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor;
import java.util.logging.Logger;

final class HttpAddressPortExtractor<REQUEST> implements FallbackAddressPortExtractor<REQUEST> {
final class HostAddressAndPortExtractor<REQUEST> implements AddressAndPortExtractor<REQUEST> {

private static final Logger logger = Logger.getLogger(HttpCommonAttributesGetter.class.getName());

private final HttpCommonAttributesGetter<REQUEST, ?> getter;

HttpAddressPortExtractor(HttpCommonAttributesGetter<REQUEST, ?> getter) {
HostAddressAndPortExtractor(HttpCommonAttributesGetter<REQUEST, ?> getter) {
this.getter = getter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static <REQUEST, RESPONSE> HttpClientAttributesExtractorBuilder<REQUEST,

private final InternalNetClientAttributesExtractor<REQUEST, RESPONSE> internalNetExtractor;
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalNetworkExtractor;
private final InternalServerAttributesExtractor<REQUEST, RESPONSE> internalServerExtractor;
private final InternalServerAttributesExtractor<REQUEST> internalServerExtractor;
private final ToIntFunction<Context> resendCountIncrementer;

HttpClientAttributesExtractor(HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> builder) {
Expand Down Expand Up @@ -133,7 +133,6 @@ public void onEnd(

internalNetExtractor.onEnd(attributes, request, response);
internalNetworkExtractor.onEnd(attributes, request, response);
internalServerExtractor.onEnd(attributes, request, response);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ServerAddressAndPortExtractor;
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import java.util.ArrayList;
Expand All @@ -31,7 +33,7 @@ public final class HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> {
REQUEST, RESPONSE>
netAttributesGetter;

final HttpAddressPortExtractor<REQUEST> addressPortExtractor;
final AddressAndPortExtractor<REQUEST> serverAddressAndPortExtractor;
List<String> capturedRequestHeaders = emptyList();
List<String> capturedResponseHeaders = emptyList();
Set<String> knownMethods = HttpConstants.KNOWN_METHODS;
Expand All @@ -45,7 +47,9 @@ public final class HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> {
netAttributesGetter) {
this.httpAttributesGetter = httpAttributesGetter;
this.netAttributesGetter = netAttributesGetter;
addressPortExtractor = new HttpAddressPortExtractor<>(httpAttributesGetter);
serverAddressAndPortExtractor =
new ServerAddressAndPortExtractor<>(
netAttributesGetter, new HostAddressAndPortExtractor<>(httpAttributesGetter));
}

/**
Expand Down Expand Up @@ -125,25 +129,27 @@ public AttributesExtractor<REQUEST, RESPONSE> build() {

InternalNetClientAttributesExtractor<REQUEST, RESPONSE> buildNetExtractor() {
return new InternalNetClientAttributesExtractor<>(
netAttributesGetter, addressPortExtractor, SemconvStability.emitOldHttpSemconv());
netAttributesGetter, serverAddressAndPortExtractor, SemconvStability.emitOldHttpSemconv());
}

InternalNetworkAttributesExtractor<REQUEST, RESPONSE> buildNetworkExtractor() {
return new InternalNetworkAttributesExtractor<>(
netAttributesGetter,
HttpNetworkTransportFilter.INSTANCE,
AddressAndPortExtractor.noop(),
serverAddressAndPortExtractor,
/* captureLocalSocketAttributes= */ false,
/* captureOldPeerDomainAttribute= */ true,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv());
}

InternalServerAttributesExtractor<REQUEST, RESPONSE> buildServerExtractor() {
InternalServerAttributesExtractor<REQUEST> buildServerExtractor() {
return new InternalServerAttributesExtractor<>(
netAttributesGetter,
new ClientSideServerPortCondition<>(httpAttributesGetter),
addressPortExtractor,
serverAddressAndPortExtractor,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv(),
InternalServerAttributesExtractor.Mode.PEER,
/* captureServerSocketAttributes= */ true);
InternalServerAttributesExtractor.Mode.PEER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public static <REQUEST, RESPONSE> HttpServerAttributesExtractorBuilder<REQUEST,
private final InternalUrlAttributesExtractor<REQUEST> internalUrlExtractor;
private final InternalNetServerAttributesExtractor<REQUEST, RESPONSE> internalNetExtractor;
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalNetworkExtractor;
private final InternalServerAttributesExtractor<REQUEST, RESPONSE> internalServerExtractor;
private final InternalClientAttributesExtractor<REQUEST, RESPONSE> internalClientExtractor;
private final InternalServerAttributesExtractor<REQUEST> internalServerExtractor;
private final InternalClientAttributesExtractor<REQUEST> internalClientExtractor;
private final Function<Context, String> httpRouteGetter;

HttpServerAttributesExtractor(HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> builder) {
Expand Down Expand Up @@ -128,8 +128,6 @@ public void onEnd(
super.onEnd(attributes, context, request, response, error);

internalNetworkExtractor.onEnd(attributes, request, response);
internalServerExtractor.onEnd(attributes, request, response);
internalClientExtractor.onEnd(attributes, request, response);

internalSet(attributes, SemanticAttributes.HTTP_ROUTE, httpRouteGetter.apply(context));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ClientAddressAndPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ServerAddressAndPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.InternalUrlAttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
Expand All @@ -33,7 +36,8 @@ public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> {
REQUEST, RESPONSE>
netAttributesGetter;

final HttpAddressPortExtractor<REQUEST> addressPortExtractor;
final AddressAndPortExtractor<REQUEST> clientAddressPortExtractor;
final AddressAndPortExtractor<REQUEST> serverAddressPortExtractor;
List<String> capturedRequestHeaders = emptyList();
List<String> capturedResponseHeaders = emptyList();
Set<String> knownMethods = HttpConstants.KNOWN_METHODS;
Expand All @@ -47,7 +51,13 @@ public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> {
netAttributesGetter) {
this.httpAttributesGetter = httpAttributesGetter;
this.netAttributesGetter = netAttributesGetter;
addressPortExtractor = new HttpAddressPortExtractor<>(httpAttributesGetter);

clientAddressPortExtractor =
new ClientAddressAndPortExtractor<>(
netAttributesGetter, new ForwardedAddressAndPortExtractor<>(httpAttributesGetter));
serverAddressPortExtractor =
new ServerAddressAndPortExtractor<>(
netAttributesGetter, new HostAddressAndPortExtractor<>(httpAttributesGetter));
}

/**
Expand Down Expand Up @@ -135,32 +145,33 @@ InternalUrlAttributesExtractor<REQUEST> buildUrlExtractor() {

InternalNetServerAttributesExtractor<REQUEST, RESPONSE> buildNetExtractor() {
return new InternalNetServerAttributesExtractor<>(
netAttributesGetter, addressPortExtractor, SemconvStability.emitOldHttpSemconv());
netAttributesGetter, serverAddressPortExtractor, SemconvStability.emitOldHttpSemconv());
}

InternalNetworkAttributesExtractor<REQUEST, RESPONSE> buildNetworkExtractor() {
return new InternalNetworkAttributesExtractor<>(
netAttributesGetter,
HttpNetworkTransportFilter.INSTANCE,
serverAddressPortExtractor,
clientAddressPortExtractor,
/* captureLocalSocketAttributes= */ false,
/* captureOldPeerDomainAttribute= */ false,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv());
}

InternalServerAttributesExtractor<REQUEST, RESPONSE> buildServerExtractor() {
InternalServerAttributesExtractor<REQUEST> buildServerExtractor() {
return new InternalServerAttributesExtractor<>(
netAttributesGetter,
new ServerSideServerPortCondition<>(httpAttributesGetter),
addressPortExtractor,
serverAddressPortExtractor,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv(),
InternalServerAttributesExtractor.Mode.HOST,
/* captureServerSocketAttributes= */ false);
InternalServerAttributesExtractor.Mode.HOST);
}

InternalClientAttributesExtractor<REQUEST, RESPONSE> buildClientExtractor() {
InternalClientAttributesExtractor<REQUEST> buildClientExtractor() {
return new InternalClientAttributesExtractor<>(
netAttributesGetter,
new ClientAddressAndPortExtractor<>(httpAttributesGetter),
clientAddressPortExtractor,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ServerAddressAndPortExtractor;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import javax.annotation.Nullable;

Expand All @@ -33,32 +34,37 @@ public final class NetClientAttributesExtractor<REQUEST, RESPONSE>

private final InternalNetClientAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalNetworkExtractor;
private final InternalServerAttributesExtractor<REQUEST, RESPONSE> internalServerExtractor;
private final InternalServerAttributesExtractor<REQUEST> internalServerExtractor;

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

private NetClientAttributesExtractor(NetClientAttributesGetter<REQUEST, RESPONSE> getter) {
ServerAddressAndPortExtractor<REQUEST> serverAddressAndPortExtractor =
new ServerAddressAndPortExtractor<>(getter, AddressAndPortExtractor.noop());

internalExtractor =
new InternalNetClientAttributesExtractor<>(
getter, FallbackAddressPortExtractor.noop(), SemconvStability.emitOldHttpSemconv());
getter, AddressAndPortExtractor.noop(), SemconvStability.emitOldHttpSemconv());
internalNetworkExtractor =
new InternalNetworkAttributesExtractor<>(
getter,
NetworkTransportFilter.alwaysTrue(),
AddressAndPortExtractor.noop(),
serverAddressAndPortExtractor,
/* captureLocalSocketAttributes= */ false,
/* captureOldPeerDomainAttribute= */ true,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv());
internalServerExtractor =
new InternalServerAttributesExtractor<>(
getter,
(port, request) -> true,
FallbackAddressPortExtractor.noop(),
serverAddressAndPortExtractor,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv(),
InternalServerAttributesExtractor.Mode.PEER,
/* captureServerSocketAttributes= */ true);
InternalServerAttributesExtractor.Mode.PEER);
}

@Override
Expand All @@ -75,6 +81,5 @@ public void onEnd(
@Nullable Throwable error) {
internalExtractor.onEnd(attributes, request, response);
internalNetworkExtractor.onEnd(attributes, request, response);
internalServerExtractor.onEnd(attributes, request, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,23 @@ default String getNetworkType(REQUEST request, @Nullable RESPONSE response) {
return InetSocketAddressUtil.getNetworkType(
getServerInetSocketAddress(request, response), null);
}

@Nullable
@Override
default InetSocketAddress getNetworkPeerInetSocketAddress(
REQUEST request, @Nullable RESPONSE response) {
return getServerInetSocketAddress(request, response);
}

@Nullable
@Override
default String getNetworkPeerAddress(REQUEST request, @Nullable RESPONSE response) {
return getServerSocketAddress(request, response);
}

@Nullable
@Override
default Integer getNetworkPeerPort(REQUEST request, @Nullable RESPONSE response) {
return getServerSocketPort(request, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ClientAddressAndPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.ServerAddressAndPortExtractor;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import javax.annotation.Nullable;

Expand All @@ -36,32 +38,38 @@ public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(

private final InternalNetServerAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalNetworkExtractor;
private final InternalServerAttributesExtractor<REQUEST, RESPONSE> internalServerExtractor;
private final InternalClientAttributesExtractor<REQUEST, RESPONSE> internalClientExtractor;
private final InternalServerAttributesExtractor<REQUEST> internalServerExtractor;
private final InternalClientAttributesExtractor<REQUEST> internalClientExtractor;

private NetServerAttributesExtractor(NetServerAttributesGetter<REQUEST, RESPONSE> getter) {
ServerAddressAndPortExtractor<REQUEST> serverAddressAndPortExtractor =
new ServerAddressAndPortExtractor<>(getter, AddressAndPortExtractor.noop());
ClientAddressAndPortExtractor<REQUEST> clientAddressAndPortExtractor =
new ClientAddressAndPortExtractor<>(getter, AddressAndPortExtractor.noop());

internalExtractor =
new InternalNetServerAttributesExtractor<>(
getter, FallbackAddressPortExtractor.noop(), SemconvStability.emitOldHttpSemconv());
getter, AddressAndPortExtractor.noop(), SemconvStability.emitOldHttpSemconv());
internalNetworkExtractor =
new InternalNetworkAttributesExtractor<>(
getter,
NetworkTransportFilter.alwaysTrue(),
serverAddressAndPortExtractor,
clientAddressAndPortExtractor,
/* captureLocalSocketAttributes= */ true,
/* captureOldPeerDomainAttribute= */ false,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv());
internalServerExtractor =
new InternalServerAttributesExtractor<>(
getter,
(port, request) -> true,
FallbackAddressPortExtractor.noop(),
serverAddressAndPortExtractor,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv(),
InternalServerAttributesExtractor.Mode.HOST,
/* captureServerSocketAttributes= */ true);
InternalServerAttributesExtractor.Mode.HOST);
internalClientExtractor =
new InternalClientAttributesExtractor<>(
getter,
FallbackAddressPortExtractor.noop(),
clientAddressAndPortExtractor,
SemconvStability.emitStableHttpSemconv(),
SemconvStability.emitOldHttpSemconv());
}
Expand All @@ -81,7 +89,5 @@ public void onEnd(
@Nullable RESPONSE response,
@Nullable Throwable error) {
internalNetworkExtractor.onEnd(attributes, request, response);
internalServerExtractor.onEnd(attributes, request, response);
internalClientExtractor.onEnd(attributes, request, response);
}
}
Loading
Loading