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

Make network.transport and network.type opt-in #9719

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Make network.transport and network.type opt-in
  • Loading branch information
Mateusz Rzeszutek committed Oct 19, 2023
commit 0951b1158baa181070416f4e52d6564e4455c253
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ InternalNetClientAttributesExtractor<REQUEST, RESPONSE> buildNetExtractor() {
InternalNetworkAttributesExtractor<REQUEST, RESPONSE> buildNetworkExtractor() {
return new InternalNetworkAttributesExtractor<>(
netAttributesGetter,
HttpNetworkTransportFilter.INSTANCE,
AddressAndPortExtractor.noop(),
serverAddressAndPortExtractor,
/* captureNetworkTransportAndType= */ false,
/* captureLocalSocketAttributes= */ false,
/* captureOldPeerDomainAttribute= */ true,
SemconvStability.emitStableHttpSemconv(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ InternalNetServerAttributesExtractor<REQUEST, RESPONSE> buildNetExtractor() {
InternalNetworkAttributesExtractor<REQUEST, RESPONSE> buildNetworkExtractor() {
return new InternalNetworkAttributesExtractor<>(
netAttributesGetter,
HttpNetworkTransportFilter.INSTANCE,
serverAddressPortExtractor,
clientAddressPortExtractor,
/* captureNetworkTransportAndType= */ false,
/* captureLocalSocketAttributes= */ false,
/* captureOldPeerDomainAttribute= */ false,
SemconvStability.emitStableHttpSemconv(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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 Down Expand Up @@ -51,9 +50,9 @@ private NetClientAttributesExtractor(NetClientAttributesGetter<REQUEST, RESPONSE
internalNetworkExtractor =
new InternalNetworkAttributesExtractor<>(
getter,
NetworkTransportFilter.alwaysTrue(),
AddressAndPortExtractor.noop(),
serverAddressAndPortExtractor,
/* captureNetworkTransportAndType= */ true,
/* captureLocalSocketAttributes= */ false,
/* captureOldPeerDomainAttribute= */ true,
SemconvStability.emitStableHttpSemconv(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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 Down Expand Up @@ -53,9 +52,9 @@ private NetServerAttributesExtractor(NetServerAttributesGetter<REQUEST, RESPONSE
internalNetworkExtractor =
new InternalNetworkAttributesExtractor<>(
getter,
NetworkTransportFilter.alwaysTrue(),
serverAddressAndPortExtractor,
clientAddressAndPortExtractor,
/* captureNetworkTransportAndType= */ true,
/* captureLocalSocketAttributes= */ true,
/* captureOldPeerDomainAttribute= */ false,
SemconvStability.emitStableHttpSemconv(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
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.NetworkTransportFilter;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import javax.annotation.Nullable;

Expand All @@ -37,9 +36,9 @@ public static <REQUEST, RESPONSE> NetworkAttributesExtractor<REQUEST, RESPONSE>
internalExtractor =
new InternalNetworkAttributesExtractor<>(
getter,
NetworkTransportFilter.alwaysTrue(),
AddressAndPortExtractor.noop(),
AddressAndPortExtractor.noop(),
/* captureNetworkTransportAndType= */ true,
/* captureLocalSocketAttributes= */ true,
// capture the old net.sock.peer.name attr for backwards compatibility
/* captureOldPeerDomainAttribute= */ true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@
public final class InternalNetworkAttributesExtractor<REQUEST, RESPONSE> {

private final NetworkAttributesGetter<REQUEST, RESPONSE> getter;
private final NetworkTransportFilter networkTransportFilter;
private final AddressAndPortExtractor<REQUEST> logicalLocalAddressAndPortExtractor;
private final AddressAndPortExtractor<REQUEST> logicalPeerAddressAndPortExtractor;
private final boolean captureNetworkTransportAndType;
private final boolean captureLocalSocketAttributes;
private final boolean captureOldPeerDomainAttribute;
private final boolean emitStableUrlAttributes;
private final boolean emitOldHttpAttributes;

public InternalNetworkAttributesExtractor(
NetworkAttributesGetter<REQUEST, RESPONSE> getter,
NetworkTransportFilter networkTransportFilter,
AddressAndPortExtractor<REQUEST> logicalLocalAddressAndPortExtractor,
AddressAndPortExtractor<REQUEST> logicalPeerAddressAndPortExtractor,
boolean captureNetworkTransportAndType,
boolean captureLocalSocketAttributes,
boolean captureOldPeerDomainAttribute,
boolean emitStableUrlAttributes,
boolean emitOldHttpAttributes) {
this.getter = getter;
this.networkTransportFilter = networkTransportFilter;
this.logicalLocalAddressAndPortExtractor = logicalLocalAddressAndPortExtractor;
this.logicalPeerAddressAndPortExtractor = logicalPeerAddressAndPortExtractor;
this.captureNetworkTransportAndType = captureNetworkTransportAndType;
this.captureLocalSocketAttributes = captureLocalSocketAttributes;
this.captureOldPeerDomainAttribute = captureOldPeerDomainAttribute;
this.emitStableUrlAttributes = emitStableUrlAttributes;
Expand All @@ -56,14 +56,13 @@ public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPO

if (emitStableUrlAttributes) {
String transport = lowercase(getter.getNetworkTransport(request, response));
if (networkTransportFilter.shouldAddNetworkTransport(
protocolName, protocolVersion, transport)) {
if (captureNetworkTransportAndType) {
internalSet(attributes, SemanticAttributes.NETWORK_TRANSPORT, transport);
internalSet(
attributes,
SemanticAttributes.NETWORK_TYPE,
lowercase(getter.getNetworkType(request, response)));
}
internalSet(
attributes,
SemanticAttributes.NETWORK_TYPE,
lowercase(getter.getNetworkType(request, response)));
internalSet(attributes, SemanticAttributes.NETWORK_PROTOCOL_NAME, protocolName);
internalSet(attributes, SemanticAttributes.NETWORK_PROTOCOL_VERSION, protocolVersion);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ void normal() {
asList("654", "321")),
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
entry(SemanticAttributes.NETWORK_TRANSPORT, "udp"),
entry(SemanticAttributes.NETWORK_TYPE, "ipv4"),
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ void normal() {
.containsOnly(
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"),
entry(SemanticAttributes.NETWORK_TRANSPORT, "udp"),
entry(SemanticAttributes.NETWORK_TYPE, "ipv4"),
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.entry;
import static org.junit.jupiter.params.provider.Arguments.arguments;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
Expand All @@ -28,13 +27,9 @@
import java.util.List;
import java.util.Map;
import java.util.function.ToIntFunction;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.ValueSource;

Expand Down Expand Up @@ -194,57 +189,12 @@ void normal() {
entry(
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
asList("654", "321")),
entry(SemanticAttributes.NETWORK_TRANSPORT, "udp"),
entry(SemanticAttributes.NETWORK_TYPE, "ipv4"),
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"),
entry(NetworkAttributes.NETWORK_PEER_PORT, 456L));
}

@ParameterizedTest
@ArgumentsSource(NetworkTransportAndProtocolProvider.class)
void skipNetworkTransportIfDefaultForProtocol(
String observedProtocolName,
String observedProtocolVersion,
String observedTransport,
@Nullable String extractedTransport) {
Map<String, String> request = new HashMap<>();
request.put("networkProtocolName", observedProtocolName);
request.put("networkProtocolVersion", observedProtocolVersion);
request.put("networkTransport", observedTransport);

AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());

AttributesBuilder attributes = Attributes.builder();
extractor.onStart(attributes, Context.root(), request);
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);

if (extractedTransport != null) {
assertThat(attributes.build())
.containsEntry(SemanticAttributes.NETWORK_TRANSPORT, extractedTransport);
} else {
assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.NETWORK_TRANSPORT);
}
}

static final class NetworkTransportAndProtocolProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(
arguments("http", "1.0", "tcp", null),
arguments("http", "1.1", "tcp", null),
arguments("http", "2.0", "tcp", null),
arguments("http", "3.0", "udp", null),
arguments("http", "1.1", "udp", "udp"),
arguments("ftp", "2.0", "tcp", "tcp"),
arguments("http", "3.0", "tcp", "tcp"),
arguments("http", "42", "tcp", "tcp"));
}
}

@ParameterizedTest
@ArgumentsSource(ValidRequestMethodsProvider.class)
void shouldExtractKnownMethods(String requestMethod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.entry;
import static org.junit.jupiter.params.provider.Arguments.arguments;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
Expand All @@ -28,13 +27,9 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.ValueSource;

Expand Down Expand Up @@ -231,8 +226,6 @@ void normal() {
extractor.onEnd(endAttributes, Context.root(), request, response, null);
assertThat(endAttributes.build())
.containsOnly(
entry(SemanticAttributes.NETWORK_TRANSPORT, "udp"),
entry(SemanticAttributes.NETWORK_TYPE, "ipv4"),
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"),
Expand All @@ -246,49 +239,6 @@ void normal() {
asList("654", "321")));
}

@ParameterizedTest
@ArgumentsSource(NetworkTransportAndProtocolProvider.class)
void skipNetworkTransportIfDefaultForProtocol(
String observedProtocolName,
String observedProtocolVersion,
String observedTransport,
@Nullable String extractedTransport) {
Map<String, String> request = new HashMap<>();
request.put("networkProtocolName", observedProtocolName);
request.put("networkProtocolVersion", observedProtocolVersion);
request.put("networkTransport", observedTransport);

AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());

AttributesBuilder attributes = Attributes.builder();
extractor.onStart(attributes, Context.root(), request);
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);

if (extractedTransport != null) {
assertThat(attributes.build())
.containsEntry(SemanticAttributes.NETWORK_TRANSPORT, extractedTransport);
} else {
assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.NETWORK_TRANSPORT);
}
}

static final class NetworkTransportAndProtocolProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(
arguments("http", "1.0", "tcp", null),
arguments("http", "1.1", "tcp", null),
arguments("http", "2.0", "tcp", null),
arguments("http", "3.0", "udp", null),
arguments("http", "1.1", "udp", "udp"),
arguments("ftp", "2.0", "tcp", "tcp"),
arguments("http", "3.0", "tcp", "tcp"),
arguments("http", "42", "tcp", "tcp"));
}
}

@ParameterizedTest
@ArgumentsSource(ValidRequestMethodsProvider.class)
void shouldExtractKnownMethods(String requestMethod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,13 +1002,11 @@ SpanDataAssert assertClientSpan(
&& attrs.get(SemanticAttributes.NET_TRANSPORT) != null) {
assertThat(attrs).containsEntry(SemanticAttributes.NET_TRANSPORT, IP_TCP);
}
if (SemconvStability.emitStableHttpSemconv()
&& attrs.get(SemanticAttributes.NETWORK_TRANSPORT) != null) {
assertThat(attrs).containsEntry(SemanticAttributes.NETWORK_TRANSPORT, "tcp");
}
if (SemconvStability.emitStableHttpSemconv()
&& attrs.get(SemanticAttributes.NETWORK_TYPE) != null) {
assertThat(attrs).containsEntry(SemanticAttributes.NETWORK_TYPE, "ipv4");
if (SemconvStability.emitStableHttpSemconv()) {
// we're opting out of these attributes in the new semconv
assertThat(attrs)
.doesNotContainKey(SemanticAttributes.NETWORK_TRANSPORT)
.doesNotContainKey(SemanticAttributes.NETWORK_TYPE);
}
AttributeKey<String> netProtocolKey =
getAttributeKey(SemanticAttributes.NET_PROTOCOL_NAME);
Expand Down
Loading
Loading