diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientSideServerPortCondition.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientSideServerPortCondition.java deleted file mode 100644 index a79ba36fbbc2..000000000000 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientSideServerPortCondition.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import java.util.Locale; -import java.util.function.BiPredicate; - -final class ClientSideServerPortCondition implements BiPredicate { - - private final HttpClientAttributesGetter getter; - - ClientSideServerPortCondition(HttpClientAttributesGetter getter) { - this.getter = getter; - } - - @Override - public boolean test(Integer port, REQUEST request) { - String url = getter.getUrlFull(request); - if (url == null || port == null) { - return true; - } - url = url.toLowerCase(Locale.ROOT); - // according to spec: extract if not default (80 for http scheme, 443 for https). - if ((url.startsWith("http://") && port == 80) || (url.startsWith("https://") && port == 443)) { - return false; - } - return true; - } -} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java index 7b7969f52457..db5c12823fc2 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java @@ -145,7 +145,6 @@ InternalNetworkAttributesExtractor buildNetworkExtractor() { InternalServerAttributesExtractor buildServerExtractor() { return new InternalServerAttributesExtractor<>( - new ClientSideServerPortCondition<>(httpAttributesGetter), serverAddressAndPortExtractor, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv(), diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetrics.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetrics.java index e8a3fcf2a636..84c07318753e 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetrics.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetrics.java @@ -7,7 +7,6 @@ import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpMessageBodySizeUtil.getHttpRequestBodySize; import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpMessageBodySizeUtil.getHttpResponseBodySize; -import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpMetricsUtil.mergeClientAttributes; import static java.util.logging.Level.FINE; import io.opentelemetry.api.common.Attributes; @@ -84,7 +83,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { return; } - Attributes sizeAttributes = mergeClientAttributes(startAttributes, endAttributes); + Attributes sizeAttributes = startAttributes.toBuilder().putAll(endAttributes).build(); Long requestBodySize = getHttpRequestBodySize(endAttributes, startAttributes); if (requestBodySize != null) { diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index d8e2c9cba68c..5e61b9046d25 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -6,7 +6,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpMetricsUtil.createStableDurationHistogramBuilder; -import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpMetricsUtil.mergeClientAttributes; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -91,7 +90,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { return; } - Attributes attributes = mergeClientAttributes(state.startAttributes(), endAttributes); + Attributes attributes = state.startAttributes().toBuilder().putAll(endAttributes).build(); if (stableDuration != null) { stableDuration.record((endNanos - state.startTimeNanos()) / NANOS_PER_S, attributes, context); diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsAdvice.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsAdvice.java index ed32ff729717..ba6315b3b9a1 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsAdvice.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsAdvice.java @@ -31,8 +31,7 @@ static void applyStableClientDurationAdvice(DoubleHistogramBuilder builder) { SemanticAttributes.NETWORK_PROTOCOL_NAME, SemanticAttributes.NETWORK_PROTOCOL_VERSION, SemanticAttributes.SERVER_ADDRESS, - SemanticAttributes.SERVER_PORT, - SemanticAttributes.URL_SCHEME)); + SemanticAttributes.SERVER_PORT)); } @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 @@ -68,7 +67,6 @@ static void applyClientRequestSizeAdvice(LongHistogramBuilder builder) { SemanticAttributes.NETWORK_PROTOCOL_VERSION, SemanticAttributes.SERVER_ADDRESS, SemanticAttributes.SERVER_PORT, - SemanticAttributes.URL_SCHEME, // old attributes SemanticAttributes.HTTP_METHOD, SemanticAttributes.HTTP_STATUS_CODE, diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsUtil.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsUtil.java index adb992da95b8..8960e1e67fd4 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsUtil.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsUtil.java @@ -8,12 +8,9 @@ import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableList; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.api.metrics.DoubleHistogramBuilder; import io.opentelemetry.api.metrics.Meter; import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder; -import io.opentelemetry.semconv.SemanticAttributes; import java.util.List; final class HttpMetricsUtil { @@ -34,17 +31,5 @@ static DoubleHistogramBuilder createStableDurationHistogramBuilder( return durationBuilder; } - static Attributes mergeClientAttributes(Attributes startAttributes, Attributes endAttributes) { - AttributesBuilder builder = startAttributes.toBuilder().putAll(endAttributes); - String url = startAttributes.get(SemanticAttributes.URL_FULL); - if (url != null) { - int index = url.indexOf("://"); - if (index > 0) { - builder.put(SemanticAttributes.URL_SCHEME, url.substring(0, index)); - } - } - return builder.build(); - } - private HttpMetricsUtil() {} } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java index 304a78b5a05d..f524f48e06de 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java @@ -160,7 +160,6 @@ InternalNetworkAttributesExtractor buildNetworkExtractor() { InternalServerAttributesExtractor buildServerExtractor() { return new InternalServerAttributesExtractor<>( - new ServerSideServerPortCondition<>(httpAttributesGetter), serverAddressPortExtractor, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv(), diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ServerSideServerPortCondition.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ServerSideServerPortCondition.java deleted file mode 100644 index 3702ec21c5b6..000000000000 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/ServerSideServerPortCondition.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import java.util.function.BiPredicate; - -final class ServerSideServerPortCondition implements BiPredicate { - - private final HttpServerAttributesGetter getter; - - ServerSideServerPortCondition(HttpServerAttributesGetter getter) { - this.getter = getter; - } - - @Override - public boolean test(Integer port, REQUEST request) { - String scheme = getter.getUrlScheme(request); - if (scheme == null || port == null) { - return true; - } - // according to spec: extract if not default (80 for http scheme, 443 for https). - if ((scheme.equalsIgnoreCase("http") && port == 80) - || (scheme.equalsIgnoreCase("https") && port == 443)) { - return false; - } - return true; - } -} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java index aaf6d1f531ad..5f028aec09eb 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java @@ -58,7 +58,6 @@ private NetClientAttributesExtractor(NetClientAttributesGetter( - (port, request) -> true, serverAddressAndPortExtractor, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv(), diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java index 595d831c1ccb..b62bad5c29e2 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java @@ -60,7 +60,6 @@ private NetServerAttributesExtractor(NetServerAttributesGetter( - (port, request) -> true, serverAddressAndPortExtractor, SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv(), diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java index d6005b67aee1..9eddcb0c1eee 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractor.java @@ -51,10 +51,8 @@ ServerAttributesExtractor createForServerSide( ServerAttributesExtractor( ServerAttributesGetter getter, InternalServerAttributesExtractor.Mode mode) { - // the ServerAttributesExtractor will always emit new semconv internalExtractor = new InternalServerAttributesExtractor<>( - (port, request) -> true, new ServerAddressAndPortExtractor<>(getter, AddressAndPortExtractor.noop()), SemconvStability.emitStableHttpSemconv(), SemconvStability.emitOldHttpSemconv(), diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java index 1111943fc0f9..9f0016a89e85 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/network/internal/InternalServerAttributesExtractor.java @@ -10,7 +10,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.semconv.SemanticAttributes; -import java.util.function.BiPredicate; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at @@ -18,19 +17,16 @@ */ public final class InternalServerAttributesExtractor { - private final BiPredicate captureServerPortCondition; private final AddressAndPortExtractor addressAndPortExtractor; private final boolean emitStableUrlAttributes; private final boolean emitOldHttpAttributes; private final Mode oldSemconvMode; public InternalServerAttributesExtractor( - BiPredicate captureServerPortCondition, AddressAndPortExtractor addressAndPortExtractor, boolean emitStableUrlAttributes, boolean emitOldHttpAttributes, Mode oldSemconvMode) { - this.captureServerPortCondition = captureServerPortCondition; this.addressAndPortExtractor = addressAndPortExtractor; this.emitStableUrlAttributes = emitStableUrlAttributes; this.emitOldHttpAttributes = emitOldHttpAttributes; @@ -48,9 +44,7 @@ public void onStart(AttributesBuilder attributes, REQUEST request) { internalSet(attributes, oldSemconvMode.address, serverAddressAndPort.address); } - if (serverAddressAndPort.port != null - && serverAddressAndPort.port > 0 - && captureServerPortCondition.test(serverAddressAndPort.port, request)) { + if (serverAddressAndPort.port != null && serverAddressAndPort.port > 0) { if (emitStableUrlAttributes) { internalSet(attributes, SemanticAttributes.SERVER_PORT, (long) serverAddressAndPort.port); } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientSideServerPortConditionTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientSideServerPortConditionTest.java deleted file mode 100644 index 17514dd05748..000000000000 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ClientSideServerPortConditionTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.params.provider.Arguments.arguments; -import static org.mockito.Mockito.when; - -import java.util.function.BiPredicate; -import java.util.stream.Stream; -import org.junit.jupiter.api.extension.ExtendWith; -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.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -class ClientSideServerPortConditionTest { - - @Mock HttpClientAttributesGetter getter; - - @ParameterizedTest - @ArgumentsSource(Parameters.class) - void testCondition(Integer port, String url, boolean expectedResult) { - when(getter.getUrlFull("request")).thenReturn(url); - BiPredicate condition = new ClientSideServerPortCondition<>(getter); - assertThat(condition.test(port, "request")).isEqualTo(expectedResult); - } - - static final class Parameters implements ArgumentsProvider { - - @Override - public Stream provideArguments(ExtensionContext extensionContext) { - return Stream.of( - arguments(80, "http://test", false), - arguments(80, "HTTP://TEST", false), - arguments(443, "https://test", false), - arguments(443, "HTTPs://TEST", false), - arguments(80, "https://test", true), - arguments(443, "http://test", true), - arguments(null, "http://test", true), - arguments(null, "https://test", true)); - } - } -} diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java index 928137106fc9..4a0c38250a94 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java @@ -122,7 +122,7 @@ void normal() { request.put("protocolName", "http"); request.put("protocolVersion", "1.1"); request.put("serverAddress", "github.com"); - request.put("serverPort", "123"); + request.put("serverPort", "80"); Map response = new HashMap<>(); response.put("statusCode", "202"); @@ -148,7 +148,7 @@ void normal() { AttributeKey.stringArrayKey("http.request.header.custom_request_header"), asList("123", "456")), entry(SemanticAttributes.NET_PEER_NAME, "github.com"), - entry(SemanticAttributes.NET_PEER_PORT, 123L), + entry(SemanticAttributes.NET_PEER_PORT, 80L), entry(HttpAttributes.HTTP_REQUEST_RESEND_COUNT, 2L)); AttributesBuilder endAttributes = Attributes.builder(); @@ -259,34 +259,6 @@ void extractNetHostAndPortFromNetAttributesGetter() { entry(SemanticAttributes.NET_PEER_PORT, 777L)); } - @ParameterizedTest - @ArgumentsSource(DefaultPeerPortArgumentSource.class) - void defaultPeerPort(int peerPort, String url) { - Map request = new HashMap<>(); - request.put("urlFull", url); - request.put("serverPort", String.valueOf(peerPort)); - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - - assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.NET_PEER_PORT); - } - - static class DefaultPeerPortArgumentSource implements ArgumentsProvider { - - @Override - public Stream provideArguments(ExtensionContext context) { - return Stream.of( - arguments(80, "http://github.com"), - arguments(80, "HTTP://GITHUB.COM"), - arguments(443, "https://github.com"), - arguments(443, "HTTPS://GITHUB.COM")); - } - } - @Test void zeroResends() { Map request = new HashMap<>(); diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java index 2335c59323f5..dc43f83045cb 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java @@ -124,7 +124,7 @@ void normal() { request.put("header.content-length", "10"); request.put("route", "/repositories/{id}"); request.put("header.user-agent", "okhttp 3.x"); - request.put("header.host", "github.com"); + request.put("header.host", "github.com:80"); request.put("header.forwarded", "for=1.1.1.1;proto=https"); request.put("header.custom-request-header", "123,456"); request.put("networkTransport", "tcp"); @@ -151,6 +151,7 @@ void normal() { assertThat(startAttributes.build()) .containsOnly( entry(SemanticAttributes.NET_HOST_NAME, "github.com"), + entry(SemanticAttributes.NET_HOST_PORT, 80L), entry(SemanticAttributes.HTTP_METHOD, "POST"), entry(SemanticAttributes.HTTP_SCHEME, "https"), entry(SemanticAttributes.HTTP_TARGET, "/repositories/1?details=true"), @@ -235,33 +236,6 @@ void extractNetHostAndPortFromHostHeader() { entry(SemanticAttributes.NET_HOST_PORT, 777L)); } - @ParameterizedTest - @ArgumentsSource(DefaultHostPortArgumentSource.class) - void defaultHostPort(int hostPort, String scheme) { - Map request = new HashMap<>(); - request.put("urlScheme", scheme); - request.put("serverPort", hostPort); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) - .setCapturedRequestHeaders(emptyList()) - .setCapturedResponseHeaders(emptyList()) - .build(); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - - assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.NET_HOST_PORT); - } - - static class DefaultHostPortArgumentSource implements ArgumentsProvider { - - @Override - public Stream provideArguments(ExtensionContext context) { - return Stream.of(arguments(80, "http"), arguments(443, "https")); - } - } - @ParameterizedTest @ArgumentsSource(PathAndQueryArgumentSource.class) void computeTargetFromPathAndQuery(String path, String query, String expectedTarget) { diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ServerSideServerPortConditionTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ServerSideServerPortConditionTest.java deleted file mode 100644 index eb862759cc24..000000000000 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ServerSideServerPortConditionTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.params.provider.Arguments.arguments; -import static org.mockito.Mockito.when; - -import java.util.function.BiPredicate; -import java.util.stream.Stream; -import org.junit.jupiter.api.extension.ExtendWith; -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.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -class ServerSideServerPortConditionTest { - - @Mock HttpServerAttributesGetter getter; - - @ParameterizedTest - @ArgumentsSource(Parameters.class) - void testCondition(Integer port, String scheme, boolean expectedResult) { - when(getter.getUrlScheme("request")).thenReturn(scheme); - BiPredicate condition = new ServerSideServerPortCondition<>(getter); - assertThat(condition.test(port, "request")).isEqualTo(expectedResult); - } - - static final class Parameters implements ArgumentsProvider { - - @Override - public Stream provideArguments(ExtensionContext extensionContext) { - return Stream.of( - arguments(80, "http", false), - arguments(80, "HTTP", false), - arguments(443, "https", false), - arguments(443, "HTTPs", false), - arguments(80, "https", true), - arguments(443, "http", true), - arguments(null, "http", true), - arguments(null, "https", true)); - } - } -} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java index d686cd725869..60c8b60e5e46 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java @@ -149,7 +149,7 @@ void normal() { request.put("networkPeerAddress", "4.3.2.1"); request.put("networkPeerPort", "456"); request.put("serverAddress", "github.com"); - request.put("serverPort", "123"); + request.put("serverPort", "80"); Map response = new HashMap<>(); response.put("statusCode", "202"); @@ -175,7 +175,7 @@ void normal() { AttributeKey.stringArrayKey("http.request.header.custom-request-header"), asList("123", "456")), entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), - entry(SemanticAttributes.SERVER_PORT, 123L), + entry(SemanticAttributes.SERVER_PORT, 80L), entry(HttpAttributes.HTTP_REQUEST_RESEND_COUNT, 2L)); AttributesBuilder endAttributes = Attributes.builder(); diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsStableSemconvTest.java index 843dbe562736..cc0fc2669c0f 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsStableSemconvTest.java @@ -99,8 +99,7 @@ void collectsMetrics() { equalTo( SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), - equalTo(SemanticAttributes.SERVER_PORT, 1234), - equalTo(SemanticAttributes.URL_SCHEME, "https")) + equalTo(SemanticAttributes.SERVER_PORT, 1234)) .hasExemplarsSatisfying( exemplar -> exemplar @@ -127,8 +126,7 @@ void collectsMetrics() { equalTo( SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), - equalTo(SemanticAttributes.SERVER_PORT, 1234), - equalTo(SemanticAttributes.URL_SCHEME, "https")) + equalTo(SemanticAttributes.SERVER_PORT, 1234)) .hasExemplarsSatisfying( exemplar -> exemplar diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java index bffda6c5c2db..47669bd97147 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java @@ -101,8 +101,7 @@ void collectsMetrics() { equalTo( SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), - equalTo(SemanticAttributes.SERVER_PORT, 1234), - equalTo(SemanticAttributes.URL_SCHEME, "https")) + equalTo(SemanticAttributes.SERVER_PORT, 1234)) .hasExemplarsSatisfying( exemplar -> exemplar diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java index 7e080ed31fee..13604d65c4bc 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java @@ -164,7 +164,7 @@ void normal() { request.put("header.content-length", "10"); request.put("route", "/repositories/{id}"); request.put("header.user-agent", "okhttp 3.x"); - request.put("header.host", "github.com:123"); + request.put("header.host", "github.com:443"); request.put("header.forwarded", "for=1.1.1.1;proto=https"); request.put("header.custom-request-header", "123,456"); request.put("networkTransport", "udp"); @@ -195,7 +195,7 @@ void normal() { assertThat(startAttributes.build()) .containsOnly( entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), - entry(SemanticAttributes.SERVER_PORT, 123L), + entry(SemanticAttributes.SERVER_PORT, 443L), entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), entry(SemanticAttributes.URL_SCHEME, "https"), entry(SemanticAttributes.URL_PATH, "/repositories/1"), diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java index da88b0c63eb2..6af2a2b768c5 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java @@ -1043,9 +1043,12 @@ SpanDataAssert assertClientSpan( AttributeKey netPeerPortKey = getAttributeKey(SemanticAttributes.NET_PEER_PORT); if (httpClientAttributes.contains(netPeerPortKey)) { int uriPort = uri.getPort(); - // default values are ignored - if (uriPort <= 0 || uriPort == 80 || uriPort == 443) { - assertThat(attrs).doesNotContainKey(netPeerPortKey); + if (uriPort <= 0) { + if (attrs.get(netPeerPortKey) != null) { + int effectivePort = "https".equals(uri.getScheme()) ? 443 : 80; + assertThat(attrs).containsEntry(netPeerPortKey, effectivePort); + } + // alternatively, peer port is not emitted -- and that's fine too } else { assertThat(attrs).containsEntry(netPeerPortKey, uriPort); }