diff --git a/instrumentation-api-semconv/build.gradle.kts b/instrumentation-api-semconv/build.gradle.kts index fd51e449e7ac..8d76a932663a 100644 --- a/instrumentation-api-semconv/build.gradle.kts +++ b/instrumentation-api-semconv/build.gradle.kts @@ -23,41 +23,6 @@ dependencies { testImplementation("io.opentelemetry:opentelemetry-sdk-testing") } -testing { - suites { - val testStableHttpSemconv by registering(JvmTestSuite::class) { - dependencies { - implementation(project()) - implementation(project(":testing-common")) - implementation("io.opentelemetry:opentelemetry-sdk") - implementation("io.opentelemetry:opentelemetry-sdk-testing") - } - targets { - all { - testTask.configure { - jvmArgs("-Dotel.semconv-stability.opt-in=http") - } - } - } - } - val testBothHttpSemconv by registering(JvmTestSuite::class) { - dependencies { - implementation(project()) - implementation(project(":testing-common")) - implementation("io.opentelemetry:opentelemetry-sdk") - implementation("io.opentelemetry:opentelemetry-sdk-testing") - } - targets { - all { - testTask.configure { - jvmArgs("-Dotel.semconv-stability.opt-in=http/dup") - } - } - } - } - } -} - tasks { // exclude auto-generated code named("checkstyleMain") { @@ -74,8 +39,4 @@ tasks { sourcesJar { dependsOn("generateJflex") } - - check { - dependsOn(testing.suites) - } } 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 4a0c38250a94..86f1509534a1 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 @@ -8,9 +8,9 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; +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; @@ -18,21 +18,21 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; +import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.semconv.SemanticAttributes; +import java.net.ConnectException; import java.util.HashMap; +import java.util.HashSet; 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; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class HttpClientAttributesExtractorTest { static class TestHttpClientAttributesGetter @@ -57,7 +57,8 @@ public List getHttpRequestHeader(Map request, String nam @Override public Integer getHttpResponseStatusCode( Map request, Map response, @Nullable Throwable error) { - return Integer.parseInt(response.get("statusCode")); + String value = response.get("statusCode"); + return value == null ? null : Integer.parseInt(value); } @Override @@ -85,14 +86,29 @@ public String getNetworkType( @Override public String getNetworkProtocolName( Map request, @Nullable Map response) { - return request.get("protocolName"); + return request.get("networkProtocolName"); } @Nullable @Override public String getNetworkProtocolVersion( Map request, @Nullable Map response) { - return request.get("protocolVersion"); + return request.get("networkProtocolVersion"); + } + + @Nullable + @Override + public String getNetworkPeerAddress( + Map request, @Nullable Map response) { + return request.get("networkPeerAddress"); + } + + @Nullable + @Override + public Integer getNetworkPeerPort( + Map request, @Nullable Map response) { + String value = request.get("networkPeerPort"); + return value == null ? null : Integer.parseInt(value); } @Nullable @@ -104,8 +120,17 @@ public String getServerAddress(Map request) { @Nullable @Override public Integer getServerPort(Map request) { - String statusCode = request.get("serverPort"); - return statusCode == null ? null : Integer.parseInt(statusCode); + String value = request.get("serverPort"); + return value == null ? null : Integer.parseInt(value); + } + + @Nullable + @Override + public String getErrorType( + Map request, + @Nullable Map respobse, + @Nullable Throwable error) { + return request.get("errorType"); } } @@ -117,10 +142,12 @@ void normal() { request.put("header.content-length", "10"); request.put("header.user-agent", "okhttp 3.x"); request.put("header.custom-request-header", "123,456"); - request.put("networkTransport", "tcp"); + request.put("networkTransport", "udp"); request.put("networkType", "ipv4"); - request.put("protocolName", "http"); - request.put("protocolVersion", "1.1"); + request.put("networkProtocolName", "http"); + request.put("networkProtocolVersion", "1.1"); + request.put("networkPeerAddress", "4.3.2.1"); + request.put("networkPeerPort", "456"); request.put("serverAddress", "github.com"); request.put("serverPort", "80"); @@ -142,137 +169,256 @@ void normal() { extractor.onStart(startAttributes, Context.root(), request); assertThat(startAttributes.build()) .containsOnly( - entry(SemanticAttributes.HTTP_METHOD, "POST"), - entry(SemanticAttributes.HTTP_URL, "http://github.com"), + entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), + entry(SemanticAttributes.URL_FULL, "http://github.com"), entry( - AttributeKey.stringArrayKey("http.request.header.custom_request_header"), + AttributeKey.stringArrayKey("http.request.header.custom-request-header"), asList("123", "456")), - entry(SemanticAttributes.NET_PEER_NAME, "github.com"), - entry(SemanticAttributes.NET_PEER_PORT, 80L), + entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), + entry(SemanticAttributes.SERVER_PORT, 80L), entry(HttpAttributes.HTTP_REQUEST_RESEND_COUNT, 2L)); AttributesBuilder endAttributes = Attributes.builder(); extractor.onEnd(endAttributes, Context.root(), request, response, null); assertThat(endAttributes.build()) .containsOnly( - entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L), - entry(SemanticAttributes.HTTP_STATUS_CODE, 202L), - entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L), + entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), entry( - AttributeKey.stringArrayKey("http.response.header.custom_response_header"), + AttributeKey.stringArrayKey("http.response.header.custom-response-header"), asList("654", "321")), - entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1")); + entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 456L)); } @ParameterizedTest - @ArgumentsSource(StripUrlArgumentSource.class) - void stripBasicAuthTest(String url, String expectedResult) { + @ArgumentsSource(ValidRequestMethodsProvider.class) + void shouldExtractKnownMethods(String requestMethod) { Map request = new HashMap<>(); - request.put("urlFull", url); + request.put("method", requestMethod); AttributesExtractor, Map> extractor = HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_URL, expectedResult)); + assertThat(attributes.build()) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod) + .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL); } - static final class StripUrlArgumentSource implements ArgumentsProvider { + @ParameterizedTest + @ValueSource(strings = {"get", "Get"}) + void shouldTreatMethodsAsCaseSensitive(String requestMethod) { + Map request = new HashMap<>(); + request.put("method", requestMethod); + + AttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - @Override - public Stream provideArguments(ExtensionContext context) { - return Stream.of( - arguments("https://user1:secret@github.com", "https://REDACTED:REDACTED@github.com"), - arguments( - "https://user1:secret@github.com/path/", - "https://REDACTED:REDACTED@github.com/path/"), - arguments( - "https://user1:secret@github.com#test.html", - "https://REDACTED:REDACTED@github.com#test.html"), - arguments( - "https://user1:secret@github.com?foo=b@r", - "https://REDACTED:REDACTED@github.com?foo=b@r"), - arguments( - "https://user1:secret@github.com/p@th?foo=b@r", - "https://REDACTED:REDACTED@github.com/p@th?foo=b@r"), - arguments("https://github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"), - arguments("https://github.com#t@st.html", "https://github.com#t@st.html"), - arguments("user1:secret@github.com", "user1:secret@github.com"), - arguments("https://github.com@", "https://github.com@")); - } + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + + assertThat(attributes.build()) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); } - @Test - void invalidStatusCode() { + @ParameterizedTest + @ValueSource(strings = {"PURGE", "not a method really"}) + void shouldUseOtherForUnknownMethods(String requestMethod) { Map request = new HashMap<>(); + request.put("method", requestMethod); + + AttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + + assertThat(attributes.build()) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); + } + + @ParameterizedTest + @ValueSource(strings = {"only", "custom", "methods", "allowed"}) + void shouldExtractKnownMethods_override(String requestMethod) { + Map request = new HashMap<>(); + request.put("method", requestMethod); + + AttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()) + .setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed"))) + .build(); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + + assertThat(attributes.build()) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod) + .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL); + } + + @ParameterizedTest + @ArgumentsSource(ValidRequestMethodsProvider.class) + void shouldUseOtherForUnknownMethods_override(String requestMethod) { + Map request = new HashMap<>(); + request.put("method", requestMethod); + + AttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()) + .setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed"))) + .build(); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + + assertThat(attributes.build()) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); + } + @Test + void shouldExtractErrorType_httpStatusCode() { Map response = new HashMap<>(); - response.put("statusCode", "0"); + response.put("statusCode", "400"); AttributesExtractor, Map> extractor = HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - assertThat(attributes.build()).isEmpty(); + extractor.onStart(attributes, Context.root(), emptyMap()); + extractor.onEnd(attributes, Context.root(), emptyMap(), response, null); - extractor.onEnd(attributes, Context.root(), request, response, null); - assertThat(attributes.build()).isEmpty(); + assertThat(attributes.build()) + .containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 400) + .containsEntry(HttpAttributes.ERROR_TYPE, "400"); } @Test - void extractNetPeerNameAndPortFromHostHeader() { + void shouldExtractErrorType_getter() { Map request = new HashMap<>(); - request.put("header.host", "thehost:777"); + request.put("statusCode", "0"); + request.put("errorType", "custom error type"); AttributesExtractor, Map> extractor = HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); + extractor.onStart(attributes, Context.root(), emptyMap()); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + + assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, "custom error type"); + } + + @Test + void shouldExtractErrorType_exceptionClassName() { + AttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), emptyMap()); + extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), new ConnectException()); assertThat(attributes.build()) + .containsEntry(HttpAttributes.ERROR_TYPE, "java.net.ConnectException"); + } + + @Test + void shouldExtractErrorType_other() { + AttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), emptyMap()); + extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), null); + + assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, HttpConstants._OTHER); + } + + @Test + void shouldExtractServerAddressAndPortFromHostHeader() { + Map request = new HashMap<>(); + request.put("header.host", "github.com:123"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()) .containsOnly( - entry(SemanticAttributes.NET_PEER_NAME, "thehost"), - entry(SemanticAttributes.NET_PEER_PORT, 777L)); + entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), + entry(SemanticAttributes.SERVER_PORT, 123L)); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); } @Test - void extractNetHostAndPortFromNetAttributesGetter() { + void shouldExtractPeerAddressEvenIfItDuplicatesServerAddress() { Map request = new HashMap<>(); - request.put("header.host", "notthehost:77777"); // this should have lower precedence - request.put("serverAddress", "thehost"); - request.put("serverPort", "777"); + request.put("networkPeerAddress", "1.2.3.4"); + request.put("networkPeerPort", "456"); + request.put("serverAddress", "1.2.3.4"); + request.put("serverPort", "123"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); AttributesExtractor, Map> extractor = HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.SERVER_ADDRESS, "1.2.3.4"), + entry(SemanticAttributes.SERVER_PORT, 123L)); - assertThat(attributes.build()) + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) .containsOnly( - entry(SemanticAttributes.NET_PEER_NAME, "thehost"), - entry(SemanticAttributes.NET_PEER_PORT, 777L)); + entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 456L)); } @Test - void zeroResends() { + void shouldExtractProtocolNameDifferentFromHttp() { Map request = new HashMap<>(); + request.put("networkProtocolName", "spdy"); + request.put("networkProtocolVersion", "3.1"); - ToIntFunction resendCountFromContext = context -> 0; + Map response = new HashMap<>(); + response.put("statusCode", "200"); AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()) - .setResendCountIncrementer(resendCountFromContext) - .build(); + HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - extractor.onEnd(attributes, Context.root(), request, null, null); - assertThat(attributes.build()).isEmpty(); + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()).isEmpty(); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly( + entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), + entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "spdy"), + entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "3.1")); } } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsTest.java index 35bbbdafe5a8..11a2618c7a1b 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsTest.java @@ -15,6 +15,8 @@ import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.semconv.SemanticAttributes; @@ -24,7 +26,6 @@ class HttpClientExperimentalMetricsTest { @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void collectsMetrics() { InMemoryMetricReader metricReader = InMemoryMetricReader.create(); SdkMeterProvider meterProvider = @@ -35,24 +36,24 @@ void collectsMetrics() { Attributes requestAttributes = Attributes.builder() - .put("http.method", "GET") - .put("http.url", "https://localhost:1234/") - .put("http.target", "/") - .put("http.scheme", "https") - .put("net.peer.name", "localhost") - .put("net.peer.port", 1234) - .put("http.request_content_length", 100) + .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET") + .put(SemanticAttributes.URL_FULL, "https://localhost:1234/") + .put(SemanticAttributes.URL_PATH, "/") + .put(SemanticAttributes.URL_QUERY, "q=a") + .put(SemanticAttributes.SERVER_ADDRESS, "localhost") + .put(SemanticAttributes.SERVER_PORT, 1234) .build(); Attributes responseAttributes = Attributes.builder() - .put("http.status_code", 200) - .put("http.response_content_length", 200) - .put(SemanticAttributes.NET_PROTOCOL_NAME, "http") - .put(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0") - .put("net.sock.peer.addr", "1.2.3.4") - .put("net.sock.peer.name", "somehost20") - .put("net.sock.peer.port", 8080) + .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200) + .put(HttpAttributes.ERROR_TYPE, "400") + .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100) + .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) + .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http") + .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0") + .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") + .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) .build(); Context parent = @@ -81,6 +82,7 @@ void collectsMetrics() { assertThat(metric) .hasName("http.client.request.size") .hasUnit("By") + .hasDescription("Size of HTTP client request bodies.") .hasHistogramSatisfying( histogram -> histogram.hasPointsSatisfying( @@ -88,14 +90,16 @@ void collectsMetrics() { point .hasSum(100 /* bytes */) .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, 1234), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo( - SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4")) + SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(HttpAttributes.ERROR_TYPE, "400"), + equalTo( + SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), + equalTo( + SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, 1234)) .hasExemplarsSatisfying( exemplar -> exemplar @@ -105,6 +109,7 @@ void collectsMetrics() { assertThat(metric) .hasName("http.client.response.size") .hasUnit("By") + .hasDescription("Size of HTTP client response bodies.") .hasHistogramSatisfying( histogram -> histogram.hasPointsSatisfying( @@ -112,14 +117,16 @@ void collectsMetrics() { point .hasSum(200 /* bytes */) .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, 1234), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo( + SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(HttpAttributes.ERROR_TYPE, "400"), + equalTo( + SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), equalTo( - SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4")) + SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, 1234)) .hasExemplarsSatisfying( exemplar -> exemplar diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java index 50d00352b7d7..8ef09576acd9 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java @@ -15,8 +15,9 @@ import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.sdk.metrics.SdkMeterProvider; -import io.opentelemetry.sdk.metrics.internal.aggregator.ExplicitBucketHistogramUtils; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.semconv.SemanticAttributes; import java.util.concurrent.TimeUnit; @@ -24,13 +25,10 @@ class HttpClientMetricsTest { - static final double[] DEFAULT_BUCKETS = - ExplicitBucketHistogramUtils.DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES.stream() - .mapToDouble(d -> d) - .toArray(); + static final double[] DURATION_BUCKETS = + HttpMetricsUtil.DURATION_SECONDS_BUCKETS.stream().mapToDouble(d -> d).toArray(); @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void collectsMetrics() { InMemoryMetricReader metricReader = InMemoryMetricReader.create(); SdkMeterProvider meterProvider = @@ -40,24 +38,24 @@ void collectsMetrics() { Attributes requestAttributes = Attributes.builder() - .put("http.method", "GET") - .put("http.url", "https://localhost:1234/") - .put("http.target", "/") - .put("http.scheme", "https") - .put("net.peer.name", "localhost") - .put("net.peer.port", 1234) - .put("http.request_content_length", 100) + .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET") + .put(SemanticAttributes.URL_FULL, "https://localhost:1234/") + .put(SemanticAttributes.URL_PATH, "/") + .put(SemanticAttributes.URL_QUERY, "q=a") + .put(SemanticAttributes.SERVER_ADDRESS, "localhost") + .put(SemanticAttributes.SERVER_PORT, 1234) .build(); Attributes responseAttributes = Attributes.builder() - .put("http.status_code", 200) - .put("http.response_content_length", 200) - .put(SemanticAttributes.NET_PROTOCOL_NAME, "http") - .put(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0") - .put("net.sock.peer.addr", "1.2.3.4") - .put("net.sock.peer.name", "somehost20") - .put("net.sock.peer.port", 8080) + .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200) + .put(HttpAttributes.ERROR_TYPE, "400") + .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100) + .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) + .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http") + .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0") + .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") + .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) .build(); Context parent = @@ -84,29 +82,32 @@ void collectsMetrics() { .satisfiesExactlyInAnyOrder( metric -> assertThat(metric) - .hasName("http.client.duration") - .hasUnit("ms") + .hasName("http.client.request.duration") + .hasUnit("s") + .hasDescription("Duration of HTTP client requests.") .hasHistogramSatisfying( histogram -> histogram.hasPointsSatisfying( point -> point - .hasSum(150 /* millis */) + .hasSum(0.15 /* seconds */) .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, 1234), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo( - SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4")) + SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(HttpAttributes.ERROR_TYPE, "400"), + equalTo( + SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), + equalTo( + SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, 1234)) .hasExemplarsSatisfying( exemplar -> exemplar .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") .hasSpanId("090a0b0c0d0e0f00")) - .hasBucketBoundaries(DEFAULT_BUCKETS)))); + .hasBucketBoundaries(DURATION_BUCKETS)))); listener.onEnd(context2, responseAttributes, nanos(300)); @@ -114,11 +115,11 @@ void collectsMetrics() { .satisfiesExactlyInAnyOrder( metric -> assertThat(metric) - .hasName("http.client.duration") + .hasName("http.client.request.duration") .hasHistogramSatisfying( histogram -> histogram.hasPointsSatisfying( - point -> point.hasSum(300 /* millis */)))); + point -> point.hasSum(0.3 /* seconds */)))); } private static long nanos(int millis) { diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientPeerServiceAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientPeerServiceAttributesExtractorTest.java index 47cbcc31590d..2c6933069d2c 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientPeerServiceAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientPeerServiceAttributesExtractorTest.java @@ -10,8 +10,6 @@ import static org.assertj.core.api.Assertions.entry; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.opentelemetry.api.common.Attributes; @@ -76,7 +74,6 @@ void shouldNotSetAnyValueIfPeerNameDoesNotMatch() { assertTrue(endAttributes.build().isEmpty()); } - @SuppressWarnings("deprecation") // old semconv @Test void shouldSetPeerNameIfItMatches() { // given @@ -100,37 +97,6 @@ void shouldSetPeerNameIfItMatches() { AttributesBuilder endAttributes = Attributes.builder(); underTest.onEnd(endAttributes, context, "request", "response", null); - // then - assertThat(startAttributes.build()).isEmpty(); - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); - verify(httpAttributesExtractor, never()).getServerSocketDomain(any(), any()); - } - - @SuppressWarnings("deprecation") // old semconv - @Test - void shouldSetSockPeerNameIfItMatchesAndNoPeerNameProvided() { - // given - Map peerServiceMapping = new HashMap<>(); - peerServiceMapping.put("example.com", "myService"); - peerServiceMapping.put("1.2.3.4", "someOtherService"); - - PeerServiceResolver peerServiceResolver = PeerServiceResolver.create(peerServiceMapping); - - HttpClientPeerServiceAttributesExtractor underTest = - new HttpClientPeerServiceAttributesExtractor<>( - httpAttributesExtractor, peerServiceResolver); - - when(httpAttributesExtractor.getServerSocketDomain(any(), any())).thenReturn("example.com"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - underTest.onStart(startAttributes, context, "request"); - AttributesBuilder endAttributes = Attributes.builder(); - underTest.onEnd(endAttributes, context, "request", "response", null); - // then assertThat(startAttributes.build()).isEmpty(); assertThat(endAttributes.build()) diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpExperimentalAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpExperimentalAttributesExtractorTest.java similarity index 100% rename from instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpExperimentalAttributesExtractorTest.java rename to instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpExperimentalAttributesExtractorTest.java 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 dc43f83045cb..cc090dab111d 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 @@ -8,138 +8,182 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; +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; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; +import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.semconv.SemanticAttributes; +import java.net.ConnectException; import java.util.HashMap; +import java.util.HashSet; 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; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class HttpServerAttributesExtractorTest { static class TestHttpServerAttributesGetter - implements HttpServerAttributesGetter, Map> { + implements HttpServerAttributesGetter, Map> { @Override - public String getHttpRequestMethod(Map request) { - return (String) request.get("method"); + public String getHttpRequestMethod(Map request) { + return request.get("method"); } @Override - public String getUrlScheme(Map request) { - return (String) request.get("urlScheme"); + public String getUrlScheme(Map request) { + return request.get("urlScheme"); } @Nullable @Override - public String getUrlPath(Map request) { - return (String) request.get("urlPath"); + public String getUrlPath(Map request) { + return request.get("urlPath"); } @Nullable @Override - public String getUrlQuery(Map request) { - return (String) request.get("urlQuery"); + public String getUrlQuery(Map request) { + return request.get("urlQuery"); } @Override - public String getHttpRoute(Map request) { - return (String) request.get("route"); + public String getHttpRoute(Map request) { + return request.get("route"); } @Override - public List getHttpRequestHeader(Map request, String name) { - String values = (String) request.get("header." + name); + public List getHttpRequestHeader(Map request, String name) { + String values = request.get("header." + name); return values == null ? emptyList() : asList(values.split(",")); } @Override public Integer getHttpResponseStatusCode( - Map request, Map response, @Nullable Throwable error) { - String value = (String) response.get("statusCode"); + Map request, Map response, @Nullable Throwable error) { + String value = response.get("statusCode"); return value == null ? null : Integer.parseInt(value); } @Override public List getHttpResponseHeader( - Map request, Map response, String name) { - String values = (String) response.get("header." + name); + Map request, Map response, String name) { + String values = response.get("header." + name); return values == null ? emptyList() : asList(values.split(",")); } @Nullable @Override public String getNetworkTransport( - Map request, @Nullable Map response) { - return (String) request.get("networkTransport"); + Map request, @Nullable Map response) { + return request.get("networkTransport"); } @Nullable @Override public String getNetworkType( - Map request, @Nullable Map response) { - return (String) request.get("networkType"); + Map request, @Nullable Map response) { + return request.get("networkType"); } @Nullable @Override public String getNetworkProtocolName( - Map request, Map response) { - return (String) request.get("protocolName"); + Map request, Map response) { + return request.get("networkProtocolName"); } @Nullable @Override public String getNetworkProtocolVersion( - Map request, Map response) { - return (String) request.get("protocolVersion"); + Map request, Map response) { + return request.get("networkProtocolVersion"); + } + + @Nullable + @Override + public String getNetworkLocalAddress( + Map request, @Nullable Map response) { + return request.get("networkLocalAddress"); + } + + @Nullable + @Override + public Integer getNetworkLocalPort( + Map request, @Nullable Map response) { + String value = request.get("networkLocalPort"); + return value == null ? null : Integer.parseInt(value); + } + + @Nullable + @Override + public String getNetworkPeerAddress( + Map request, @Nullable Map response) { + return request.get("networkPeerAddress"); + } + + @Nullable + @Override + public Integer getNetworkPeerPort( + Map request, @Nullable Map response) { + String value = request.get("networkPeerPort"); + return value == null ? null : Integer.parseInt(value); + } + + @Nullable + @Override + public String getErrorType( + Map request, + @Nullable Map respobse, + @Nullable Throwable error) { + return request.get("errorType"); } } @Test void normal() { - Map request = new HashMap<>(); + Map request = new HashMap<>(); request.put("method", "POST"); - request.put("urlFull", "http://github.com"); + request.put("urlFull", "https://github.com"); request.put("urlPath", "/repositories/1"); request.put("urlQuery", "details=true"); - request.put("urlScheme", "http"); + request.put("urlScheme", "https"); 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:80"); + 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", "tcp"); + request.put("networkTransport", "udp"); request.put("networkType", "ipv4"); - request.put("protocolName", "http"); - request.put("protocolVersion", "2.0"); - - Map response = new HashMap<>(); + request.put("networkProtocolName", "http"); + request.put("networkProtocolVersion", "2.0"); + request.put("networkLocalAddress", "1.2.3.4"); + request.put("networkLocalPort", "42"); + request.put("networkPeerAddress", "4.3.2.1"); + request.put("networkPeerPort", "456"); + + Map response = new HashMap<>(); response.put("statusCode", "202"); response.put("header.content-length", "20"); response.put("header.custom-response-header", "654,321"); Function routeFromContext = ctx -> "/repositories/{repoId}"; - AttributesExtractor, Map> extractor = + AttributesExtractor, Map> extractor = HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) .setCapturedRequestHeaders(singletonList("Custom-Request-Header")) .setCapturedResponseHeaders(singletonList("Custom-Response-Header")) @@ -150,122 +194,362 @@ void normal() { extractor.onStart(startAttributes, Context.root(), request); 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"), + entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), + entry(SemanticAttributes.SERVER_PORT, 443L), + entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), + entry(SemanticAttributes.URL_SCHEME, "https"), + entry(SemanticAttributes.URL_PATH, "/repositories/1"), + entry(SemanticAttributes.URL_QUERY, "details=true"), entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"), entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{id}"), - entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"), + entry(SemanticAttributes.CLIENT_ADDRESS, "1.1.1.1"), entry( - AttributeKey.stringArrayKey("http.request.header.custom_request_header"), + AttributeKey.stringArrayKey("http.request.header.custom-request-header"), asList("123", "456"))); AttributesBuilder endAttributes = Attributes.builder(); extractor.onEnd(endAttributes, Context.root(), request, response, null); assertThat(endAttributes.build()) .containsOnly( - entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"), + entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 456L), entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"), - entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L), - entry(SemanticAttributes.HTTP_STATUS_CODE, 202L), - entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L), + entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), entry( - AttributeKey.stringArrayKey("http.response.header.custom_response_header"), + AttributeKey.stringArrayKey("http.response.header.custom-response-header"), asList("654", "321"))); } - @Test - void extractClientIpFromX_Forwarded_For() { - Map request = new HashMap<>(); - request.put("header.x-forwarded-for", "1.1.1.1"); + @ParameterizedTest + @ArgumentsSource(ValidRequestMethodsProvider.class) + void shouldExtractKnownMethods(String requestMethod) { + Map request = new HashMap<>(); + request.put("method", requestMethod); - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) - .setCapturedRequestHeaders(emptyList()) - .setCapturedResponseHeaders(emptyList()) - .build(); + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + assertThat(attributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1")); + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod) + .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL); + } + + @ParameterizedTest + @ValueSource(strings = {"get", "Get"}) + void shouldTreatMethodsAsCaseSensitive(String requestMethod) { + Map request = new HashMap<>(); + request.put("method", requestMethod); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - extractor.onEnd(attributes, Context.root(), request, null, null); assertThat(attributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1")); + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); } - @Test - void extractClientIpFromX_Forwarded_Proto() { - Map request = new HashMap<>(); - request.put("header.x-forwarded-proto", "https"); + @ParameterizedTest + @ValueSource(strings = {"PURGE", "not a method really"}) + void shouldUseOtherForUnknownMethods(String requestMethod) { + Map request = new HashMap<>(); + request.put("method", requestMethod); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + + assertThat(attributes.build()) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); + } - AttributesExtractor, Map> extractor = + @ParameterizedTest + @ValueSource(strings = {"only", "custom", "methods", "allowed"}) + void shouldExtractKnownMethods_override(String requestMethod) { + Map request = new HashMap<>(); + request.put("method", requestMethod); + + AttributesExtractor, Map> extractor = HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) - .setCapturedRequestHeaders(emptyList()) - .setCapturedResponseHeaders(emptyList()) + .setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed"))) .build(); AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, Context.root(), request); - assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_SCHEME, "https")); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - extractor.onEnd(attributes, Context.root(), request, null, null); - assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_SCHEME, "https")); + assertThat(attributes.build()) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod) + .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL); } - @Test - void extractNetHostAndPortFromHostHeader() { - Map request = new HashMap<>(); - request.put("header.host", "thehost:777"); + @ParameterizedTest + @ArgumentsSource(ValidRequestMethodsProvider.class) + void shouldUseOtherForUnknownMethods_override(String requestMethod) { + Map request = new HashMap<>(); + request.put("method", requestMethod); - AttributesExtractor, Map> extractor = + AttributesExtractor, Map> extractor = HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) - .setCapturedRequestHeaders(emptyList()) - .setCapturedResponseHeaders(emptyList()) + .setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed"))) .build(); AttributesBuilder attributes = Attributes.builder(); extractor.onStart(attributes, Context.root(), request); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + assertThat(attributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_HOST_NAME, "thehost"), - entry(SemanticAttributes.NET_HOST_PORT, 777L)); + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); } - @ParameterizedTest - @ArgumentsSource(PathAndQueryArgumentSource.class) - void computeTargetFromPathAndQuery(String path, String query, String expectedTarget) { - Map request = new HashMap<>(); - request.put("urlPath", path); - request.put("urlQuery", query); + @Test + void shouldExtractErrorType_httpStatusCode() { + Map response = new HashMap<>(); + response.put("statusCode", "500"); - AttributesExtractor, Map> extractor = + AttributesExtractor, Map> extractor = HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); + extractor.onStart(attributes, Context.root(), emptyMap()); + extractor.onEnd(attributes, Context.root(), emptyMap(), response, null); - if (expectedTarget == null) { - assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.HTTP_TARGET); - } else { - assertThat(attributes.build()).containsEntry(SemanticAttributes.HTTP_TARGET, expectedTarget); - } + assertThat(attributes.build()) + .containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 500) + .containsEntry(HttpAttributes.ERROR_TYPE, "500"); } - static class PathAndQueryArgumentSource implements ArgumentsProvider { + @Test + void shouldExtractErrorType_getter() { + Map request = new HashMap<>(); + request.put("statusCode", "0"); + request.put("errorType", "custom error type"); - @Override - public Stream provideArguments(ExtensionContext context) { - return Stream.of( - arguments(null, null, null), - arguments("path", null, "path"), - arguments("path", "", "path"), - arguments(null, "query", "?query"), - arguments("path", "query", "path?query")); - } + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), emptyMap()); + extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); + + assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, "custom error type"); + } + + @Test + void shouldExtractErrorType_exceptionClassName() { + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), emptyMap()); + extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), new ConnectException()); + + assertThat(attributes.build()) + .containsEntry(HttpAttributes.ERROR_TYPE, "java.net.ConnectException"); + } + + @Test + void shouldExtractErrorType_other() { + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder attributes = Attributes.builder(); + extractor.onStart(attributes, Context.root(), emptyMap()); + extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), null); + + assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, HttpConstants._OTHER); + } + + @Test + void shouldPreferUrlSchemeFromForwardedHeader() { + Map request = new HashMap<>(); + request.put("urlScheme", "http"); + request.put("header.forwarded", "proto=https"); + + Map response = new HashMap<>(); + response.put("statusCode", "202"); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()).containsOnly(entry(SemanticAttributes.URL_SCHEME, "https")); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L)); + } + + @Test + void shouldExtractServerAddressAndPortFromForwardedHeader() { + Map request = new HashMap<>(); + request.put("header.forwarded", "host=example.com:42"); + request.put("header.x-forwarded-host", "opentelemetry.io:987"); + request.put("header.host", "github.com:123"); + request.put("header.:authority", "opentelemetry.io:456"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.SERVER_ADDRESS, "example.com"), + entry(SemanticAttributes.SERVER_PORT, 42L)); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + } + + @Test + void shouldExtractServerAddressAndPortFromForwardedHostHeader() { + Map request = new HashMap<>(); + request.put("header.x-forwarded-host", "opentelemetry.io:987"); + request.put("header.host", "github.com:123"); + request.put("header.:authority", "opentelemetry.io:42"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"), + entry(SemanticAttributes.SERVER_PORT, 987L)); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + } + + @Test + void shouldExtractServerAddressAndPortFromAuthorityPseudoHeader() { + Map request = new HashMap<>(); + request.put("header.:authority", "opentelemetry.io:42"); + request.put("header.host", "github.com:123"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"), + entry(SemanticAttributes.SERVER_PORT, 42L)); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + } + + @Test + void shouldExtractServerAddressAndPortFromHostHeader() { + Map request = new HashMap<>(); + request.put("header.host", "github.com:123"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + + assertThat(startAttributes.build()) + .containsOnly( + entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), + entry(SemanticAttributes.SERVER_PORT, 123L)); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); + } + + @Test + void shouldExtractPeerAddressEvenIfItDuplicatesClientAddress() { + Map request = new HashMap<>(); + request.put("networkPeerAddress", "1.2.3.4"); + request.put("networkPeerPort", "456"); + request.put("header.forwarded", "for=1.2.3.4:123"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()) + .containsOnly(entry(SemanticAttributes.CLIENT_ADDRESS, "1.2.3.4")); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly( + entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 456L)); + } + + @Test + void shouldExtractProtocolNameDifferentFromHttp() { + Map request = new HashMap<>(); + request.put("networkProtocolName", "spdy"); + request.put("networkProtocolVersion", "3.1"); + + Map response = new HashMap<>(); + response.put("statusCode", "200"); + + AttributesExtractor, Map> extractor = + HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); + + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, Context.root(), request); + assertThat(startAttributes.build()).isEmpty(); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, Context.root(), request, response, null); + assertThat(endAttributes.build()) + .containsOnly( + entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), + entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "spdy"), + entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "3.1")); } } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerExperimentalMetricsTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerExperimentalMetricsTest.java index e9a16d9bdba6..dc130376058f 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerExperimentalMetricsTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerExperimentalMetricsTest.java @@ -7,7 +7,6 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.Span; @@ -16,6 +15,8 @@ import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.semconv.SemanticAttributes; @@ -25,7 +26,6 @@ class HttpServerExperimentalMetricsTest { @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void collectsMetrics() { InMemoryMetricReader metricReader = InMemoryMetricReader.create(); SdkMeterProvider meterProvider = @@ -36,26 +36,28 @@ void collectsMetrics() { Attributes requestAttributes = Attributes.builder() - .put("http.method", "GET") - .put("http.target", "/") - .put("http.scheme", "https") - .put("net.transport", IP_TCP) - .put(SemanticAttributes.NET_PROTOCOL_NAME, "http") - .put(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0") - .put("net.host.name", "localhost") - .put("net.host.port", 1234) - .put("net.sock.family", "inet") - .put("net.sock.peer.addr", "1.2.3.4") - .put("net.sock.peer.port", 8080) - .put("net.sock.host.addr", "4.3.2.1") - .put("net.sock.host.port", 9090) + .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET") + .put(SemanticAttributes.URL_SCHEME, "https") + .put(SemanticAttributes.URL_PATH, "/") + .put(SemanticAttributes.URL_QUERY, "q=a") + .put(SemanticAttributes.NETWORK_TRANSPORT, "tcp") + .put(SemanticAttributes.NETWORK_TYPE, "ipv4") + .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http") + .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0") + .put(SemanticAttributes.SERVER_ADDRESS, "localhost") + .put(SemanticAttributes.SERVER_PORT, 1234) .build(); Attributes responseAttributes = Attributes.builder() - .put("http.status_code", 200) - .put("http.request_content_length", 100) - .put("http.response_content_length", 200) + .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200) + .put(HttpAttributes.ERROR_TYPE, "500") + .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100) + .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) + .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") + .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) + .put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4.3.2.1") + .put(NetworkAttributes.NETWORK_LOCAL_PORT, 9090) .build(); SpanContext spanContext1 = @@ -80,6 +82,7 @@ void collectsMetrics() { assertThat(metric) .hasName("http.server.active_requests") .hasUnit("{requests}") + .hasDescription("Number of active HTTP server requests.") .hasLongSumSatisfying( sum -> sum.hasPointsSatisfying( @@ -87,10 +90,8 @@ void collectsMetrics() { point .hasValue(1) .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_SCHEME, "https"), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, 1234L)) + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.URL_SCHEME, "https")) .hasExemplarsSatisfying( exemplar -> exemplar @@ -112,10 +113,8 @@ void collectsMetrics() { point .hasValue(2) .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_SCHEME, "https"), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, 1234L)) + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.URL_SCHEME, "https")) .hasExemplarsSatisfying( exemplar -> exemplar @@ -136,10 +135,8 @@ void collectsMetrics() { point .hasValue(1) .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_SCHEME, "https"), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, 1234L)) + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.URL_SCHEME, "https")) .hasExemplarsSatisfying( exemplar -> exemplar @@ -149,6 +146,7 @@ void collectsMetrics() { assertThat(metric) .hasName("http.server.request.size") .hasUnit("By") + .hasDescription("Size of HTTP server request bodies.") .hasHistogramSatisfying( histogram -> histogram.hasPointsSatisfying( @@ -156,13 +154,15 @@ void collectsMetrics() { point .hasSum(100 /* bytes */) .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.HTTP_SCHEME, "https"), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, 1234)) + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo( + SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(HttpAttributes.ERROR_TYPE, "500"), + equalTo( + SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), + equalTo( + SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), + equalTo(SemanticAttributes.URL_SCHEME, "https")) .hasExemplarsSatisfying( exemplar -> exemplar @@ -172,6 +172,7 @@ void collectsMetrics() { assertThat(metric) .hasName("http.server.response.size") .hasUnit("By") + .hasDescription("Size of HTTP server response bodies.") .hasHistogramSatisfying( histogram -> histogram.hasPointsSatisfying( @@ -179,13 +180,15 @@ void collectsMetrics() { point .hasSum(200 /* bytes */) .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.HTTP_SCHEME, "https"), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, 1234)) + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo( + SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(HttpAttributes.ERROR_TYPE, "500"), + equalTo( + SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), + equalTo( + SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), + equalTo(SemanticAttributes.URL_SCHEME, "https")) .hasExemplarsSatisfying( exemplar -> exemplar diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java index 1926cc6bff73..eb2d93328d0c 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java @@ -7,7 +7,6 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.Span; @@ -16,20 +15,18 @@ import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.sdk.metrics.SdkMeterProvider; -import io.opentelemetry.sdk.metrics.internal.aggregator.ExplicitBucketHistogramUtils; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.semconv.SemanticAttributes; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class HttpServerMetricsTest { - static final double[] DEFAULT_BUCKETS = - ExplicitBucketHistogramUtils.DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES.stream() - .mapToDouble(d -> d) - .toArray(); + static final double[] DURATION_BUCKETS = + HttpMetricsUtil.DURATION_SECONDS_BUCKETS.stream().mapToDouble(d -> d).toArray(); @Test void collectsMetrics() { @@ -41,26 +38,28 @@ void collectsMetrics() { Attributes requestAttributes = Attributes.builder() - .put("http.method", "GET") - .put("http.target", "/") - .put("http.scheme", "https") - .put("net.transport", IP_TCP) - .put(SemanticAttributes.NET_PROTOCOL_NAME, "http") - .put(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0") - .put("net.host.name", "localhost") - .put("net.host.port", 1234) - .put("net.sock.family", "inet") - .put("net.sock.peer.addr", "1.2.3.4") - .put("net.sock.peer.port", 8080) - .put("net.sock.host.addr", "4.3.2.1") - .put("net.sock.host.port", 9090) + .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET") + .put(SemanticAttributes.URL_SCHEME, "https") + .put(SemanticAttributes.URL_PATH, "/") + .put(SemanticAttributes.URL_QUERY, "q=a") + .put(SemanticAttributes.NETWORK_TRANSPORT, "tcp") + .put(SemanticAttributes.NETWORK_TYPE, "ipv4") + .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http") + .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0") + .put(SemanticAttributes.SERVER_ADDRESS, "localhost") + .put(SemanticAttributes.SERVER_PORT, 1234) .build(); Attributes responseAttributes = Attributes.builder() - .put("http.status_code", 200) - .put("http.request_content_length", 100) - .put("http.response_content_length", 200) + .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200) + .put(HttpAttributes.ERROR_TYPE, "500") + .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100) + .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) + .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") + .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) + .put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4.3.2.1") + .put(NetworkAttributes.NETWORK_LOCAL_PORT, 9090) .build(); SpanContext spanContext1 = @@ -88,28 +87,31 @@ void collectsMetrics() { .satisfiesExactlyInAnyOrder( metric -> assertThat(metric) - .hasName("http.server.duration") - .hasUnit("ms") + .hasName("http.server.request.duration") + .hasDescription("Duration of HTTP server requests.") + .hasUnit("s") .hasHistogramSatisfying( histogram -> histogram.hasPointsSatisfying( point -> point - .hasSum(150 /* millis */) + .hasSum(0.15 /* seconds */) .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.HTTP_SCHEME, "https"), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, 1234)) + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo( + SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(HttpAttributes.ERROR_TYPE, "500"), + equalTo( + SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), + equalTo( + SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), + equalTo(SemanticAttributes.URL_SCHEME, "https")) .hasExemplarsSatisfying( exemplar -> exemplar .hasTraceId(spanContext1.getTraceId()) .hasSpanId(spanContext1.getSpanId())) - .hasBucketBoundaries(DEFAULT_BUCKETS)))); + .hasBucketBoundaries(DURATION_BUCKETS)))); listener.onEnd(context2, responseAttributes, nanos(300)); @@ -117,13 +119,13 @@ void collectsMetrics() { .satisfiesExactlyInAnyOrder( metric -> assertThat(metric) - .hasName("http.server.duration") + .hasName("http.server.request.duration") .hasHistogramSatisfying( histogram -> histogram.hasPointsSatisfying( point -> point - .hasSum(300 /* millis */) + .hasSum(0.3 /* seconds */) .hasExemplarsSatisfying( exemplar -> exemplar @@ -141,9 +143,13 @@ void collectsHttpRouteFromEndAttributes() { OperationListener listener = HttpServerMetrics.get().create(meterProvider.get("test")); Attributes requestAttributes = - Attributes.builder().put("net.host.name", "host").put("http.scheme", "https").build(); + Attributes.builder() + .put(SemanticAttributes.SERVER_ADDRESS, "host") + .put(SemanticAttributes.URL_SCHEME, "https") + .build(); - Attributes responseAttributes = Attributes.builder().put("http.route", "/test/{id}").build(); + Attributes responseAttributes = + Attributes.builder().put(SemanticAttributes.HTTP_ROUTE, "/test/{id}").build(); Context parentContext = Context.root(); @@ -156,17 +162,16 @@ void collectsHttpRouteFromEndAttributes() { .anySatisfy( metric -> assertThat(metric) - .hasName("http.server.duration") - .hasUnit("ms") + .hasName("http.server.request.duration") + .hasUnit("s") .hasHistogramSatisfying( histogram -> histogram.hasPointsSatisfying( point -> point - .hasSum(100 /* millis */) + .hasSum(0.100 /* seconds */) .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_SCHEME, "https"), - equalTo(SemanticAttributes.NET_HOST_NAME, "host"), + equalTo(SemanticAttributes.URL_SCHEME, "https"), equalTo( SemanticAttributes.HTTP_ROUTE, "/test/{id}"))))); } diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/ValidRequestMethodsProvider.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ValidRequestMethodsProvider.java similarity index 100% rename from instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/ValidRequestMethodsProvider.java rename to instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/ValidRequestMethodsProvider.java diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetterTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetterTest.java deleted file mode 100644 index e53f7e56fe7d..000000000000 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetterTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.net; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.semconv.SemanticAttributes; -import java.net.Inet4Address; -import java.net.InetSocketAddress; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; - -@SuppressWarnings("deprecation") // testing deprecated class -@ExtendWith(MockitoExtension.class) -class InetSocketAddressNetClientAttributesGetterTest { - - static class TestNetClientAttributesGetter - implements NetClientAttributesGetter { - - @Override - public String getServerAddress(InetSocketAddress request) { - // net.peer.name and net.peer.port are tested in NetClientAttributesExtractorTest - return null; - } - - @Override - public Integer getServerPort(InetSocketAddress request) { - // net.peer.name and net.peer.port are tested in NetClientAttributesExtractorTest - return null; - } - - @Override - public InetSocketAddress getNetworkPeerInetSocketAddress( - InetSocketAddress request, InetSocketAddress response) { - return response; - } - } - - private final AttributesExtractor extractor = - NetClientAttributesExtractor.create(new TestNetClientAttributesGetter()); - - @Test - void noInetSocketAddress() { - - AttributesBuilder attributes = Attributes.builder(); - extractor.onEnd(attributes, Context.root(), null, null, null); - assertThat(attributes.build()).isEmpty(); - } - - @Test - @SuppressWarnings("AddressSelection") - void fullAddress() { - // given - InetSocketAddress address = new InetSocketAddress("api.github.com", 456); - assertThat(address.getAddress().getHostAddress()).isNotNull(); - - boolean ipv4 = address.getAddress() instanceof Inet4Address; - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, address); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, address, address, null); - - // then - assertThat(startAttributes.build()).isEmpty(); - - AttributesBuilder builder = Attributes.builder(); - builder.put(SemanticAttributes.NET_SOCK_PEER_ADDR, address.getAddress().getHostAddress()); - if (!ipv4) { - builder.put(SemanticAttributes.NET_SOCK_FAMILY, "inet6"); - } - builder.put(SemanticAttributes.NET_SOCK_PEER_NAME, "api.github.com"); - builder.put(SemanticAttributes.NET_SOCK_PEER_PORT, 456L); - - assertThat(endAttributes.build()).isEqualTo(builder.build()); - } - - @Test - void unresolved() { - // given - InetSocketAddress address = InetSocketAddress.createUnresolved("api.github.com", 456); - assertThat(address.getAddress()).isNull(); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, address); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, address, address, null); - - // then - assertThat(startAttributes.build()).isEmpty(); - assertThat(endAttributes.build()).isEmpty(); - } -} diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java deleted file mode 100644 index a17a2d769de3..000000000000 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.net; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.semconv.SemanticAttributes; -import java.net.Inet4Address; -import java.net.InetSocketAddress; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; - -@SuppressWarnings("deprecation") // testing deprecated class -@ExtendWith(MockitoExtension.class) -class InetSocketAddressNetServerAttributesGetterTest { - - static class TestNetServerAttributesGetter - implements NetServerAttributesGetter { - - @Override - public String getServerAddress(Addresses request) { - // net.host.name and net.host.port are tested in NetClientAttributesExtractorTest - return null; - } - - @Override - public Integer getServerPort(Addresses request) { - // net.host.name and net.host.port are tested in NetClientAttributesExtractorTest - return null; - } - - @Override - public InetSocketAddress getNetworkPeerInetSocketAddress( - Addresses request, Addresses response) { - return request.peer; - } - - @Override - public InetSocketAddress getNetworkLocalInetSocketAddress( - Addresses request, Addresses response) { - return request.host; - } - } - - private final AttributesExtractor extractor = - NetServerAttributesExtractor.create(new TestNetServerAttributesGetter()); - - @Test - void noInetSocketAddress() { - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), new Addresses(null, null)); - assertThat(attributes.build()).isEmpty(); - } - - @Test - @SuppressWarnings("AddressSelection") - void fullAddress() { - // given - Addresses request = - new Addresses( - new InetSocketAddress("github.com", 123), new InetSocketAddress("api.github.com", 456)); - assertThat(request.peer.getAddress().getHostAddress()).isNotNull(); - assertThat(request.host.getAddress().getHostAddress()).isNotNull(); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, request); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, request, request, null); - - // then - if (!request.isIpv4()) { - assertThat(startAttributes.build()) - .isEqualTo(Attributes.of(SemanticAttributes.NET_SOCK_FAMILY, "inet6")); - } else { - assertThat(startAttributes.build()).isEmpty(); - } - - assertThat(endAttributes.build()) - .containsOnly( - entry( - SemanticAttributes.NET_SOCK_HOST_ADDR, request.host.getAddress().getHostAddress()), - entry(SemanticAttributes.NET_SOCK_HOST_PORT, 456L), - entry( - SemanticAttributes.NET_SOCK_PEER_ADDR, request.peer.getAddress().getHostAddress()), - entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L)); - } - - @Test - void unresolved() { - // given - Addresses request = - new Addresses( - InetSocketAddress.createUnresolved("github.com", 123), - InetSocketAddress.createUnresolved("api.github.com", 456)); - assertThat(request.peer.getAddress()).isNull(); - assertThat(request.host.getAddress()).isNull(); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, request); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, request, request, null); - - // then - assertThat(startAttributes.build()).isEmpty(); - assertThat(endAttributes.build()).isEmpty(); - } - - static final class Addresses { - - private final InetSocketAddress peer; - private final InetSocketAddress host; - - Addresses(InetSocketAddress peer, InetSocketAddress host) { - this.peer = peer; - this.host = host; - } - - boolean isIpv4() { - return peer.getAddress() instanceof Inet4Address; - } - } -} diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java index 1a4d66015da0..2313630c0a9e 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java @@ -7,13 +7,13 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; -import static java.util.Collections.emptyMap; import static org.assertj.core.api.Assertions.entry; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -117,84 +117,16 @@ void normal() { // then assertThat(startAttributes.build()) .containsOnly( - entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"), - entry(SemanticAttributes.NET_PEER_PORT, 42L)); + entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"), + entry(SemanticAttributes.SERVER_PORT, 42L)); assertThat(endAttributes.build()) .containsOnly( - entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), - entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"), - entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), - entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L)); - } - - @Test - void empty() { - // given - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, emptyMap()); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, emptyMap(), emptyMap(), null); - - // then - assertThat(startAttributes.build()).isEmpty(); - assertThat(endAttributes.build()).isEmpty(); - } - - @Test - void doesNotSetNegativePortValues() { - // given - Map map = new HashMap<>(); - map.put("peerName", "opentelemetry.io"); - map.put("peerPort", "-12"); - map.put("sockPeerAddr", "1:2:3:4::"); - map.put("sockPeerPort", "-42"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, map, null); - - // then - assertThat(startAttributes.build()) - .containsOnly(entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io")); - - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::")); - } - - @Test - void doesNotSetSockFamilyInet() { - // given - Map map = new HashMap<>(); - map.put("peerName", "opentelemetry.io"); - map.put("sockPeerAddr", "1.2.3.4"); - map.put("sockFamily", SemanticAttributes.NetSockFamilyValues.INET); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, map, null); - - // then - assertThat(startAttributes.build()) - .containsOnly(entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io")); - - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4")); + entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), + entry(SemanticAttributes.NETWORK_TYPE, "ipv6"), + entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), + entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 123L)); } } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java index 498e046b9160..9f8954c4c132 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java @@ -7,13 +7,13 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; -import static java.util.Collections.emptyMap; import static org.assertj.core.api.Assertions.entry; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -131,90 +131,18 @@ void normal() { // then assertThat(startAttributes.build()) .containsOnly( - entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), - entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"), - entry(SemanticAttributes.NET_HOST_PORT, 80L), - entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6")); + entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"), + entry(SemanticAttributes.SERVER_PORT, 80L)); assertThat(endAttributes.build()) .containsOnly( - entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"), - entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L), - entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), - entry(SemanticAttributes.NET_SOCK_PEER_PORT, 42L)); - } - - @Test - void empty() { - // given - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, emptyMap()); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, emptyMap(), null, null); - - // then - assertThat(startAttributes.build()).isEmpty(); - assertThat(endAttributes.build()).isEmpty(); - } - - @Test - void doesNotSetNegativePort() { - // given - Map map = new HashMap<>(); - map.put("hostName", "opentelemetry.io"); - map.put("hostPort", "-80"); - map.put("sockPeerAddr", "1:2:3:4::"); - map.put("sockPeerPort", "-42"); - map.put("sockHostAddr", "4:3:2:1::"); - map.put("sockHostPort", "-8080"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, null, null); - - // then - assertThat(startAttributes.build()) - .containsOnly(entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io")); - - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"), - entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::")); - } - - @Test - void doesNotSetSockFamilyInet() { - // given - Map map = new HashMap<>(); - map.put("hostName", "opentelemetry.io"); - map.put("sockPeerAddr", "1.2.3.4"); - map.put("sockFamily", SemanticAttributes.NetSockFamilyValues.INET); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, null, null); - - // then - assertThat(startAttributes.build()) - .containsOnly(entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io")); - - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4")); + entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), + entry(SemanticAttributes.NETWORK_TYPE, "ipv6"), + entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), + entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + entry(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4:3:2:1::"), + entry(NetworkAttributes.NETWORK_LOCAL_PORT, 8080L), + entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"), + entry(NetworkAttributes.NETWORK_PEER_PORT, 42L)); } } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorOldSemconvTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorOldSemconvTest.java deleted file mode 100644 index 7fcc492c775e..000000000000 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorOldSemconvTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.network; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static java.util.Collections.emptyMap; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 -class ClientAttributesExtractorOldSemconvTest { - - static class TestClientAttributesGetter - implements ClientAttributesGetter, Void> { - - @Nullable - @Override - public String getClientAddress(Map request) { - return request.get("address"); - } - - @Nullable - @Override - public Integer getClientPort(Map request) { - String value = request.get("port"); - return value == null ? null : Integer.parseInt(value); - } - } - - @Test - void allAttributes() { - Map request = new HashMap<>(); - request.put("address", "opentelemetry.io"); - request.put("port", "80"); - - AttributesExtractor, Void> extractor = - ClientAttributesExtractor.create(new TestClientAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_CLIENT_IP, "opentelemetry.io")); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()).isEmpty(); - } - - @Test - void noAttributes() { - AttributesExtractor, Void> extractor = - ClientAttributesExtractor.create(new TestClientAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), emptyMap()); - assertThat(startAttributes.build()).isEmpty(); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null); - assertThat(endAttributes.build()).isEmpty(); - } -} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorTest.java similarity index 100% rename from instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorTest.java rename to instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ClientAttributesExtractorTest.java diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorInetSocketAddressTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorInetSocketAddressTest.java similarity index 100% rename from instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorInetSocketAddressTest.java rename to instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorInetSocketAddressTest.java diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorOldSemconvTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorOldSemconvTest.java deleted file mode 100644 index 7ea4e0cf74a4..000000000000 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorOldSemconvTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.network; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static java.util.Collections.emptyMap; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 -class NetworkAttributesExtractorOldSemconvTest { - - static class TestNetworkAttributesGetter - implements NetworkAttributesGetter, Void> { - - @Nullable - @Override - public String getNetworkTransport(Map request, @Nullable Void response) { - return request.get("transport"); - } - - @Nullable - @Override - public String getNetworkType(Map request, @Nullable Void response) { - return request.get("type"); - } - - @Nullable - @Override - public String getNetworkProtocolName(Map request, @Nullable Void response) { - return request.get("protocolName"); - } - - @Nullable - @Override - public String getNetworkProtocolVersion(Map request, @Nullable Void response) { - return request.get("protocolVersion"); - } - - @Nullable - @Override - public String getNetworkLocalAddress(Map request, @Nullable Void response) { - return request.get("localAddress"); - } - - @Nullable - @Override - public Integer getNetworkLocalPort(Map request, @Nullable Void response) { - String value = request.get("localPort"); - return value == null ? null : Integer.parseInt(value); - } - - @Nullable - @Override - public String getNetworkPeerAddress(Map request, @Nullable Void response) { - return request.get("peerAddress"); - } - - @Nullable - @Override - public Integer getNetworkPeerPort(Map request, @Nullable Void response) { - String value = request.get("peerPort"); - return value == null ? null : Integer.parseInt(value); - } - } - - @Test - void allAttributes() { - Map request = new HashMap<>(); - request.put("transport", "TcP"); - request.put("type", "IPv4"); - request.put("protocolName", "Http"); - request.put("protocolVersion", "1.1"); - request.put("localAddress", "1.2.3.4"); - request.put("localPort", "8080"); - request.put("peerAddress", "4.3.2.1"); - request.put("peerPort", "9090"); - - AttributesExtractor, Void> extractor = - NetworkAttributesExtractor.create(new TestNetworkAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()).isEmpty(); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()) - .containsOnly( - // the NetworkAttributesExtractor can't emit old net.transport & net.sock.family - entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "1.2.3.4"), - entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L), - entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "4.3.2.1"), - entry(SemanticAttributes.NET_SOCK_PEER_PORT, 9090L)); - } - - @Test - void noAttributes() { - AttributesExtractor, Void> extractor = - NetworkAttributesExtractor.create(new TestNetworkAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), emptyMap()); - assertThat(startAttributes.build()).isEmpty(); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null); - assertThat(endAttributes.build()).isEmpty(); - } -} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorTest.java similarity index 100% rename from instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorTest.java rename to instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/NetworkAttributesExtractorTest.java diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorOldSemconvTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorOldSemconvTest.java deleted file mode 100644 index a294ef229c5a..000000000000 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorOldSemconvTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.network; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static java.util.Collections.emptyMap; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 -class ServerAttributesExtractorOldSemconvTest { - - static class TestServerAttributesGetter - implements ServerAttributesGetter, Void> { - - @Nullable - @Override - public String getServerAddress(Map request) { - return request.get("address"); - } - - @Nullable - @Override - public Integer getServerPort(Map request) { - String port = request.get("port"); - return port == null ? null : Integer.parseInt(port); - } - } - - @Test - void allAttributes_peer() { - Map request = new HashMap<>(); - request.put("address", "opentelemetry.io"); - request.put("port", "80"); - - AttributesExtractor, Void> extractor = - ServerAttributesExtractor.create(new TestServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"), - entry(SemanticAttributes.NET_PEER_PORT, 80L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()).isEmpty(); - } - - @SuppressWarnings("deprecation") // need to test the old semconv too - @Test - void allAttributes_host() { - Map request = new HashMap<>(); - request.put("address", "opentelemetry.io"); - request.put("port", "80"); - - AttributesExtractor, Void> extractor = - ServerAttributesExtractor.createForServerSide(new TestServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"), - entry(SemanticAttributes.NET_HOST_PORT, 80L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, null, null); - assertThat(endAttributes.build()).isEmpty(); - } - - @Test - void noAttributes() { - AttributesExtractor, Void> extractor = - ServerAttributesExtractor.create(new TestServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), emptyMap()); - assertThat(startAttributes.build()).isEmpty(); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null); - assertThat(endAttributes.build()).isEmpty(); - } -} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorTest.java similarity index 100% rename from instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorTest.java rename to instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/network/ServerAttributesExtractorTest.java diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetricsTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetricsTest.java index 267cbea980f2..f6a9f73c6779 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetricsTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetricsTest.java @@ -24,7 +24,6 @@ class RpcClientMetricsTest { @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void collectsMetrics() { InMemoryMetricReader metricReader = InMemoryMetricReader.createDelta(); SdkMeterProvider meterProvider = @@ -41,15 +40,16 @@ void collectsMetrics() { Attributes responseAttributes1 = Attributes.builder() - .put(SemanticAttributes.NET_PEER_NAME, "example.com") - .put(SemanticAttributes.NET_PEER_PORT, 8080) - .put(SemanticAttributes.NET_TRANSPORT, "ip_tcp") + .put(SemanticAttributes.SERVER_ADDRESS, "example.com") + .put(SemanticAttributes.SERVER_PORT, 8080) + .put(SemanticAttributes.NETWORK_TRANSPORT, "tcp") + .put(SemanticAttributes.NETWORK_TYPE, "ipv4") .build(); Attributes responseAttributes2 = Attributes.builder() - .put(SemanticAttributes.NET_PEER_PORT, 8080) - .put(SemanticAttributes.NET_TRANSPORT, "ip_tcp") + .put(SemanticAttributes.SERVER_PORT, 8080) + .put(SemanticAttributes.NETWORK_TRANSPORT, "tcp") .build(); Context parent = @@ -91,9 +91,10 @@ void collectsMetrics() { "myservice.EchoService"), equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"), equalTo( - SemanticAttributes.NET_PEER_NAME, "example.com"), - equalTo(SemanticAttributes.NET_PEER_PORT, 8080), - equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp")) + SemanticAttributes.SERVER_ADDRESS, "example.com"), + equalTo(SemanticAttributes.SERVER_PORT, 8080), + equalTo(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")) .hasExemplarsSatisfying( exemplar -> exemplar @@ -120,8 +121,9 @@ void collectsMetrics() { SemanticAttributes.RPC_SERVICE, "myservice.EchoService"), equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"), - equalTo(SemanticAttributes.NET_PEER_PORT, 8080), - equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"))))); + equalTo(SemanticAttributes.SERVER_PORT, 8080), + equalTo( + SemanticAttributes.NETWORK_TRANSPORT, "tcp"))))); } private static long nanos(int millis) { diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetricsTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetricsTest.java index fd12a60d1483..c589c033a7b6 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetricsTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetricsTest.java @@ -15,6 +15,7 @@ import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.semconv.SemanticAttributes; @@ -24,7 +25,6 @@ class RpcServerMetricsTest { @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void collectsMetrics() { InMemoryMetricReader metricReader = InMemoryMetricReader.createDelta(); SdkMeterProvider meterProvider = @@ -41,17 +41,18 @@ void collectsMetrics() { Attributes responseAttributes1 = Attributes.builder() - .put(SemanticAttributes.NET_HOST_NAME, "example.com") - .put(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1") - .put(SemanticAttributes.NET_HOST_PORT, 8080) - .put(SemanticAttributes.NET_TRANSPORT, "ip_tcp") + .put(SemanticAttributes.SERVER_ADDRESS, "example.com") + .put(SemanticAttributes.SERVER_PORT, 8080) + .put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "127.0.0.1") + .put(SemanticAttributes.NETWORK_TRANSPORT, "tcp") + .put(SemanticAttributes.NETWORK_TYPE, "ipv4") .build(); Attributes responseAttributes2 = Attributes.builder() - .put(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1") - .put(SemanticAttributes.NET_HOST_PORT, 8080) - .put(SemanticAttributes.NET_TRANSPORT, "ip_tcp") + .put(SemanticAttributes.SERVER_PORT, 8080) + .put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "127.0.0.1") + .put(SemanticAttributes.NETWORK_TRANSPORT, "tcp") .build(); Context parent = @@ -93,8 +94,9 @@ void collectsMetrics() { "myservice.EchoService"), equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"), equalTo( - SemanticAttributes.NET_HOST_NAME, "example.com"), - equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp")) + SemanticAttributes.SERVER_ADDRESS, "example.com"), + equalTo(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")) .hasExemplarsSatisfying( exemplar -> exemplar @@ -122,8 +124,7 @@ void collectsMetrics() { "myservice.EchoService"), equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"), equalTo( - SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"))))); + SemanticAttributes.NETWORK_TRANSPORT, "tcp"))))); } private static long nanos(int millis) { diff --git a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBothSemconvTest.java b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBothSemconvTest.java deleted file mode 100644 index 59f9e43d6a4e..000000000000 --- a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBothSemconvTest.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.ToIntFunction; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -class HttpClientAttributesExtractorBothSemconvTest { - - static class TestHttpClientAttributesGetter - implements HttpClientAttributesGetter, Map> { - - @Override - public String getUrlFull(Map request) { - return request.get("urlFull"); - } - - @Override - public String getHttpRequestMethod(Map request) { - return request.get("method"); - } - - @Override - public List getHttpRequestHeader(Map request, String name) { - String value = request.get("header." + name); - return value == null ? emptyList() : asList(value.split(",")); - } - - @Override - public Integer getHttpResponseStatusCode( - Map request, Map response, @Nullable Throwable error) { - return Integer.parseInt(response.get("statusCode")); - } - - @Override - public List getHttpResponseHeader( - Map request, Map response, String name) { - String value = response.get("header." + name); - return value == null ? emptyList() : asList(value.split(",")); - } - - @Nullable - @Override - public String getNetworkTransport( - Map request, @Nullable Map response) { - return request.get("networkTransport"); - } - - @Nullable - @Override - public String getNetworkType( - Map request, @Nullable Map response) { - return request.get("networkType"); - } - - @Nullable - @Override - public String getNetworkProtocolName( - Map request, @Nullable Map response) { - return request.get("protocolName"); - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - Map request, @Nullable Map response) { - return request.get("protocolVersion"); - } - - @Nullable - @Override - public String getServerAddress(Map request) { - return request.get("serverAddress"); - } - - @Nullable - @Override - public Integer getServerPort(Map request) { - String statusCode = request.get("serverPort"); - return statusCode == null ? null : Integer.parseInt(statusCode); - } - } - - @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 - void normal() { - Map request = new HashMap<>(); - request.put("method", "POST"); - request.put("urlFull", "http://github.com"); - request.put("header.content-length", "10"); - request.put("header.user-agent", "okhttp 3.x"); - request.put("header.custom-request-header", "123,456"); - request.put("networkTransport", "udp"); - request.put("networkType", "ipv4"); - request.put("protocolName", "http"); - request.put("protocolVersion", "1.1"); - request.put("serverAddress", "github.com"); - request.put("serverPort", "123"); - - Map response = new HashMap<>(); - response.put("statusCode", "202"); - response.put("header.content-length", "20"); - response.put("header.custom-response-header", "654,321"); - - ToIntFunction resendCountFromContext = context -> 2; - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()) - .setCapturedRequestHeaders(singletonList("Custom-Request-Header")) - .setCapturedResponseHeaders(singletonList("Custom-Response-Header")) - .setResendCountIncrementer(resendCountFromContext) - .build(); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.HTTP_METHOD, "POST"), - entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), - entry(SemanticAttributes.HTTP_URL, "http://github.com"), - entry(SemanticAttributes.URL_FULL, "http://github.com"), - entry( - AttributeKey.stringArrayKey("http.request.header.custom_request_header"), - asList("123", "456")), - entry( - 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.SERVER_ADDRESS, "github.com"), - entry(SemanticAttributes.SERVER_PORT, 123L), - entry(HttpAttributes.HTTP_REQUEST_RESEND_COUNT, 2L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L), - entry(SemanticAttributes.HTTP_STATUS_CODE, 202L), - entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), - entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L), - entry( - AttributeKey.stringArrayKey("http.response.header.custom_response_header"), - asList("654", "321")), - entry( - AttributeKey.stringArrayKey("http.response.header.custom-response-header"), - asList("654", "321")), - entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1")); - } -} diff --git a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBothSemconvTest.java b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBothSemconvTest.java deleted file mode 100644 index 55cc917cc854..000000000000 --- a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBothSemconvTest.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -class HttpServerAttributesExtractorBothSemconvTest { - - static class TestHttpServerAttributesGetter - implements HttpServerAttributesGetter, Map> { - - @Override - public String getHttpRequestMethod(Map request) { - return (String) request.get("method"); - } - - @Override - public String getUrlScheme(Map request) { - return (String) request.get("urlScheme"); - } - - @Nullable - @Override - public String getUrlPath(Map request) { - return (String) request.get("urlPath"); - } - - @Nullable - @Override - public String getUrlQuery(Map request) { - return (String) request.get("urlQuery"); - } - - @Override - public String getHttpRoute(Map request) { - return (String) request.get("route"); - } - - @Override - public List getHttpRequestHeader(Map request, String name) { - String values = (String) request.get("header." + name); - return values == null ? emptyList() : asList(values.split(",")); - } - - @Override - public Integer getHttpResponseStatusCode( - Map request, Map response, @Nullable Throwable error) { - String value = (String) response.get("statusCode"); - return value == null ? null : Integer.parseInt(value); - } - - @Override - public List getHttpResponseHeader( - Map request, Map response, String name) { - String values = (String) response.get("header." + name); - return values == null ? emptyList() : asList(values.split(",")); - } - - @Nullable - @Override - public String getNetworkTransport( - Map request, @Nullable Map response) { - return (String) request.get("networkTransport"); - } - - @Nullable - @Override - public String getNetworkType( - Map request, @Nullable Map response) { - return (String) request.get("networkType"); - } - - @Nullable - @Override - public String getNetworkProtocolName( - Map request, Map response) { - return (String) request.get("protocolName"); - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - Map request, Map response) { - return (String) request.get("protocolVersion"); - } - } - - @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 - void normal() { - Map request = new HashMap<>(); - request.put("method", "POST"); - request.put("urlFull", "https://github.com"); - request.put("urlPath", "/repositories/1"); - request.put("urlQuery", "details=true"); - request.put("urlScheme", "https"); - 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.forwarded", "for=1.1.1.1;proto=https"); - request.put("header.custom-request-header", "123,456"); - request.put("networkTransport", "udp"); - request.put("networkType", "ipv4"); - request.put("protocolName", "http"); - request.put("protocolVersion", "2.0"); - - Map response = new HashMap<>(); - response.put("statusCode", "202"); - response.put("header.content-length", "20"); - response.put("header.custom-response-header", "654,321"); - - Function routeFromContext = ctx -> "/repositories/{repoId}"; - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) - .setCapturedRequestHeaders(singletonList("Custom-Request-Header")) - .setCapturedResponseHeaders(singletonList("Custom-Response-Header")) - .setHttpRouteGetter(routeFromContext) - .build(); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_HOST_NAME, "github.com"), - entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), - entry(SemanticAttributes.HTTP_METHOD, "POST"), - entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), - entry(SemanticAttributes.HTTP_SCHEME, "https"), - entry(SemanticAttributes.HTTP_TARGET, "/repositories/1?details=true"), - entry(SemanticAttributes.URL_SCHEME, "https"), - entry(SemanticAttributes.URL_PATH, "/repositories/1"), - entry(SemanticAttributes.URL_QUERY, "details=true"), - entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"), - entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{id}"), - entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"), - entry(SemanticAttributes.CLIENT_ADDRESS, "1.1.1.1"), - entry( - AttributeKey.stringArrayKey("http.request.header.custom_request_header"), - asList("123", "456")), - entry( - AttributeKey.stringArrayKey("http.request.header.custom-request-header"), - asList("123", "456"))); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"), - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), - entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"), - entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L), - entry(SemanticAttributes.HTTP_STATUS_CODE, 202L), - entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), - entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L), - entry( - AttributeKey.stringArrayKey("http.response.header.custom_response_header"), - asList("654", "321")), - entry( - AttributeKey.stringArrayKey("http.response.header.custom-response-header"), - asList("654", "321"))); - } -} diff --git a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorBothSemconvTest.java b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorBothSemconvTest.java deleted file mode 100644 index 57c317f5242b..000000000000 --- a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorBothSemconvTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.net; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -@SuppressWarnings("deprecation") // testing deprecated class -class NetClientAttributesExtractorBothSemconvTest { - - static class TestNetClientAttributesGetter - implements NetClientAttributesGetter, Map> { - - @Override - public String getTransport(Map request, Map response) { - return response.get("netTransport"); - } - - @Nullable - @Override - public String getNetworkTransport( - Map request, @Nullable Map response) { - return request.get("transport"); - } - - @Nullable - @Override - public String getNetworkType( - Map request, @Nullable Map response) { - return request.get("type"); - } - - @Nullable - @Override - public String getNetworkProtocolName( - Map request, @Nullable Map response) { - return request.get("protocolName"); - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - Map request, @Nullable Map response) { - return request.get("protocolVersion"); - } - - @Override - public String getServerAddress(Map request) { - return request.get("peerName"); - } - - @Override - public Integer getServerPort(Map request) { - String peerPort = request.get("peerPort"); - return peerPort == null ? null : Integer.valueOf(peerPort); - } - - @Override - public String getSockFamily(Map request, Map response) { - return response.get("sockFamily"); - } - - @Override - public String getNetworkPeerAddress(Map request, Map response) { - return response.get("sockPeerAddr"); - } - - @Override - public Integer getNetworkPeerPort(Map request, Map response) { - String sockPeerPort = response.get("sockPeerPort"); - return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort); - } - } - - private final AttributesExtractor, Map> extractor = - NetClientAttributesExtractor.create(new TestNetClientAttributesGetter()); - - @Test - void normal() { - // given - Map map = new HashMap<>(); - map.put("netTransport", IP_TCP); - map.put("transport", "tcp"); - map.put("type", "ipv6"); - map.put("protocolName", "http"); - map.put("protocolVersion", "1.1"); - map.put("peerName", "opentelemetry.io"); - map.put("peerPort", "42"); - map.put("sockFamily", "inet6"); - map.put("sockPeerAddr", "1:2:3:4::"); - map.put("sockPeerName", "proxy.opentelemetry.io"); - map.put("sockPeerPort", "123"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, map, null); - - // then - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"), - entry(SemanticAttributes.NET_PEER_PORT, 42L), - entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"), - entry(SemanticAttributes.SERVER_PORT, 42L)); - - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), - entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), - entry(SemanticAttributes.NETWORK_TYPE, "ipv6"), - entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), - entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"), - entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), - entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L), - entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"), - entry(NetworkAttributes.NETWORK_PEER_PORT, 123L)); - } -} diff --git a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorBothSemconvTest.java b/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorBothSemconvTest.java deleted file mode 100644 index 0ec785070170..000000000000 --- a/instrumentation-api-semconv/src/testBothHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorBothSemconvTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.net; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -@SuppressWarnings("deprecation") // testing deprecated class -class NetServerAttributesExtractorBothSemconvTest { - - static class TestNetServerAttributesGetter - implements NetServerAttributesGetter, Void> { - - @Override - public String getTransport(Map request) { - return request.get("netTransport"); - } - - @Nullable - @Override - public String getNetworkTransport(Map request, @Nullable Void response) { - return request.get("transport"); - } - - @Nullable - @Override - public String getNetworkType(Map request, @Nullable Void response) { - return request.get("type"); - } - - @Nullable - @Override - public String getNetworkProtocolName(Map request, Void response) { - return request.get("protocolName"); - } - - @Nullable - @Override - public String getNetworkProtocolVersion(Map request, Void response) { - return request.get("protocolVersion"); - } - - @Nullable - @Override - public String getServerAddress(Map request) { - return request.get("hostName"); - } - - @Nullable - @Override - public Integer getServerPort(Map request) { - String hostPort = request.get("hostPort"); - return hostPort == null ? null : Integer.valueOf(hostPort); - } - - @Nullable - @Override - public String getSockFamily(Map request) { - return request.get("sockFamily"); - } - - @Override - public String getNetworkPeerAddress(Map request, Void response) { - return request.get("sockPeerAddr"); - } - - @Override - public Integer getNetworkPeerPort(Map request, Void response) { - String sockPeerPort = request.get("sockPeerPort"); - return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort); - } - - @Nullable - @Override - public String getNetworkLocalAddress(Map request, Void response) { - return request.get("sockHostAddr"); - } - - @Nullable - @Override - public Integer getNetworkLocalPort(Map request, Void response) { - String sockHostPort = request.get("sockHostPort"); - return sockHostPort == null ? null : Integer.valueOf(sockHostPort); - } - } - - AttributesExtractor, Void> extractor = - NetServerAttributesExtractor.create(new TestNetServerAttributesGetter()); - - @Test - void normal() { - // given - Map map = new HashMap<>(); - map.put("netTransport", IP_TCP); - map.put("transport", "tcp"); - map.put("type", "ipv6"); - map.put("protocolName", "http"); - map.put("protocolVersion", "1.1"); - map.put("hostName", "opentelemetry.io"); - map.put("hostPort", "80"); - map.put("sockFamily", "inet6"); - map.put("sockPeerAddr", "1:2:3:4::"); - map.put("sockPeerPort", "42"); - map.put("sockHostAddr", "4:3:2:1::"); - map.put("sockHostPort", "8080"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, null, null); - - // then - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), - entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"), - entry(SemanticAttributes.NET_HOST_PORT, 80L), - entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"), - entry(SemanticAttributes.SERVER_PORT, 80L), - entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6")); - - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"), - entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L), - entry(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4:3:2:1::"), - entry(NetworkAttributes.NETWORK_LOCAL_PORT, 8080L), - entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), - entry(SemanticAttributes.NET_SOCK_PEER_PORT, 42L), - entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"), - entry(NetworkAttributes.NETWORK_PEER_PORT, 42L), - entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), - entry(SemanticAttributes.NETWORK_TYPE, "ipv6"), - entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), - entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1")); - } -} 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 deleted file mode 100644 index 62952e3e27c5..000000000000 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorStableSemconvTest.java +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; -import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; -import io.opentelemetry.instrumentation.api.internal.HttpConstants; -import io.opentelemetry.semconv.SemanticAttributes; -import java.net.ConnectException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.function.ToIntFunction; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ArgumentsSource; -import org.junit.jupiter.params.provider.ValueSource; - -class HttpClientAttributesExtractorStableSemconvTest { - - static class TestHttpClientAttributesGetter - implements HttpClientAttributesGetter, Map> { - - @Override - public String getUrlFull(Map request) { - return request.get("urlFull"); - } - - @Override - public String getHttpRequestMethod(Map request) { - return request.get("method"); - } - - @Override - public List getHttpRequestHeader(Map request, String name) { - String value = request.get("header." + name); - return value == null ? emptyList() : asList(value.split(",")); - } - - @Override - public Integer getHttpResponseStatusCode( - Map request, Map response, @Nullable Throwable error) { - String value = response.get("statusCode"); - return value == null ? null : Integer.parseInt(value); - } - - @Override - public List getHttpResponseHeader( - Map request, Map response, String name) { - String value = response.get("header." + name); - return value == null ? emptyList() : asList(value.split(",")); - } - - @Nullable - @Override - public String getNetworkTransport( - Map request, @Nullable Map response) { - return request.get("networkTransport"); - } - - @Nullable - @Override - public String getNetworkType( - Map request, @Nullable Map response) { - return request.get("networkType"); - } - - @Nullable - @Override - public String getNetworkProtocolName( - Map request, @Nullable Map response) { - return request.get("networkProtocolName"); - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - Map request, @Nullable Map response) { - return request.get("networkProtocolVersion"); - } - - @Nullable - @Override - public String getNetworkPeerAddress( - Map request, @Nullable Map response) { - return request.get("networkPeerAddress"); - } - - @Nullable - @Override - public Integer getNetworkPeerPort( - Map request, @Nullable Map response) { - String value = request.get("networkPeerPort"); - return value == null ? null : Integer.parseInt(value); - } - - @Nullable - @Override - public String getServerAddress(Map request) { - return request.get("serverAddress"); - } - - @Nullable - @Override - public Integer getServerPort(Map request) { - String value = request.get("serverPort"); - return value == null ? null : Integer.parseInt(value); - } - - @Nullable - @Override - public String getErrorType( - Map request, - @Nullable Map respobse, - @Nullable Throwable error) { - return request.get("errorType"); - } - } - - @Test - void normal() { - Map request = new HashMap<>(); - request.put("method", "POST"); - request.put("urlFull", "http://github.com"); - request.put("header.content-length", "10"); - request.put("header.user-agent", "okhttp 3.x"); - request.put("header.custom-request-header", "123,456"); - request.put("networkTransport", "udp"); - request.put("networkType", "ipv4"); - request.put("networkProtocolName", "http"); - request.put("networkProtocolVersion", "1.1"); - request.put("networkPeerAddress", "4.3.2.1"); - request.put("networkPeerPort", "456"); - request.put("serverAddress", "github.com"); - request.put("serverPort", "80"); - - Map response = new HashMap<>(); - response.put("statusCode", "202"); - response.put("header.content-length", "20"); - response.put("header.custom-response-header", "654,321"); - - ToIntFunction resendCountFromContext = context -> 2; - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()) - .setCapturedRequestHeaders(singletonList("Custom-Request-Header")) - .setCapturedResponseHeaders(singletonList("Custom-Response-Header")) - .setResendCountIncrementer(resendCountFromContext) - .build(); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), - entry(SemanticAttributes.URL_FULL, "http://github.com"), - entry( - AttributeKey.stringArrayKey("http.request.header.custom-request-header"), - asList("123", "456")), - entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), - entry(SemanticAttributes.SERVER_PORT, 80L), - entry(HttpAttributes.HTTP_REQUEST_RESEND_COUNT, 2L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), - entry( - AttributeKey.stringArrayKey("http.response.header.custom-response-header"), - asList("654", "321")), - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), - entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"), - entry(NetworkAttributes.NETWORK_PEER_PORT, 456L)); - } - - @ParameterizedTest - @ArgumentsSource(ValidRequestMethodsProvider.class) - void shouldExtractKnownMethods(String requestMethod) { - Map request = new HashMap<>(); - request.put("method", requestMethod); - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod) - .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL); - } - - @ParameterizedTest - @ValueSource(strings = {"get", "Get"}) - void shouldTreatMethodsAsCaseSensitive(String requestMethod) { - Map request = new HashMap<>(); - request.put("method", requestMethod); - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); - } - - @ParameterizedTest - @ValueSource(strings = {"PURGE", "not a method really"}) - void shouldUseOtherForUnknownMethods(String requestMethod) { - Map request = new HashMap<>(); - request.put("method", requestMethod); - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); - } - - @ParameterizedTest - @ValueSource(strings = {"only", "custom", "methods", "allowed"}) - void shouldExtractKnownMethods_override(String requestMethod) { - Map request = new HashMap<>(); - request.put("method", requestMethod); - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()) - .setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed"))) - .build(); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod) - .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL); - } - - @ParameterizedTest - @ArgumentsSource(ValidRequestMethodsProvider.class) - void shouldUseOtherForUnknownMethods_override(String requestMethod) { - Map request = new HashMap<>(); - request.put("method", requestMethod); - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()) - .setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed"))) - .build(); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); - } - - @Test - void shouldExtractErrorType_httpStatusCode() { - Map response = new HashMap<>(); - response.put("statusCode", "400"); - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), emptyMap()); - extractor.onEnd(attributes, Context.root(), emptyMap(), response, null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 400) - .containsEntry(HttpAttributes.ERROR_TYPE, "400"); - } - - @Test - void shouldExtractErrorType_getter() { - Map request = new HashMap<>(); - request.put("statusCode", "0"); - request.put("errorType", "custom error type"); - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), emptyMap()); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, "custom error type"); - } - - @Test - void shouldExtractErrorType_exceptionClassName() { - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), emptyMap()); - extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), new ConnectException()); - - assertThat(attributes.build()) - .containsEntry(HttpAttributes.ERROR_TYPE, "java.net.ConnectException"); - } - - @Test - void shouldExtractErrorType_other() { - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), emptyMap()); - extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), null); - - assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, HttpConstants._OTHER); - } - - @Test - void shouldExtractServerAddressAndPortFromHostHeader() { - Map request = new HashMap<>(); - request.put("header.host", "github.com:123"); - - Map response = new HashMap<>(); - response.put("statusCode", "200"); - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), - entry(SemanticAttributes.SERVER_PORT, 123L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); - } - - @Test - void shouldExtractPeerAddressEvenIfItDuplicatesServerAddress() { - Map request = new HashMap<>(); - request.put("networkPeerAddress", "1.2.3.4"); - request.put("networkPeerPort", "456"); - request.put("serverAddress", "1.2.3.4"); - request.put("serverPort", "123"); - - Map response = new HashMap<>(); - response.put("statusCode", "200"); - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_ADDRESS, "1.2.3.4"), - entry(SemanticAttributes.SERVER_PORT, 123L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), - entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"), - entry(NetworkAttributes.NETWORK_PEER_PORT, 456L)); - } - - @Test - void shouldExtractProtocolNameDifferentFromHttp() { - Map request = new HashMap<>(); - request.put("networkProtocolName", "spdy"); - request.put("networkProtocolVersion", "3.1"); - - Map response = new HashMap<>(); - response.put("statusCode", "200"); - - AttributesExtractor, Map> extractor = - HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()).isEmpty(); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), - entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "spdy"), - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "3.1")); - } -} 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 deleted file mode 100644 index cc0fc2669c0f..000000000000 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientExperimentalMetricsStableSemconvTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanContext; -import io.opentelemetry.api.trace.TraceFlags; -import io.opentelemetry.api.trace.TraceState; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; -import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; -import io.opentelemetry.sdk.metrics.SdkMeterProvider; -import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.Test; - -class HttpClientExperimentalMetricsStableSemconvTest { - - @Test - void collectsMetrics() { - InMemoryMetricReader metricReader = InMemoryMetricReader.create(); - SdkMeterProvider meterProvider = - SdkMeterProvider.builder().registerMetricReader(metricReader).build(); - - OperationListener listener = - HttpClientExperimentalMetrics.get().create(meterProvider.get("test")); - - Attributes requestAttributes = - Attributes.builder() - .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET") - .put(SemanticAttributes.URL_FULL, "https://localhost:1234/") - .put(SemanticAttributes.URL_PATH, "/") - .put(SemanticAttributes.URL_QUERY, "q=a") - .put(SemanticAttributes.SERVER_ADDRESS, "localhost") - .put(SemanticAttributes.SERVER_PORT, 1234) - .build(); - - Attributes responseAttributes = - Attributes.builder() - .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200) - .put(HttpAttributes.ERROR_TYPE, "400") - .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100) - .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) - .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http") - .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0") - .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") - .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) - .build(); - - Context parent = - Context.root() - .with( - Span.wrap( - SpanContext.create( - "ff01020304050600ff0a0b0c0d0e0f00", - "090a0b0c0d0e0f00", - TraceFlags.getSampled(), - TraceState.getDefault()))); - - Context context1 = listener.onStart(parent, requestAttributes, nanos(100)); - - assertThat(metricReader.collectAllMetrics()).isEmpty(); - - Context context2 = listener.onStart(Context.root(), requestAttributes, nanos(150)); - - assertThat(metricReader.collectAllMetrics()).isEmpty(); - - listener.onEnd(context1, responseAttributes, nanos(250)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("http.client.request.size") - .hasUnit("By") - .hasDescription("Size of HTTP client request bodies.") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(100 /* bytes */) - .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), - equalTo( - SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), - equalTo(HttpAttributes.ERROR_TYPE, "400"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), - equalTo(SemanticAttributes.SERVER_PORT, 1234)) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") - .hasSpanId("090a0b0c0d0e0f00")))), - metric -> - assertThat(metric) - .hasName("http.client.response.size") - .hasUnit("By") - .hasDescription("Size of HTTP client response bodies.") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(200 /* bytes */) - .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), - equalTo( - SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), - equalTo(HttpAttributes.ERROR_TYPE, "400"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), - equalTo(SemanticAttributes.SERVER_PORT, 1234)) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") - .hasSpanId("090a0b0c0d0e0f00"))))); - - listener.onEnd(context2, responseAttributes, nanos(300)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("http.client.request.size") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying(point -> point.hasSum(200 /* bytes */))), - metric -> - assertThat(metric) - .hasName("http.client.response.size") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying(point -> point.hasSum(400 /* bytes */)))); - } - - private static long nanos(int millis) { - return TimeUnit.MILLISECONDS.toNanos(millis); - } -} 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 deleted file mode 100644 index 47669bd97147..000000000000 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanContext; -import io.opentelemetry.api.trace.TraceFlags; -import io.opentelemetry.api.trace.TraceState; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; -import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; -import io.opentelemetry.sdk.metrics.SdkMeterProvider; -import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.Test; - -class HttpClientMetricsStableSemconvTest { - - static final double[] DURATION_BUCKETS = - HttpMetricsUtil.DURATION_SECONDS_BUCKETS.stream().mapToDouble(d -> d).toArray(); - - @Test - void collectsMetrics() { - InMemoryMetricReader metricReader = InMemoryMetricReader.create(); - SdkMeterProvider meterProvider = - SdkMeterProvider.builder().registerMetricReader(metricReader).build(); - - OperationListener listener = HttpClientMetrics.get().create(meterProvider.get("test")); - - Attributes requestAttributes = - Attributes.builder() - .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET") - .put(SemanticAttributes.URL_FULL, "https://localhost:1234/") - .put(SemanticAttributes.URL_PATH, "/") - .put(SemanticAttributes.URL_QUERY, "q=a") - .put(SemanticAttributes.SERVER_ADDRESS, "localhost") - .put(SemanticAttributes.SERVER_PORT, 1234) - .build(); - - Attributes responseAttributes = - Attributes.builder() - .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200) - .put(HttpAttributes.ERROR_TYPE, "400") - .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100) - .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) - .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http") - .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0") - .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") - .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) - .build(); - - Context parent = - Context.root() - .with( - Span.wrap( - SpanContext.create( - "ff01020304050600ff0a0b0c0d0e0f00", - "090a0b0c0d0e0f00", - TraceFlags.getSampled(), - TraceState.getDefault()))); - - Context context1 = listener.onStart(parent, requestAttributes, nanos(100)); - - assertThat(metricReader.collectAllMetrics()).isEmpty(); - - Context context2 = listener.onStart(Context.root(), requestAttributes, nanos(150)); - - assertThat(metricReader.collectAllMetrics()).isEmpty(); - - listener.onEnd(context1, responseAttributes, nanos(250)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("http.client.request.duration") - .hasUnit("s") - .hasDescription("Duration of HTTP client requests.") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(0.15 /* seconds */) - .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), - equalTo( - SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), - equalTo(HttpAttributes.ERROR_TYPE, "400"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), - equalTo(SemanticAttributes.SERVER_PORT, 1234)) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") - .hasSpanId("090a0b0c0d0e0f00")) - .hasBucketBoundaries(DURATION_BUCKETS)))); - - listener.onEnd(context2, responseAttributes, nanos(300)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("http.client.request.duration") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> point.hasSum(0.3 /* seconds */)))); - } - - private static long nanos(int millis) { - return TimeUnit.MILLISECONDS.toNanos(millis); - } -} 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 deleted file mode 100644 index d61ad91a7f74..000000000000 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorStableSemconvTest.java +++ /dev/null @@ -1,555 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; -import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; -import io.opentelemetry.instrumentation.api.internal.HttpConstants; -import io.opentelemetry.semconv.SemanticAttributes; -import java.net.ConnectException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ArgumentsSource; -import org.junit.jupiter.params.provider.ValueSource; - -class HttpServerAttributesExtractorStableSemconvTest { - - static class TestHttpServerAttributesGetter - implements HttpServerAttributesGetter, Map> { - - @Override - public String getHttpRequestMethod(Map request) { - return request.get("method"); - } - - @Override - public String getUrlScheme(Map request) { - return request.get("urlScheme"); - } - - @Nullable - @Override - public String getUrlPath(Map request) { - return request.get("urlPath"); - } - - @Nullable - @Override - public String getUrlQuery(Map request) { - return request.get("urlQuery"); - } - - @Override - public String getHttpRoute(Map request) { - return request.get("route"); - } - - @Override - public List getHttpRequestHeader(Map request, String name) { - String values = request.get("header." + name); - return values == null ? emptyList() : asList(values.split(",")); - } - - @Override - public Integer getHttpResponseStatusCode( - Map request, Map response, @Nullable Throwable error) { - String value = response.get("statusCode"); - return value == null ? null : Integer.parseInt(value); - } - - @Override - public List getHttpResponseHeader( - Map request, Map response, String name) { - String values = response.get("header." + name); - return values == null ? emptyList() : asList(values.split(",")); - } - - @Nullable - @Override - public String getNetworkTransport( - Map request, @Nullable Map response) { - return request.get("networkTransport"); - } - - @Nullable - @Override - public String getNetworkType( - Map request, @Nullable Map response) { - return request.get("networkType"); - } - - @Nullable - @Override - public String getNetworkProtocolName( - Map request, Map response) { - return request.get("networkProtocolName"); - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - Map request, Map response) { - return request.get("networkProtocolVersion"); - } - - @Nullable - @Override - public String getNetworkLocalAddress( - Map request, @Nullable Map response) { - return request.get("networkLocalAddress"); - } - - @Nullable - @Override - public Integer getNetworkLocalPort( - Map request, @Nullable Map response) { - String value = request.get("networkLocalPort"); - return value == null ? null : Integer.parseInt(value); - } - - @Nullable - @Override - public String getNetworkPeerAddress( - Map request, @Nullable Map response) { - return request.get("networkPeerAddress"); - } - - @Nullable - @Override - public Integer getNetworkPeerPort( - Map request, @Nullable Map response) { - String value = request.get("networkPeerPort"); - return value == null ? null : Integer.parseInt(value); - } - - @Nullable - @Override - public String getErrorType( - Map request, - @Nullable Map respobse, - @Nullable Throwable error) { - return request.get("errorType"); - } - } - - @Test - void normal() { - Map request = new HashMap<>(); - request.put("method", "POST"); - request.put("urlFull", "https://github.com"); - request.put("urlPath", "/repositories/1"); - request.put("urlQuery", "details=true"); - request.put("urlScheme", "https"); - 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:443"); - request.put("header.forwarded", "for=1.1.1.1;proto=https"); - request.put("header.custom-request-header", "123,456"); - request.put("networkTransport", "udp"); - request.put("networkType", "ipv4"); - request.put("networkProtocolName", "http"); - request.put("networkProtocolVersion", "2.0"); - request.put("networkLocalAddress", "1.2.3.4"); - request.put("networkLocalPort", "42"); - request.put("networkPeerAddress", "4.3.2.1"); - request.put("networkPeerPort", "456"); - - Map response = new HashMap<>(); - response.put("statusCode", "202"); - response.put("header.content-length", "20"); - response.put("header.custom-response-header", "654,321"); - - Function routeFromContext = ctx -> "/repositories/{repoId}"; - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) - .setCapturedRequestHeaders(singletonList("Custom-Request-Header")) - .setCapturedResponseHeaders(singletonList("Custom-Response-Header")) - .setHttpRouteGetter(routeFromContext) - .build(); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), - entry(SemanticAttributes.SERVER_PORT, 443L), - entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), - entry(SemanticAttributes.URL_SCHEME, "https"), - entry(SemanticAttributes.URL_PATH, "/repositories/1"), - entry(SemanticAttributes.URL_QUERY, "details=true"), - entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"), - entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{id}"), - entry(SemanticAttributes.CLIENT_ADDRESS, "1.1.1.1"), - entry( - AttributeKey.stringArrayKey("http.request.header.custom-request-header"), - asList("123", "456"))); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), - entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"), - entry(NetworkAttributes.NETWORK_PEER_PORT, 456L), - entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"), - entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), - entry( - AttributeKey.stringArrayKey("http.response.header.custom-response-header"), - asList("654", "321"))); - } - - @ParameterizedTest - @ArgumentsSource(ValidRequestMethodsProvider.class) - void shouldExtractKnownMethods(String requestMethod) { - Map request = new HashMap<>(); - request.put("method", requestMethod); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod) - .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL); - } - - @ParameterizedTest - @ValueSource(strings = {"get", "Get"}) - void shouldTreatMethodsAsCaseSensitive(String requestMethod) { - Map request = new HashMap<>(); - request.put("method", requestMethod); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); - } - - @ParameterizedTest - @ValueSource(strings = {"PURGE", "not a method really"}) - void shouldUseOtherForUnknownMethods(String requestMethod) { - Map request = new HashMap<>(); - request.put("method", requestMethod); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); - } - - @ParameterizedTest - @ValueSource(strings = {"only", "custom", "methods", "allowed"}) - void shouldExtractKnownMethods_override(String requestMethod) { - Map request = new HashMap<>(); - request.put("method", requestMethod); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) - .setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed"))) - .build(); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod) - .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL); - } - - @ParameterizedTest - @ArgumentsSource(ValidRequestMethodsProvider.class) - void shouldUseOtherForUnknownMethods_override(String requestMethod) { - Map request = new HashMap<>(); - request.put("method", requestMethod); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter()) - .setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed"))) - .build(); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), request); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) - .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); - } - - @Test - void shouldExtractErrorType_httpStatusCode() { - Map response = new HashMap<>(); - response.put("statusCode", "500"); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), emptyMap()); - extractor.onEnd(attributes, Context.root(), emptyMap(), response, null); - - assertThat(attributes.build()) - .containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 500) - .containsEntry(HttpAttributes.ERROR_TYPE, "500"); - } - - @Test - void shouldExtractErrorType_getter() { - Map request = new HashMap<>(); - request.put("statusCode", "0"); - request.put("errorType", "custom error type"); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), emptyMap()); - extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); - - assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, "custom error type"); - } - - @Test - void shouldExtractErrorType_exceptionClassName() { - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), emptyMap()); - extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), new ConnectException()); - - assertThat(attributes.build()) - .containsEntry(HttpAttributes.ERROR_TYPE, "java.net.ConnectException"); - } - - @Test - void shouldExtractErrorType_other() { - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, Context.root(), emptyMap()); - extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), null); - - assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, HttpConstants._OTHER); - } - - @Test - void shouldPreferUrlSchemeFromForwardedHeader() { - Map request = new HashMap<>(); - request.put("urlScheme", "http"); - request.put("header.forwarded", "proto=https"); - - Map response = new HashMap<>(); - response.put("statusCode", "202"); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()).containsOnly(entry(SemanticAttributes.URL_SCHEME, "https")); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L)); - } - - @Test - void shouldExtractServerAddressAndPortFromForwardedHeader() { - Map request = new HashMap<>(); - request.put("header.forwarded", "host=example.com:42"); - request.put("header.x-forwarded-host", "opentelemetry.io:987"); - request.put("header.host", "github.com:123"); - request.put("header.:authority", "opentelemetry.io:42"); - - Map response = new HashMap<>(); - response.put("statusCode", "200"); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_ADDRESS, "example.com"), - entry(SemanticAttributes.SERVER_PORT, 42L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); - } - - @Test - void shouldExtractServerAddressAndPortFromForwardedHostHeader() { - Map request = new HashMap<>(); - request.put("header.x-forwarded-host", "opentelemetry.io:987"); - request.put("header.host", "github.com:123"); - request.put("header.:authority", "opentelemetry.io:42"); - - Map response = new HashMap<>(); - response.put("statusCode", "200"); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"), - entry(SemanticAttributes.SERVER_PORT, 987L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); - } - - @Test - void shouldExtractServerAddressAndPortFromAuthorityPseudoHeader() { - Map request = new HashMap<>(); - request.put("header.:authority", "opentelemetry.io:42"); - request.put("header.host", "github.com:123"); - - Map response = new HashMap<>(); - response.put("statusCode", "200"); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"), - entry(SemanticAttributes.SERVER_PORT, 42L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); - } - - @Test - void shouldExtractServerAddressAndPortFromHostHeader() { - Map request = new HashMap<>(); - request.put("header.host", "github.com:123"); - - Map response = new HashMap<>(); - response.put("statusCode", "200"); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_ADDRESS, "github.com"), - entry(SemanticAttributes.SERVER_PORT, 123L)); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); - } - - @Test - void shouldExtractPeerAddressEvenIfItDuplicatesClientAddress() { - Map request = new HashMap<>(); - request.put("networkPeerAddress", "1.2.3.4"); - request.put("networkPeerPort", "456"); - request.put("header.forwarded", "for=1.2.3.4:123"); - - Map response = new HashMap<>(); - response.put("statusCode", "200"); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()) - .containsOnly(entry(SemanticAttributes.CLIENT_ADDRESS, "1.2.3.4")); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), - entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"), - entry(NetworkAttributes.NETWORK_PEER_PORT, 456L)); - } - - @Test - void shouldExtractProtocolNameDifferentFromHttp() { - Map request = new HashMap<>(); - request.put("networkProtocolName", "spdy"); - request.put("networkProtocolVersion", "3.1"); - - Map response = new HashMap<>(); - response.put("statusCode", "200"); - - AttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter()); - - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, Context.root(), request); - assertThat(startAttributes.build()).isEmpty(); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, Context.root(), request, response, null); - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), - entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "spdy"), - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "3.1")); - } -} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerExperimentalMetricsStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerExperimentalMetricsStableSemconvTest.java deleted file mode 100644 index b313794577c0..000000000000 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerExperimentalMetricsStableSemconvTest.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanContext; -import io.opentelemetry.api.trace.TraceFlags; -import io.opentelemetry.api.trace.TraceState; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; -import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; -import io.opentelemetry.sdk.metrics.SdkMeterProvider; -import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.Test; - -class HttpServerExperimentalMetricsStableSemconvTest { - - @Test - void collectsMetrics() { - InMemoryMetricReader metricReader = InMemoryMetricReader.create(); - SdkMeterProvider meterProvider = - SdkMeterProvider.builder().registerMetricReader(metricReader).build(); - - OperationListener listener = - HttpServerExperimentalMetrics.get().create(meterProvider.get("test")); - - Attributes requestAttributes = - Attributes.builder() - .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET") - .put(SemanticAttributes.URL_SCHEME, "https") - .put(SemanticAttributes.URL_PATH, "/") - .put(SemanticAttributes.URL_QUERY, "q=a") - .put(SemanticAttributes.NETWORK_TRANSPORT, "tcp") - .put(SemanticAttributes.NETWORK_TYPE, "ipv4") - .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http") - .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0") - .put(SemanticAttributes.SERVER_ADDRESS, "localhost") - .put(SemanticAttributes.SERVER_PORT, 1234) - .build(); - - Attributes responseAttributes = - Attributes.builder() - .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200) - .put(HttpAttributes.ERROR_TYPE, "500") - .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100) - .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) - .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") - .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) - .put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4.3.2.1") - .put(NetworkAttributes.NETWORK_LOCAL_PORT, 9090) - .build(); - - SpanContext spanContext1 = - SpanContext.create( - "ff01020304050600ff0a0b0c0d0e0f00", - "090a0b0c0d0e0f00", - TraceFlags.getSampled(), - TraceState.getDefault()); - SpanContext spanContext2 = - SpanContext.create( - "123456789abcdef00000000000999999", - "abcde00000054321", - TraceFlags.getSampled(), - TraceState.getDefault()); - - Context parent1 = Context.root().with(Span.wrap(spanContext1)); - Context context1 = listener.onStart(parent1, requestAttributes, nanos(100)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("http.server.active_requests") - .hasUnit("{requests}") - .hasDescription("Number of active HTTP server requests.") - .hasLongSumSatisfying( - sum -> - sum.hasPointsSatisfying( - point -> - point - .hasValue(1) - .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), - equalTo(SemanticAttributes.URL_SCHEME, "https")) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId(spanContext1.getTraceId()) - .hasSpanId(spanContext1.getSpanId()))))); - - Context parent2 = Context.root().with(Span.wrap(spanContext2)); - Context context2 = listener.onStart(parent2, requestAttributes, nanos(150)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("http.server.active_requests") - .hasLongSumSatisfying( - sum -> - sum.hasPointsSatisfying( - point -> - point - .hasValue(2) - .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), - equalTo(SemanticAttributes.URL_SCHEME, "https")) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId(spanContext2.getTraceId()) - .hasSpanId(spanContext2.getSpanId()))))); - - listener.onEnd(context1, responseAttributes, nanos(250)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("http.server.active_requests") - .hasLongSumSatisfying( - sum -> - sum.hasPointsSatisfying( - point -> - point - .hasValue(1) - .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), - equalTo(SemanticAttributes.URL_SCHEME, "https")) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId(spanContext1.getTraceId()) - .hasSpanId(spanContext1.getSpanId())))), - metric -> - assertThat(metric) - .hasName("http.server.request.size") - .hasUnit("By") - .hasDescription("Size of HTTP server request bodies.") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(100 /* bytes */) - .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), - equalTo( - SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), - equalTo(HttpAttributes.ERROR_TYPE, "500"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.URL_SCHEME, "https")) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId(spanContext1.getTraceId()) - .hasSpanId(spanContext1.getSpanId())))), - metric -> - assertThat(metric) - .hasName("http.server.response.size") - .hasUnit("By") - .hasDescription("Size of HTTP server response bodies.") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(200 /* bytes */) - .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), - equalTo( - SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), - equalTo(HttpAttributes.ERROR_TYPE, "500"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.URL_SCHEME, "https")) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId(spanContext1.getTraceId()) - .hasSpanId(spanContext1.getSpanId()))))); - - listener.onEnd(context2, responseAttributes, nanos(300)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("http.server.active_requests") - .hasLongSumSatisfying( - sum -> - sum.hasPointsSatisfying( - point -> - point - .hasValue(0) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId(spanContext2.getTraceId()) - .hasSpanId(spanContext2.getSpanId())))), - metric -> - assertThat(metric) - .hasName("http.server.request.size") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(200 /* bytes */) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId(spanContext2.getTraceId()) - .hasSpanId(spanContext2.getSpanId())))), - metric -> - assertThat(metric) - .hasName("http.server.response.size") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(400 /* bytes */) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId(spanContext2.getTraceId()) - .hasSpanId(spanContext2.getSpanId()))))); - } - - private static long nanos(int millis) { - return TimeUnit.MILLISECONDS.toNanos(millis); - } -} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsStableSemconvTest.java deleted file mode 100644 index 57776bf00e87..000000000000 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsStableSemconvTest.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanContext; -import io.opentelemetry.api.trace.TraceFlags; -import io.opentelemetry.api.trace.TraceState; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; -import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; -import io.opentelemetry.sdk.metrics.SdkMeterProvider; -import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.Test; - -class HttpServerMetricsStableSemconvTest { - - static final double[] DURATION_BUCKETS = - HttpMetricsUtil.DURATION_SECONDS_BUCKETS.stream().mapToDouble(d -> d).toArray(); - - @Test - void collectsMetrics() { - InMemoryMetricReader metricReader = InMemoryMetricReader.create(); - SdkMeterProvider meterProvider = - SdkMeterProvider.builder().registerMetricReader(metricReader).build(); - - OperationListener listener = HttpServerMetrics.get().create(meterProvider.get("test")); - - Attributes requestAttributes = - Attributes.builder() - .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET") - .put(SemanticAttributes.URL_SCHEME, "https") - .put(SemanticAttributes.URL_PATH, "/") - .put(SemanticAttributes.URL_QUERY, "q=a") - .put(SemanticAttributes.NETWORK_TRANSPORT, "tcp") - .put(SemanticAttributes.NETWORK_TYPE, "ipv4") - .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http") - .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0") - .put(SemanticAttributes.SERVER_ADDRESS, "localhost") - .put(SemanticAttributes.SERVER_PORT, 1234) - .build(); - - Attributes responseAttributes = - Attributes.builder() - .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200) - .put(HttpAttributes.ERROR_TYPE, "500") - .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100) - .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200) - .put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4") - .put(NetworkAttributes.NETWORK_PEER_PORT, 8080) - .put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4.3.2.1") - .put(NetworkAttributes.NETWORK_LOCAL_PORT, 9090) - .build(); - - SpanContext spanContext1 = - SpanContext.create( - "ff01020304050600ff0a0b0c0d0e0f00", - "090a0b0c0d0e0f00", - TraceFlags.getSampled(), - TraceState.getDefault()); - SpanContext spanContext2 = - SpanContext.create( - "123456789abcdef00000000000999999", - "abcde00000054321", - TraceFlags.getSampled(), - TraceState.getDefault()); - - Context parent1 = Context.root().with(Span.wrap(spanContext1)); - Context context1 = listener.onStart(parent1, requestAttributes, nanos(100)); - - Context parent2 = Context.root().with(Span.wrap(spanContext2)); - Context context2 = listener.onStart(parent2, requestAttributes, nanos(150)); - - listener.onEnd(context1, responseAttributes, nanos(250)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("http.server.request.duration") - .hasDescription("Duration of HTTP server requests.") - .hasUnit("s") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(0.15 /* seconds */) - .hasAttributesSatisfying( - equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), - equalTo( - SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), - equalTo(HttpAttributes.ERROR_TYPE, "500"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - equalTo( - SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), - equalTo(SemanticAttributes.URL_SCHEME, "https")) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId(spanContext1.getTraceId()) - .hasSpanId(spanContext1.getSpanId())) - .hasBucketBoundaries(DURATION_BUCKETS)))); - - listener.onEnd(context2, responseAttributes, nanos(300)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("http.server.request.duration") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(0.3 /* seconds */) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId(spanContext2.getTraceId()) - .hasSpanId(spanContext2.getSpanId()))))); - } - - @Test - void collectsHttpRouteFromEndAttributes() { - // given - InMemoryMetricReader metricReader = InMemoryMetricReader.create(); - SdkMeterProvider meterProvider = - SdkMeterProvider.builder().registerMetricReader(metricReader).build(); - - OperationListener listener = HttpServerMetrics.get().create(meterProvider.get("test")); - - Attributes requestAttributes = - Attributes.builder() - .put(SemanticAttributes.SERVER_ADDRESS, "host") - .put(SemanticAttributes.URL_SCHEME, "https") - .build(); - - Attributes responseAttributes = - Attributes.builder().put(SemanticAttributes.HTTP_ROUTE, "/test/{id}").build(); - - Context parentContext = Context.root(); - - // when - Context context = listener.onStart(parentContext, requestAttributes, nanos(100)); - listener.onEnd(context, responseAttributes, nanos(200)); - - // then - assertThat(metricReader.collectAllMetrics()) - .anySatisfy( - metric -> - assertThat(metric) - .hasName("http.server.request.duration") - .hasUnit("s") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(0.100 /* seconds */) - .hasAttributesSatisfying( - equalTo(SemanticAttributes.URL_SCHEME, "https"), - equalTo( - SemanticAttributes.HTTP_ROUTE, "/test/{id}"))))); - } - - private static long nanos(int millis) { - return TimeUnit.MILLISECONDS.toNanos(millis); - } -} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorStableSemconvTest.java deleted file mode 100644 index ee6d78dab425..000000000000 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorStableSemconvTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.net; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -@SuppressWarnings("deprecation") // testing deprecated class -class NetClientAttributesExtractorStableSemconvTest { - - static class TestNetClientAttributesGetter - implements NetClientAttributesGetter, Map> { - - @Override - public String getTransport(Map request, Map response) { - return response.get("netTransport"); - } - - @Nullable - @Override - public String getNetworkTransport( - Map request, @Nullable Map response) { - return request.get("transport"); - } - - @Nullable - @Override - public String getNetworkType( - Map request, @Nullable Map response) { - return request.get("type"); - } - - @Nullable - @Override - public String getNetworkProtocolName( - Map request, @Nullable Map response) { - return request.get("protocolName"); - } - - @Nullable - @Override - public String getNetworkProtocolVersion( - Map request, @Nullable Map response) { - return request.get("protocolVersion"); - } - - @Override - public String getServerAddress(Map request) { - return request.get("peerName"); - } - - @Override - public Integer getServerPort(Map request) { - String peerPort = request.get("peerPort"); - return peerPort == null ? null : Integer.valueOf(peerPort); - } - - @Override - public String getSockFamily(Map request, Map response) { - return response.get("sockFamily"); - } - - @Override - public String getNetworkPeerAddress(Map request, Map response) { - return response.get("sockPeerAddr"); - } - - @Override - public Integer getNetworkPeerPort(Map request, Map response) { - String sockPeerPort = response.get("sockPeerPort"); - return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort); - } - } - - private final AttributesExtractor, Map> extractor = - NetClientAttributesExtractor.create(new TestNetClientAttributesGetter()); - - @Test - void normal() { - // given - Map map = new HashMap<>(); - map.put("netTransport", IP_TCP); - map.put("transport", "tcp"); - map.put("type", "ipv6"); - map.put("protocolName", "http"); - map.put("protocolVersion", "1.1"); - map.put("peerName", "opentelemetry.io"); - map.put("peerPort", "42"); - map.put("sockFamily", "inet6"); - map.put("sockPeerAddr", "1:2:3:4::"); - map.put("sockPeerPort", "123"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, map, null); - - // then - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"), - entry(SemanticAttributes.SERVER_PORT, 42L)); - - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), - entry(SemanticAttributes.NETWORK_TYPE, "ipv6"), - entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), - entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"), - entry(NetworkAttributes.NETWORK_PEER_PORT, 123L)); - } -} diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorStableSemconvTest.java deleted file mode 100644 index 38bc5b0eb0ce..000000000000 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorStableSemconvTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter.net; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; -import static org.assertj.core.api.Assertions.entry; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -@SuppressWarnings("deprecation") // testing deprecated class -class NetServerAttributesExtractorStableSemconvTest { - - static class TestNetServerAttributesGetter - implements NetServerAttributesGetter, Void> { - - @Override - public String getTransport(Map request) { - return request.get("netTransport"); - } - - @Nullable - @Override - public String getNetworkTransport(Map request, @Nullable Void response) { - return request.get("transport"); - } - - @Nullable - @Override - public String getNetworkType(Map request, @Nullable Void response) { - return request.get("type"); - } - - @Nullable - @Override - public String getNetworkProtocolName(Map request, Void response) { - return request.get("protocolName"); - } - - @Nullable - @Override - public String getNetworkProtocolVersion(Map request, Void response) { - return request.get("protocolVersion"); - } - - @Nullable - @Override - public String getServerAddress(Map request) { - return request.get("hostName"); - } - - @Nullable - @Override - public Integer getServerPort(Map request) { - String hostPort = request.get("hostPort"); - return hostPort == null ? null : Integer.valueOf(hostPort); - } - - @Nullable - @Override - public String getSockFamily(Map request) { - return request.get("sockFamily"); - } - - @Override - public String getNetworkPeerAddress(Map request, Void response) { - return request.get("sockPeerAddr"); - } - - @Override - public Integer getNetworkPeerPort(Map request, Void response) { - String sockPeerPort = request.get("sockPeerPort"); - return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort); - } - - @Nullable - @Override - public String getNetworkLocalAddress(Map request, Void response) { - return request.get("sockHostAddr"); - } - - @Nullable - @Override - public Integer getNetworkLocalPort(Map request, Void response) { - String sockHostPort = request.get("sockHostPort"); - return sockHostPort == null ? null : Integer.valueOf(sockHostPort); - } - } - - AttributesExtractor, Void> extractor = - NetServerAttributesExtractor.create(new TestNetServerAttributesGetter()); - - @Test - void normal() { - // given - Map map = new HashMap<>(); - map.put("netTransport", IP_TCP); - map.put("transport", "tcp"); - map.put("type", "ipv6"); - map.put("protocolName", "http"); - map.put("protocolVersion", "1.1"); - map.put("hostName", "opentelemetry.io"); - map.put("hostPort", "80"); - map.put("sockFamily", "inet6"); - map.put("sockPeerAddr", "1:2:3:4::"); - map.put("sockPeerPort", "42"); - map.put("sockHostAddr", "4:3:2:1::"); - map.put("sockHostPort", "8080"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, context, map); - - AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, context, map, null, null); - - // then - assertThat(startAttributes.build()) - .containsOnly( - entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"), - entry(SemanticAttributes.SERVER_PORT, 80L)); - - assertThat(endAttributes.build()) - .containsOnly( - entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), - entry(SemanticAttributes.NETWORK_TYPE, "ipv6"), - entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"), - entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), - entry(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4:3:2:1::"), - entry(NetworkAttributes.NETWORK_LOCAL_PORT, 8080L), - entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"), - entry(NetworkAttributes.NETWORK_PEER_PORT, 42L)); - } -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/SemconvStability.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/SemconvStability.java index 6bd928b72b77..c73a17945329 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/SemconvStability.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/SemconvStability.java @@ -16,31 +16,16 @@ */ public final class SemconvStability { - private static final boolean emitOldHttpSemconv; - private static final boolean emitStableHttpSemconv; private static final boolean emitOldJvmSemconv; private static final boolean emitStableJvmSemconv; static { - boolean oldHttp = true; - boolean stableHttp = false; boolean oldJvm = true; boolean stableJvm = false; String value = ConfigPropertiesUtil.getString("otel.semconv-stability.opt-in"); if (value != null) { Set values = new HashSet<>(asList(value.split(","))); - if (values.contains("http")) { - oldHttp = false; - stableHttp = true; - } - // no else -- technically it's possible to set "http,http/dup", in which case we should emit - // both sets of attributes - if (values.contains("http/dup")) { - oldHttp = true; - stableHttp = true; - } - if (values.contains("jvm")) { oldJvm = false; stableJvm = true; @@ -51,18 +36,16 @@ public final class SemconvStability { } } - emitOldHttpSemconv = oldHttp; - emitStableHttpSemconv = stableHttp; emitOldJvmSemconv = oldJvm; emitStableJvmSemconv = stableJvm; } public static boolean emitOldHttpSemconv() { - return emitOldHttpSemconv; + return false; } public static boolean emitStableHttpSemconv() { - return emitStableHttpSemconv; + return true; } public static boolean emitOldJvmSemconv() { diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy b/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy index 584f7fdab75d..2f61a1c298a5 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy @@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.apachedubbo.v2_7 import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.HelloServiceImpl +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.SemanticAttributes @@ -102,11 +103,11 @@ abstract class AbstractDubboTest extends InstrumentationSpecification { "$SemanticAttributes.RPC_SYSTEM" "apache_dubbo" "$SemanticAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService" "$SemanticAttributes.RPC_METHOD" "\$invoke" - "$SemanticAttributes.NET_PEER_NAME" "localhost" - "$SemanticAttributes.NET_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String} - "$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long} - "$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String} + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" Long + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String} + "$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long} + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } } } span(2) { @@ -117,10 +118,9 @@ abstract class AbstractDubboTest extends InstrumentationSpecification { "$SemanticAttributes.RPC_SYSTEM" "apache_dubbo" "$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService" "$SemanticAttributes.RPC_METHOD" "hello" - "$SemanticAttributes.NET_SOCK_PEER_ADDR" String - "$SemanticAttributes.NET_SOCK_PEER_NAME" String - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" String + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } } } } @@ -179,11 +179,11 @@ abstract class AbstractDubboTest extends InstrumentationSpecification { "$SemanticAttributes.RPC_SYSTEM" "apache_dubbo" "$SemanticAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService" "$SemanticAttributes.RPC_METHOD" "\$invokeAsync" - "$SemanticAttributes.NET_PEER_NAME" "localhost" - "$SemanticAttributes.NET_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String} - "$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long} - "$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String} + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" Long + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String} + "$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long} + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } } } span(2) { @@ -194,10 +194,9 @@ abstract class AbstractDubboTest extends InstrumentationSpecification { "$SemanticAttributes.RPC_SYSTEM" "apache_dubbo" "$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService" "$SemanticAttributes.RPC_METHOD" "hello" - "$SemanticAttributes.NET_SOCK_PEER_ADDR" String - "$SemanticAttributes.NET_SOCK_PEER_NAME" String - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" String + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } } } } diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy b/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy index 67fe69e60aea..90fadf562245 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy @@ -10,6 +10,7 @@ import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.HelloServiceImpl import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.MiddleServiceImpl +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.SemanticAttributes @@ -138,11 +139,11 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification "$SemanticAttributes.RPC_SYSTEM" "apache_dubbo" "$SemanticAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService" "$SemanticAttributes.RPC_METHOD" "\$invoke" - "$SemanticAttributes.NET_PEER_NAME" "localhost" - "$SemanticAttributes.NET_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String} - "$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String} - "$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long} + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" Long + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String} + "$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long} + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } } } span(2) { @@ -153,10 +154,9 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification "$SemanticAttributes.RPC_SYSTEM" "apache_dubbo" "$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService" "$SemanticAttributes.RPC_METHOD" "hello" - "$SemanticAttributes.NET_SOCK_PEER_ADDR" String - "$SemanticAttributes.NET_SOCK_PEER_NAME" String - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" String + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } } } span(3) { @@ -167,11 +167,11 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification "$SemanticAttributes.RPC_SYSTEM" "apache_dubbo" "$SemanticAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService" "$SemanticAttributes.RPC_METHOD" "\$invoke" - "$SemanticAttributes.NET_PEER_NAME" "localhost" - "$SemanticAttributes.NET_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String } - "$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long } - "$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" Long + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String } + "$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long } + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } } } span(4) { @@ -182,10 +182,9 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification "$SemanticAttributes.RPC_SYSTEM" "apache_dubbo" "$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService" "$SemanticAttributes.RPC_METHOD" "hello" - "$SemanticAttributes.NET_SOCK_PEER_ADDR" String - "$SemanticAttributes.NET_SOCK_PEER_NAME" String - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" String + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } } } } @@ -256,11 +255,11 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification "$SemanticAttributes.RPC_SYSTEM" "apache_dubbo" "$SemanticAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService" "$SemanticAttributes.RPC_METHOD" "\$invoke" - "$SemanticAttributes.NET_PEER_NAME" "localhost" - "$SemanticAttributes.NET_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String} - "$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long} - "$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String} + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" Long + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String} + "$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long} + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } } } span(2) { @@ -271,10 +270,9 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification "$SemanticAttributes.RPC_SYSTEM" "apache_dubbo" "$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService" "$SemanticAttributes.RPC_METHOD" "hello" - "$SemanticAttributes.NET_SOCK_PEER_ADDR" String - "$SemanticAttributes.NET_SOCK_PEER_NAME" String - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" String + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } } } } diff --git a/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/test/groovy/AbstractCommonsHttpClientTest.groovy b/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/test/groovy/AbstractCommonsHttpClientTest.groovy index 9ceabf5fc463..41452ae2c947 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/test/groovy/AbstractCommonsHttpClientTest.groovy +++ b/instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/test/groovy/AbstractCommonsHttpClientTest.groovy @@ -3,10 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpClientTest -import io.opentelemetry.semconv.SemanticAttributes import org.apache.commons.httpclient.HttpClient import org.apache.commons.httpclient.HttpConnectionManager import org.apache.commons.httpclient.HttpMethod @@ -97,13 +95,4 @@ abstract class AbstractCommonsHttpClientTest extends HttpClientTest boolean testNonStandardHttpMethod() { false } - - @Override - Set> httpAttributes(URI uri) { - Set> extra = [ - SemanticAttributes.HTTP_SCHEME, - SemanticAttributes.HTTP_TARGET - ] - super.httpAttributes(uri) + extra - } } diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/AbstractApacheHttpClientTest.java b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/AbstractApacheHttpClientTest.java index 170b62f80eae..4741d7c9c74b 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/AbstractApacheHttpClientTest.java +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/AbstractApacheHttpClientTest.java @@ -6,7 +6,6 @@ package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0; import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; @@ -33,19 +32,15 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.setHttpAttributes(this::getHttpAttributes); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected Set> getHttpAttributes(URI uri) { Set> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - if (SemconvStability.emitOldHttpSemconv()) { - // unopened port or non routable address; or timeout - // circular redirects don't report protocol information as well - if ("http://localhost:61/".equals(uri.toString()) - || "https://192.0.2.1/".equals(uri.toString()) - || uri.toString().contains("/read-timeout") - || uri.toString().contains("/circular-redirect")) { - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); - } + // unopened port or non routable address; or timeout + // circular redirects don't report protocol information as well + if ("http://localhost:61/".equals(uri.toString()) + || "https://192.0.2.1/".equals(uri.toString()) + || uri.toString().contains("/read-timeout") + || uri.toString().contains("/circular-redirect")) { + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION); } return attributes; } diff --git a/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientTest.java b/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientTest.java index f1bafe1ee87a..ba66f2ca683a 100644 --- a/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientTest.java +++ b/instrumentation/async-http-client/async-http-client-1.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientTest.java @@ -13,7 +13,6 @@ import com.ning.http.client.Response; import com.ning.http.client.uri.Uri; import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; @@ -69,7 +68,7 @@ public void sendRequestWithCallback( request, new AsyncCompletionHandler() { @Override - public Void onCompleted(Response response) throws Exception { + public Void onCompleted(Response response) { requestResult.complete(response.getStatusCode()); return null; } @@ -82,7 +81,6 @@ public void onThrowable(Throwable throwable) { } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.disableTestRedirects(); @@ -90,15 +88,13 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { if (!Boolean.getBoolean("testLatestDeps")) { optionsBuilder.disableTestReadTimeout(); } - if (SemconvStability.emitOldHttpSemconv()) { - optionsBuilder.setHttpAttributes( - endpoint -> { - Set> attributes = - new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); - return attributes; - }); - } + + optionsBuilder.setHttpAttributes( + endpoint -> { + Set> attributes = + new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION); + return attributes; + }); } } diff --git a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/ApiGatewayProxyAttributesExtractor.java b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/ApiGatewayProxyAttributesExtractor.java index bdb42099cbd6..248ff259f6a0 100644 --- a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/ApiGatewayProxyAttributesExtractor.java +++ b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/ApiGatewayProxyAttributesExtractor.java @@ -11,7 +11,6 @@ import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils.lowercaseMap; import static io.opentelemetry.semconv.SemanticAttributes.FAAS_TRIGGER; import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_STATUS_CODE; -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_STATUS_CODE; import static io.opentelemetry.semconv.SemanticAttributes.USER_AGENT_ORIGINAL; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; @@ -19,7 +18,6 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.awslambdacore.v1_0.AwsLambdaRequest; import io.opentelemetry.semconv.SemanticAttributes; import java.io.UnsupportedEncodingException; @@ -47,19 +45,13 @@ public void onStart( } } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void onRequest(AttributesBuilder attributes, APIGatewayProxyRequestEvent request) { String method = request.getHttpMethod(); - if (SemconvStability.emitStableHttpSemconv()) { - if (method == null || knownMethods.contains(method)) { - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method); - } else { - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER); - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); - } - } - if (SemconvStability.emitOldHttpSemconv()) { - internalSet(attributes, SemanticAttributes.HTTP_METHOD, method); + if (method == null || knownMethods.contains(method)) { + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method); + } else { + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER); + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); } Map headers = lowercaseMap(request.getHeaders()); @@ -68,16 +60,7 @@ void onRequest(AttributesBuilder attributes, APIGatewayProxyRequestEvent request attributes.put(USER_AGENT_ORIGINAL, userAgent); } - String httpUrl = getHttpUrl(request, headers); - if (httpUrl != null) { - if (SemconvStability.emitStableHttpSemconv()) { - internalSet(attributes, SemanticAttributes.URL_FULL, httpUrl); - } - - if (SemconvStability.emitOldHttpSemconv()) { - internalSet(attributes, SemanticAttributes.HTTP_URL, httpUrl); - } - } + internalSet(attributes, SemanticAttributes.URL_FULL, getHttpUrl(request, headers)); } private static String getHttpUrl( @@ -113,7 +96,6 @@ private static String getHttpUrl( } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void onEnd( AttributesBuilder attributes, Context context, @@ -123,12 +105,7 @@ public void onEnd( if (response instanceof APIGatewayProxyResponseEvent) { Integer statusCode = ((APIGatewayProxyResponseEvent) response).getStatusCode(); if (statusCode != null) { - if (SemconvStability.emitStableHttpSemconv()) { - attributes.put(HTTP_RESPONSE_STATUS_CODE, statusCode); - } - if (SemconvStability.emitOldHttpSemconv()) { - attributes.put(HTTP_STATUS_CODE, statusCode); - } + attributes.put(HTTP_RESPONSE_STATUS_CODE, statusCode); } } } diff --git a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/test/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/AwsLambdaApiGatewayWrapperTest.java b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/test/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/AwsLambdaApiGatewayWrapperTest.java index e14085a0ab60..56d33bc055ff 100644 --- a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/test/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/AwsLambdaApiGatewayWrapperTest.java +++ b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/test/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/AwsLambdaApiGatewayWrapperTest.java @@ -34,7 +34,6 @@ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public class AwsLambdaApiGatewayWrapperTest { @RegisterExtension @@ -103,12 +102,12 @@ void tracedWithHttpPropagation() { equalTo(ResourceAttributes.CLOUD_ACCOUNT_ID, "123456789"), equalTo(SemanticAttributes.FAAS_INVOCATION_ID, "1-22-333"), equalTo(SemanticAttributes.FAAS_TRIGGER, "http"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo(SemanticAttributes.USER_AGENT_ORIGINAL, "Test Client"), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, "http://localhost:123/hello/world?a=b&c=d"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L)))); + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)))); } @Test diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/S3TracingTest.groovy b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/S3TracingTest.groovy index 987a50ed9576..a0b25f5b28dc 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/S3TracingTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/S3TracingTest.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import spock.lang.Shared @@ -60,15 +61,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "aws.queue.name" queueName "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -85,15 +83,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "PUT" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -110,15 +105,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "aws.queue.url" queueUrl "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -135,15 +127,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "aws.queue.url" queueUrl "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -160,15 +149,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "PUT" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -184,15 +170,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "PUT" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } span(1) { @@ -206,14 +189,15 @@ class S3TracingTest extends AgentInstrumentationSpecification { "aws.queue.url" queueUrl "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.url" String - "net.peer.name" String - "net.peer.port" { it == null || Number } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.SERVER_PORT" { it == null || Number } "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "s3ToSqsTestQueue" "$SemanticAttributes.MESSAGING_OPERATION" "process" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(2) { @@ -235,15 +219,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "GET" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -259,15 +240,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "DELETE" - "http.status_code" 204 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "DELETE" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 204 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -283,15 +261,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "DELETE" - "http.status_code" 204 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "DELETE" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 204 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -307,15 +282,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "aws.queue.url" queueUrl "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -364,15 +336,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "aws.queue.name" queueName "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -388,15 +357,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "aws.queue.url" queueUrl "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -412,15 +378,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "PUT" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -435,15 +398,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.method" "CreateTopic" "rpc.system" "aws-api" "rpc.service" "AmazonSNS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -458,15 +418,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.method" "Subscribe" "rpc.system" "aws-api" "rpc.service" "AmazonSNS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -482,15 +439,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "aws.queue.url" queueUrl "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -505,15 +459,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.method" "SetTopicAttributes" "rpc.system" "aws-api" "rpc.service" "AmazonSNS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -529,15 +480,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "PUT" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -553,15 +501,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "PUT" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -577,16 +522,15 @@ class S3TracingTest extends AgentInstrumentationSpecification { "aws.queue.url" queueUrl "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.url" String - "net.peer.name" String - "net.peer.port" { it == null || Number } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.SERVER_PORT" { it == null || Number } "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "s3ToSnsToSqsTestQueue" "$SemanticAttributes.MESSAGING_OPERATION" "process" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(1) { @@ -608,15 +552,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "GET" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -632,15 +573,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "DELETE" - "http.status_code" 204 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "DELETE" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 204 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -656,15 +594,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Amazon S3" "aws.bucket.name" bucketName - "http.method" "DELETE" - "http.status_code" 204 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "DELETE" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 204 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -680,15 +615,12 @@ class S3TracingTest extends AgentInstrumentationSpecification { "aws.queue.url" queueUrl "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://") } + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/SnsTracingTest.groovy b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/SnsTracingTest.groovy index 97749cf0857f..a251cc11addc 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/SnsTracingTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/SnsTracingTest.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import spock.lang.Shared @@ -52,14 +53,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification { "aws.queue.name" queueName "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" String + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -76,14 +75,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification { "aws.queue.url" queueUrl "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" String + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -100,14 +97,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification { "aws.queue.url" queueUrl "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" String + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -123,14 +118,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification { "rpc.method" "CreateTopic" "rpc.system" "aws-api" "rpc.service" "AmazonSNS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" String + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -146,14 +139,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification { "rpc.method" "Subscribe" "rpc.system" "aws-api" "rpc.service" "AmazonSNS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" String + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } } @@ -168,14 +159,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification { "rpc.method" "Publish" "rpc.system" "aws-api" "rpc.service" "AmazonSNS" - "http.method" "POST" - "http.status_code" 200 - "http.url" String - "net.peer.name" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "net.peer.port" { it == null || Number } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" String + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" { it == null || Number } } } span(1) { @@ -189,14 +178,15 @@ class SnsTracingTest extends AgentInstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "AmazonSQS" "rpc.method" "ReceiveMessage" - "http.method" "POST" - "http.url" String - "net.peer.name" String - "net.peer.port" { it == null || Number } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" String + "$SemanticAttributes.SERVER_ADDRESS" String + "$SemanticAttributes.SERVER_PORT" { it == null || Number } "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "snsToSqsTestQueue" "$SemanticAttributes.MESSAGING_OPERATION" "process" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(2) { diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/awssdk/v1_11/Aws1ClientTest.groovy b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/awssdk/v1_11/Aws1ClientTest.groovy index 41f89e47dd0f..4c83f51722e8 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/awssdk/v1_11/Aws1ClientTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/awssdk/v1_11/Aws1ClientTest.groovy @@ -17,6 +17,7 @@ import com.amazonaws.services.s3.AmazonS3Client import com.amazonaws.services.s3.AmazonS3ClientBuilder import io.opentelemetry.api.trace.Span import io.opentelemetry.api.trace.SpanKind +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.awssdk.v1_11.AbstractAws1ClientTest import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.semconv.SemanticAttributes @@ -99,15 +100,16 @@ class Aws1ClientTest extends AbstractAws1ClientTest implements AgentTestTrait { errorEvent IllegalStateException, "bad handler" hasNoParent() attributes { - "$SemanticAttributes.HTTP_URL" "https://s3.amazonaws.com" - "$SemanticAttributes.HTTP_METHOD" "HEAD" - "$SemanticAttributes.NET_PEER_NAME" "s3.amazonaws.com" + "$SemanticAttributes.URL_FULL" "https://s3.amazonaws.com" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "HEAD" + "$SemanticAttributes.SERVER_ADDRESS" "s3.amazonaws.com" "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" "Amazon S3" "$SemanticAttributes.RPC_METHOD" "HeadBucket" "aws.endpoint" "https://s3.amazonaws.com" "aws.agent" "java-aws-sdk" "aws.bucket.name" "someBucket" + "$HttpAttributes.ERROR_TYPE" IllegalStateException.name } } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test_before_1_11_106/groovy/Aws0ClientTest.groovy b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test_before_1_11_106/groovy/Aws0ClientTest.groovy index 543b6e8e8e40..e977832476df 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test_before_1_11_106/groovy/Aws0ClientTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test_before_1_11_106/groovy/Aws0ClientTest.groovy @@ -23,6 +23,7 @@ import com.amazonaws.services.rds.model.DeleteOptionGroupRequest import com.amazonaws.services.s3.AmazonS3Client import com.amazonaws.services.s3.S3ClientOptions import io.opentelemetry.api.trace.Span +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import io.opentelemetry.testing.internal.armeria.common.HttpResponse @@ -106,14 +107,12 @@ class Aws0ClientTest extends AgentInstrumentationSpecification { kind CLIENT hasNoParent() attributes { - "$SemanticAttributes.HTTP_URL" "${server.httpUri()}" - "$SemanticAttributes.HTTP_METHOD" "$method" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_PEER_PORT" server.httpPort() - "$SemanticAttributes.NET_PEER_NAME" "127.0.0.1" + "$SemanticAttributes.URL_FULL" "${server.httpUri()}" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "$method" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" server.httpPort() + "$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1" "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" { it.contains(service) } "$SemanticAttributes.RPC_METHOD" "${operation}" @@ -170,10 +169,10 @@ class Aws0ClientTest extends AgentInstrumentationSpecification { errorEvent AmazonClientException, ~/Unable to execute HTTP request/ hasNoParent() attributes { - "$SemanticAttributes.HTTP_URL" "http://localhost:${UNUSABLE_PORT}" - "$SemanticAttributes.HTTP_METHOD" "$method" - "$SemanticAttributes.NET_PEER_PORT" 61 - "$SemanticAttributes.NET_PEER_NAME" "localhost" + "$SemanticAttributes.URL_FULL" "http://localhost:${UNUSABLE_PORT}" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "$method" + "$SemanticAttributes.SERVER_PORT" 61 + "$SemanticAttributes.SERVER_ADDRESS" "localhost" "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" { it.contains(service) } "$SemanticAttributes.RPC_METHOD" "${operation}" @@ -182,6 +181,7 @@ class Aws0ClientTest extends AgentInstrumentationSpecification { for (def addedTag : additionalAttributes) { "$addedTag.key" "$addedTag.value" } + "$HttpAttributes.ERROR_TYPE" AmazonClientException.name } } } @@ -217,15 +217,16 @@ class Aws0ClientTest extends AgentInstrumentationSpecification { errorEvent IllegalStateException, "bad handler" hasNoParent() attributes { - "$SemanticAttributes.HTTP_URL" "https://s3.amazonaws.com" - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.NET_PEER_NAME" "s3.amazonaws.com" + "$SemanticAttributes.URL_FULL" "https://s3.amazonaws.com" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.SERVER_ADDRESS" "s3.amazonaws.com" "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" "Amazon S3" "$SemanticAttributes.RPC_METHOD" "GetObject" "aws.endpoint" "https://s3.amazonaws.com" "aws.agent" "java-aws-sdk" "aws.bucket.name" "someBucket" + "$HttpAttributes.ERROR_TYPE" IllegalStateException.name } } } @@ -259,16 +260,17 @@ class Aws0ClientTest extends AgentInstrumentationSpecification { errorEvent AmazonClientException, ~/Unable to execute HTTP request/ hasNoParent() attributes { - "$SemanticAttributes.HTTP_URL" "${server.httpUri()}" - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.NET_PEER_PORT" server.httpPort() - "$SemanticAttributes.NET_PEER_NAME" "127.0.0.1" + "$SemanticAttributes.URL_FULL" "${server.httpUri()}" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.SERVER_PORT" server.httpPort() + "$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1" "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" "Amazon S3" "$SemanticAttributes.RPC_METHOD" "GetObject" "aws.endpoint" "${server.httpUri()}" "aws.agent" "java-aws-sdk" "aws.bucket.name" "someBucket" + "$HttpAttributes.ERROR_TYPE" AmazonClientException.name } } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractAws1ClientTest.groovy b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractAws1ClientTest.groovy index 95e6ed8985d1..ea371826cf4e 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractAws1ClientTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractAws1ClientTest.groovy @@ -28,6 +28,7 @@ import com.amazonaws.services.rds.model.DeleteOptionGroupRequest import com.amazonaws.services.s3.AmazonS3Client import com.amazonaws.services.s3.AmazonS3ClientBuilder import io.opentelemetry.api.trace.Span +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import io.opentelemetry.testing.internal.armeria.common.HttpResponse @@ -102,15 +103,12 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification { kind operation == "SendMessage" ? PRODUCER : CLIENT hasNoParent() attributes { - "$SemanticAttributes.HTTP_URL" "${server.httpUri()}" - "$SemanticAttributes.HTTP_METHOD" "$method" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_PEER_PORT" server.httpPort() - "$SemanticAttributes.NET_PEER_NAME" "127.0.0.1" + "$SemanticAttributes.URL_FULL" "${server.httpUri()}" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "$method" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_PORT" server.httpPort() + "$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1" "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" { it.contains(service) } "$SemanticAttributes.RPC_METHOD" "${operation}" @@ -182,10 +180,10 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification { errorEvent SdkClientException, ~/Unable to execute HTTP request/ hasNoParent() attributes { - "$SemanticAttributes.HTTP_URL" "http://127.0.0.1:${UNUSABLE_PORT}" - "$SemanticAttributes.HTTP_METHOD" "$method" - "$SemanticAttributes.NET_PEER_NAME" "127.0.0.1" - "$SemanticAttributes.NET_PEER_PORT" 61 + "$SemanticAttributes.URL_FULL" "http://127.0.0.1:${UNUSABLE_PORT}" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "$method" + "$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1" + "$SemanticAttributes.SERVER_PORT" 61 "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" { it.contains(service) } "$SemanticAttributes.RPC_METHOD" "${operation}" @@ -194,6 +192,7 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification { for (def addedTag : additionalAttributes) { "$addedTag.key" "$addedTag.value" } + "$HttpAttributes.ERROR_TYPE" SdkClientException.name } } } @@ -237,16 +236,17 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification { } hasNoParent() attributes { - "$SemanticAttributes.HTTP_URL" "${server.httpUri()}" - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.NET_PEER_PORT" server.httpPort() - "$SemanticAttributes.NET_PEER_NAME" "127.0.0.1" + "$SemanticAttributes.URL_FULL" "${server.httpUri()}" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.SERVER_PORT" server.httpPort() + "$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1" "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" "Amazon S3" "$SemanticAttributes.RPC_METHOD" "GetObject" "aws.endpoint" "${server.httpUri()}" "aws.agent" "java-aws-sdk" "aws.bucket.name" "someBucket" + "$HttpAttributes.ERROR_TYPE" {it == SdkClientException.name || it == AmazonClientException.name } } } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsSuppressReceiveSpansTest.groovy b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsSuppressReceiveSpansTest.groovy index 07c041e52d3c..2fe4e2a83709 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsSuppressReceiveSpansTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsSuppressReceiveSpansTest.groovy @@ -12,6 +12,7 @@ import com.amazonaws.services.sqs.AmazonSQSAsyncClient import com.amazonaws.services.sqs.AmazonSQSAsyncClientBuilder import com.amazonaws.services.sqs.model.ReceiveMessageRequest import com.amazonaws.services.sqs.model.SendMessageRequest +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.SemanticAttributes @@ -75,14 +76,12 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif "rpc.system" "aws-api" "rpc.service" "AmazonSQS" "rpc.method" "CreateQueue" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" } } } @@ -98,18 +97,16 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif "rpc.system" "aws-api" "rpc.method" "SendMessage" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "publish" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" } } span(1) { @@ -123,14 +120,15 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "process" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(2) { @@ -170,14 +168,12 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif "rpc.system" "aws-api" "rpc.service" "AmazonSQS" "rpc.method" "CreateQueue" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" } } } @@ -193,18 +189,16 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif "rpc.system" "aws-api" "rpc.method" "SendMessage" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "publish" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" } } span(1) { @@ -218,14 +212,15 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "process" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(2) { @@ -255,14 +250,12 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" } } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsTracingTest.groovy b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsTracingTest.groovy index eff15ed53f11..04a1c9c887d8 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsTracingTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSqsTracingTest.groovy @@ -13,6 +13,7 @@ import com.amazonaws.services.sqs.AmazonSQSAsyncClientBuilder import com.amazonaws.services.sqs.model.MessageAttributeValue import com.amazonaws.services.sqs.model.ReceiveMessageRequest import com.amazonaws.services.sqs.model.SendMessageRequest +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.sdk.trace.data.SpanData @@ -87,14 +88,12 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "AmazonSQS" "rpc.method" "CreateQueue" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" } } } @@ -110,18 +109,16 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification { "rpc.system" "aws-api" "rpc.method" "SendMessage" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "publish" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" if (testCaptureHeaders) { "messaging.header.test_message_header" { it == ["test"] } } @@ -141,17 +138,15 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification { "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "receive" - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" if (testCaptureHeaders) { "messaging.header.test_message_header" { it == ["test"] } } @@ -169,10 +164,10 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification { "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "process" @@ -180,6 +175,7 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification { if (testCaptureHeaders) { "messaging.header.test_message_header" { it == ["test"] } } + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(2) { @@ -223,14 +219,12 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "AmazonSQS" "rpc.method" "CreateQueue" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" } } } @@ -246,18 +240,16 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification { "rpc.system" "aws-api" "rpc.method" "SendMessage" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "publish" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" } } publishSpan = span(0) @@ -293,14 +285,12 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification { "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" } } span(2) { @@ -314,17 +304,15 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification { "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.status_code" 200 - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "receive" - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" } } span(3) { @@ -339,14 +327,15 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification { "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" "rpc.system" "aws-api" "rpc.service" "AmazonSQS" - "http.method" "POST" - "http.url" "http://localhost:$sqsPort" - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "process" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(4) { diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientCoreTest.groovy b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientCoreTest.groovy index cf216cb0f591..12ba9c8adbe4 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientCoreTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientCoreTest.groovy @@ -133,13 +133,11 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification { kind CLIENT hasNoParent() attributes { - "$SemanticAttributes.NET_PEER_NAME" "127.0.0.1" - "$SemanticAttributes.NET_PEER_PORT" server.httpPort() - "$SemanticAttributes.HTTP_URL" { it.startsWith("${server.httpUri()}${path}") } - "$SemanticAttributes.HTTP_METHOD" "$method" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1" + "$SemanticAttributes.SERVER_PORT" server.httpPort() + "$SemanticAttributes.URL_FULL" { it.startsWith("${server.httpUri()}${path}") } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "$method" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" "DynamoDb" "$SemanticAttributes.RPC_METHOD" "CreateTable" @@ -168,13 +166,11 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification { kind CLIENT hasNoParent() attributes { - "$SemanticAttributes.NET_PEER_NAME" "127.0.0.1" - "$SemanticAttributes.NET_PEER_PORT" server.httpPort() - "$SemanticAttributes.HTTP_URL" { it.startsWith("${server.httpUri()}${path}") } - "$SemanticAttributes.HTTP_METHOD" "$method" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1" + "$SemanticAttributes.SERVER_PORT" server.httpPort() + "$SemanticAttributes.URL_FULL" { it.startsWith("${server.httpUri()}${path}") } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "$method" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" "DynamoDb" "$SemanticAttributes.RPC_METHOD" "Query" @@ -202,13 +198,11 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification { kind CLIENT hasNoParent() attributes { - "$SemanticAttributes.NET_PEER_NAME" "127.0.0.1" - "$SemanticAttributes.NET_PEER_PORT" server.httpPort() - "$SemanticAttributes.HTTP_URL" { it.startsWith("${server.httpUri()}${path}") } - "$SemanticAttributes.HTTP_METHOD" "$method" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1" + "$SemanticAttributes.SERVER_PORT" server.httpPort() + "$SemanticAttributes.URL_FULL" { it.startsWith("${server.httpUri()}${path}") } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "$method" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" "$service" "$SemanticAttributes.RPC_METHOD" "${operation}" diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.groovy b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.groovy index 7c152bb91b15..8518fca70836 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.groovy @@ -116,17 +116,15 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest { // the bucket name is a valid DNS label, even in the case that we are using an endpoint override. // Previously the sdk was only doing that if endpoint had "s3" as label in the FQDN. // Our test assert both cases so that we don't need to know what version is being tested. - "$SemanticAttributes.NET_PEER_NAME" { it == "somebucket.localhost" || it == "localhost" } - "$SemanticAttributes.HTTP_URL" { it.startsWith("http://somebucket.localhost:${server.httpPort()}") || it.startsWith("http://localhost:${server.httpPort()}/somebucket") } + "$SemanticAttributes.SERVER_ADDRESS" { it == "somebucket.localhost" || it == "localhost" } + "$SemanticAttributes.URL_FULL" { it.startsWith("http://somebucket.localhost:${server.httpPort()}") || it.startsWith("http://localhost:${server.httpPort()}/somebucket") } } else { - "$SemanticAttributes.NET_PEER_NAME" "localhost" - "$SemanticAttributes.HTTP_URL" { it.startsWith("http://localhost:${server.httpPort()}") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:${server.httpPort()}") } } - "$SemanticAttributes.NET_PEER_PORT" server.httpPort() - "$SemanticAttributes.HTTP_METHOD" "$method" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.SERVER_PORT" server.httpPort() + "$SemanticAttributes.HTTP_REQUEST_METHOD" "$method" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" "$service" "$SemanticAttributes.RPC_METHOD" "${operation}" @@ -256,17 +254,15 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest { // the bucket name is a valid DNS label, even in the case that we are using an endpoint override. // Previously the sdk was only doing that if endpoint had "s3" as label in the FQDN. // Our test assert both cases so that we don't need to know what version is being tested. - "$SemanticAttributes.NET_PEER_NAME" { it == "somebucket.localhost" || it == "localhost" } - "$SemanticAttributes.HTTP_URL" { it.startsWith("http://somebucket.localhost:${server.httpPort()}") || it.startsWith("http://localhost:${server.httpPort()}") } + "$SemanticAttributes.SERVER_ADDRESS" { it == "somebucket.localhost" || it == "localhost" } + "$SemanticAttributes.URL_FULL" { it.startsWith("http://somebucket.localhost:${server.httpPort()}") || it.startsWith("http://localhost:${server.httpPort()}") } } else { - "$SemanticAttributes.NET_PEER_NAME" "localhost" - "$SemanticAttributes.HTTP_URL" { it == "http://localhost:${server.httpPort()}" || it == "http://localhost:${server.httpPort()}/" } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.URL_FULL" { it == "http://localhost:${server.httpPort()}" || it == "http://localhost:${server.httpPort()}/" } } - "$SemanticAttributes.NET_PEER_PORT" server.httpPort() - "$SemanticAttributes.HTTP_METHOD" "$method" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.SERVER_PORT" server.httpPort() + "$SemanticAttributes.HTTP_REQUEST_METHOD" "$method" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" "$service" "$SemanticAttributes.RPC_METHOD" "${operation}" @@ -424,10 +420,10 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest { // the bucket name is a valid DNS label, even in the case that we are using an endpoint override. // Previously the sdk was only doing that if endpoint had "s3" as label in the FQDN. // Our test assert both cases so that we don't need to know what version is being tested. - "$SemanticAttributes.NET_PEER_NAME" { it == "somebucket.localhost" || it == "localhost" } - "$SemanticAttributes.HTTP_URL" { it == "http://somebucket.localhost:${server.httpPort()}/somekey" || it == "http://localhost:${server.httpPort()}/somebucket/somekey" } - "$SemanticAttributes.NET_PEER_PORT" server.httpPort() - "$SemanticAttributes.HTTP_METHOD" "GET" + "$SemanticAttributes.SERVER_ADDRESS" { it == "somebucket.localhost" || it == "localhost" } + "$SemanticAttributes.URL_FULL" { it == "http://somebucket.localhost:${server.httpPort()}/somekey" || it == "http://localhost:${server.httpPort()}/somebucket/somekey" } + "$SemanticAttributes.SERVER_PORT" server.httpPort() + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" "$SemanticAttributes.RPC_SYSTEM" "aws-api" "$SemanticAttributes.RPC_SERVICE" "S3" "$SemanticAttributes.RPC_METHOD" "GetObject" diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy index f63988717feb..54b143ac106d 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsSuppressReceiveSpansTest.groovy @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.awssdk.v2_2 +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import org.elasticmq.rest.sqs.SQSRestServerBuilder @@ -129,13 +130,11 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp "rpc.system" "aws-api" "rpc.service" "Sqs" "rpc.method" "CreateQueue" - "http.method" "POST" - "http.status_code" 200 - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort } } } @@ -151,17 +150,15 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp "rpc.system" "aws-api" "rpc.method" "SendMessage" "rpc.service" "Sqs" - "http.method" "POST" - "http.status_code" 200 - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "publish" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } } } span(1) { @@ -174,15 +171,15 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp "rpc.method" "ReceiveMessage" "rpc.system" "aws-api" "rpc.service" "Sqs" - "http.method" "POST" - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "process" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(2) { @@ -214,13 +211,11 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" "rpc.system" "aws-api" "rpc.service" "Sqs" - "http.method" "POST" - "http.status_code" 200 - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort } } } @@ -327,16 +322,14 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp "rpc.system" "aws-api" "rpc.method" "SendMessageBatch" "rpc.service" "Sqs" - "http.method" "POST" - "http.status_code" 200 - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "publish" - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } } } for (int i: 1..(xrayInjectionEnabled ? 3 : 2)) { @@ -351,15 +344,15 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp "rpc.method" "ReceiveMessage" "rpc.system" "aws-api" "rpc.service" "Sqs" - "http.method" "POST" - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "process" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } } @@ -379,15 +372,15 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp "rpc.method" "ReceiveMessage" "rpc.system" "aws-api" "rpc.service" "Sqs" - "http.method" "POST" - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "process" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } } diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.groovy b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.groovy index 53def4447aef..1b72da3a1296 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2SqsTracingTest.groovy @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.awssdk.v2_2 +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.semconv.SemanticAttributes @@ -131,13 +132,11 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification { "rpc.system" "aws-api" "rpc.service" "Sqs" "rpc.method" "CreateQueue" - "http.method" "POST" - "http.status_code" 200 - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort } } } @@ -153,17 +152,15 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification { "rpc.system" "aws-api" "rpc.method" "SendMessage" "rpc.service" "Sqs" - "http.method" "POST" - "http.status_code" 200 - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "publish" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } if (captureHeaders) { "messaging.header.test_message_header" { it == ["test"] } } @@ -194,13 +191,11 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification { "aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs" "rpc.system" "aws-api" "rpc.service" "Sqs" - "http.method" "POST" - "http.status_code" 200 - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort } } } @@ -218,16 +213,14 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification { "rpc.method" "ReceiveMessage" "rpc.system" "aws-api" "rpc.service" "Sqs" - "http.method" "POST" - "http.status_code" 200 - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "receive" - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } if (captureHeaders) { "messaging.header.test_message_header" { it == ["test"] } } @@ -243,18 +236,18 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification { "rpc.method" "ReceiveMessage" "rpc.system" "aws-api" "rpc.service" "Sqs" - "http.method" "POST" - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "process" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } if (captureHeaders) { "messaging.header.test_message_header" { it == ["test"] } } + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(2 + offset) { @@ -393,16 +386,14 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification { "rpc.system" "aws-api" "rpc.method" "SendMessageBatch" "rpc.service" "Sqs" - "http.method" "POST" - "http.status_code" 200 - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "publish" - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } } } publishSpan = span(0) @@ -419,16 +410,14 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification { "rpc.method" "ReceiveMessage" "rpc.system" "aws-api" "rpc.service" "Sqs" - "http.method" "POST" - "http.status_code" 200 - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "receive" - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } } } if (!xrayInjectionEnabled) { @@ -459,15 +448,15 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification { "rpc.method" "ReceiveMessage" "rpc.system" "aws-api" "rpc.service" "Sqs" - "http.method" "POST" - "http.url" { it.startsWith("http://localhost:$sqsPort") } - "net.peer.name" "localhost" - "net.peer.port" sqsPort + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") } + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" sqsPort "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs" "$SemanticAttributes.MESSAGING_OPERATION" "process" "$SemanticAttributes.MESSAGING_MESSAGE_ID" String - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(1 + 2*i + 1) { diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientRecordHttpErrorTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientRecordHttpErrorTest.java index ec7fd592412e..ad9e5e87b2dc 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientRecordHttpErrorTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientRecordHttpErrorTest.java @@ -163,10 +163,10 @@ public void testSendDynamoDbRequestWithRetries() { span.hasAttributesSatisfying( attributes -> { assertThat(attributes) - .containsEntry(SemanticAttributes.NET_PEER_NAME, "127.0.0.1") - .containsEntry(SemanticAttributes.NET_PEER_PORT, server.httpPort()) - .containsEntry(SemanticAttributes.HTTP_METHOD, method) - .containsEntry(SemanticAttributes.HTTP_STATUS_CODE, 200) + .containsEntry(SemanticAttributes.SERVER_ADDRESS, "127.0.0.1") + .containsEntry(SemanticAttributes.SERVER_PORT, server.httpPort()) + .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, method) + .containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200) .containsEntry(SemanticAttributes.RPC_SYSTEM, "aws-api") .containsEntry(SemanticAttributes.RPC_SERVICE, service) .containsEntry(SemanticAttributes.RPC_METHOD, operation) diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractQueryProtocolModelTest.java b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractQueryProtocolModelTest.java index 60d4c7d1a527..f13252a3cf40 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractQueryProtocolModelTest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractQueryProtocolModelTest.java @@ -6,7 +6,7 @@ package io.opentelemetry.instrumentation.awssdk.v2_2; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_URL; +import static io.opentelemetry.semconv.SemanticAttributes.URL_FULL; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -55,7 +55,6 @@ public void setupEach() { protected abstract InstrumentationExtension getTesting(); @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void testClientWithQueryProtocolModel() { server.enqueue( HttpResponse.of( @@ -95,7 +94,7 @@ void testClientWithQueryProtocolModel() { attributes -> { assertThat(attributes) .hasEntrySatisfying( - HTTP_URL, + URL_FULL, entry -> { assertThat(entry) .satisfies( diff --git a/instrumentation/camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/HttpSpanDecorator.java b/instrumentation/camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/HttpSpanDecorator.java index 30a354844090..dbceedc762b4 100644 --- a/instrumentation/camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/HttpSpanDecorator.java +++ b/instrumentation/camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/HttpSpanDecorator.java @@ -30,7 +30,6 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRoute; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRouteSource; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig; import io.opentelemetry.javaagent.instrumentation.apachecamel.CamelDirection; import io.opentelemetry.semconv.SemanticAttributes; @@ -89,7 +88,6 @@ public String getOperationName( } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void pre( AttributesBuilder attributes, Exchange exchange, @@ -97,28 +95,14 @@ public void pre( CamelDirection camelDirection) { super.pre(attributes, exchange, endpoint, camelDirection); - String httpUrl = getHttpUrl(exchange, endpoint); - if (httpUrl != null) { - if (SemconvStability.emitStableHttpSemconv()) { - internalSet(attributes, SemanticAttributes.URL_FULL, httpUrl); - } - - if (SemconvStability.emitOldHttpSemconv()) { - internalSet(attributes, SemanticAttributes.HTTP_URL, httpUrl); - } - } + internalSet(attributes, SemanticAttributes.URL_FULL, getHttpUrl(exchange, endpoint)); String method = getHttpMethod(exchange, endpoint); - if (SemconvStability.emitStableHttpSemconv()) { - if (method == null || knownMethods.contains(method)) { - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method); - } else { - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER); - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); - } - } - if (SemconvStability.emitOldHttpSemconv()) { - internalSet(attributes, SemanticAttributes.HTTP_METHOD, method); + if (method == null || knownMethods.contains(method)) { + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method); + } else { + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER); + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); } } @@ -175,19 +159,13 @@ protected String getHttpUrl(Exchange exchange, Endpoint endpoint) { } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void post(AttributesBuilder attributes, Exchange exchange, Endpoint endpoint) { super.post(attributes, exchange, endpoint); if (exchange.hasOut()) { Object responseCode = exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE); if (responseCode instanceof Integer) { - if (SemconvStability.emitStableHttpSemconv()) { - attributes.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, (Integer) responseCode); - } - if (SemconvStability.emitOldHttpSemconv()) { - attributes.put(SemanticAttributes.HTTP_STATUS_CODE, (Integer) responseCode); - } + attributes.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, (Integer) responseCode); } } } diff --git a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.java b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.java index 6caf1e1617f3..046980cb2cfe 100644 --- a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.java +++ b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.java @@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableMap; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerUsingTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; @@ -61,7 +62,6 @@ protected void cleanUp() { } @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void restComponentServerAndClientCallWithJettyBackend() { CamelContext camelContext = appContext.getBean(CamelContext.class); ProducerTemplate template = camelContext.createProducerTemplate(); @@ -91,42 +91,36 @@ void restComponentServerAndClientCallWithJettyBackend() { equalTo( stringKey("camel.uri"), "rest://get:api/%7Bmodule%7D/unit/%7BunitId%7D"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L)), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)), span -> span.hasName("GET /api/{module}/unit/{unitId}") .hasKind(SpanKind.SERVER) .hasParent(trace.getSpan(1)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_SCHEME, "http"), - equalTo( - SemanticAttributes.HTTP_TARGET, "/api/firstModule/unit/unitOne"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), + equalTo(SemanticAttributes.URL_SCHEME, "http"), + equalTo(SemanticAttributes.URL_PATH, "/api/firstModule/unit/unitOne"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_ROUTE, "/api/{module}/unit/{unitId}"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, Long.valueOf(port)), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, Long.valueOf(port)), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( SemanticAttributes.USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, - val -> val.isInstanceOf(Long.class)), - satisfies( - SemanticAttributes.NET_SOCK_HOST_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> val.isInstanceOf(Long.class))), span -> span.hasName("GET /api/{module}/unit/{unitId}") .hasKind(SpanKind.INTERNAL) .hasParent(trace.getSpan(2)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, "http://localhost:" + port + "/api/firstModule/unit/unitOne"), satisfies( stringKey("camel.uri"), val -> val.isInstanceOf(String.class))), diff --git a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/SingleServiceCamelTest.java b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/SingleServiceCamelTest.java index c035e60d7835..9e67da75becf 100644 --- a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/SingleServiceCamelTest.java +++ b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/SingleServiceCamelTest.java @@ -56,7 +56,6 @@ protected void cleanUp() { } @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void singleCamelServiceSpan() { URI requestUrl = address.resolve("/camelService"); @@ -69,8 +68,8 @@ public void singleCamelServiceSpan() { span.hasName("POST /camelService") .hasKind(SpanKind.SERVER) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "POST"), - equalTo(SemanticAttributes.HTTP_URL, requestUrl.toString()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), + equalTo(SemanticAttributes.URL_FULL, requestUrl.toString()), equalTo( stringKey("camel.uri"), requestUrl.toString().replace("localhost", "0.0.0.0"))))); diff --git a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.java b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.java index 298f6a070a2d..62b7788b39dc 100644 --- a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.java +++ b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.java @@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableMap; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.test.utils.PortUtils; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerUsingTest; @@ -85,7 +86,6 @@ public void configure() { } @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void twoCamelServiceSpans() throws Exception { createAndStartClient(); @@ -107,11 +107,11 @@ void twoCamelServiceSpans() throws Exception { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "POST"), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, "http://localhost:" + portOne + "/serviceOne"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), equalTo( stringKey("camel.uri"), "http://localhost:" + portOne + "/serviceOne")), @@ -120,11 +120,11 @@ void twoCamelServiceSpans() throws Exception { .hasKind(SpanKind.SERVER) .hasParent(trace.getSpan(1)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "POST"), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, "http://localhost:" + portOne + "/serviceOne"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), equalTo( stringKey("camel.uri"), "http://0.0.0.0:" + portOne + "/serviceOne")), @@ -133,11 +133,11 @@ void twoCamelServiceSpans() throws Exception { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(2)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "POST"), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, "http://127.0.0.1:" + portTwo + "/serviceTwo"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), equalTo( stringKey("camel.uri"), "http://127.0.0.1:" + portTwo + "/serviceTwo")), @@ -146,37 +146,29 @@ void twoCamelServiceSpans() throws Exception { .hasKind(SpanKind.SERVER) .hasParent(trace.getSpan(3)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "POST"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), - equalTo(SemanticAttributes.HTTP_SCHEME, "http"), - equalTo(SemanticAttributes.HTTP_TARGET, "/serviceTwo"), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L), + equalTo(SemanticAttributes.URL_SCHEME, "http"), + equalTo(SemanticAttributes.URL_PATH, "/serviceTwo"), equalTo( SemanticAttributes.USER_AGENT_ORIGINAL, "Jakarta Commons-HttpClient/3.1"), - satisfies( - SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, - val -> val.isInstanceOf(Long.class)), equalTo(SemanticAttributes.HTTP_ROUTE, "/serviceTwo"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.NET_HOST_NAME, "127.0.0.1"), - equalTo(SemanticAttributes.NET_HOST_PORT, portTwo), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, - val -> val.isInstanceOf(Long.class)), - equalTo(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "127.0.0.1"), + equalTo(SemanticAttributes.SERVER_PORT, portTwo), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_HOST_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> val.isInstanceOf(Long.class))), span -> span.hasName("POST /serviceTwo") .hasKind(SpanKind.INTERNAL) .hasParent(trace.getSpan(4)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "POST"), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, "http://127.0.0.1:" + portTwo + "/serviceTwo"), equalTo( stringKey("camel.uri"), diff --git a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsSpanAssertions.java b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsSpanAssertions.java index 4a9d920f0bc2..1881bc40bf8c 100644 --- a/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsSpanAssertions.java +++ b/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/aws/AwsSpanAssertions.java @@ -5,7 +5,6 @@ package io.opentelemetry.javaagent.instrumentation.apachecamel.aws; -import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.trace.SpanKind.CLIENT; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; @@ -13,6 +12,7 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; import io.opentelemetry.semconv.SemanticAttributes; @@ -37,7 +37,6 @@ static SpanDataAssert sqs( return sqs(span, spanName, queueUrl, queueName, CLIENT); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 static SpanDataAssert sqs( SpanDataAssert span, String spanName, String queueUrl, String queueName, SpanKind spanKind) { @@ -67,18 +66,13 @@ static SpanDataAssert sqs( val -> val.satisfiesAnyOf( v -> assertThat(v).isEqualTo(queueUrl), v -> assertThat(v).isNull())), - equalTo(SemanticAttributes.HTTP_METHOD, "POST"), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), + satisfies(SemanticAttributes.URL_FULL, val -> val.isInstanceOf(String.class)), satisfies( - SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isNull(), v -> assertThat(v).isInstanceOf(Long.class))), - satisfies(SemanticAttributes.HTTP_URL, val -> val.isInstanceOf(String.class)), - satisfies( - stringKey("net.peer.name"), + SemanticAttributes.SERVER_ADDRESS, stringAssert -> stringAssert.isInstanceOf(String.class)), satisfies( - longKey("net.peer.port"), + SemanticAttributes.SERVER_PORT, val -> val.satisfiesAnyOf( v -> assertThat(v).isNull(), @@ -90,15 +84,8 @@ static SpanDataAssert sqs( if (!spanName.endsWith("process")) { attributeAssertions.addAll( Arrays.asList( - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isNull(), - v -> assertThat(v).isInstanceOf(Long.class))), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"))); + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"))); } if (spanName.endsWith("receive") || spanName.endsWith("process") @@ -113,6 +100,7 @@ static SpanDataAssert sqs( attributeAssertions.add(equalTo(SemanticAttributes.MESSAGING_OPERATION, "process")); attributeAssertions.add( satisfies(SemanticAttributes.MESSAGING_MESSAGE_ID, val -> assertThat(val).isNotNull())); + attributeAssertions.add(equalTo(HttpAttributes.ERROR_TYPE, "_OTHER")); } else if (spanName.endsWith("publish")) { attributeAssertions.add(equalTo(SemanticAttributes.MESSAGING_OPERATION, "publish")); attributeAssertions.add( @@ -125,7 +113,6 @@ static SpanDataAssert sqs( .hasAttributesSatisfyingExactly(attributeAssertions); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 static SpanDataAssert s3(SpanDataAssert span, String spanName, String bucketName, String method) { return span.hasName(spanName) .hasAttributesSatisfyingExactly( @@ -135,25 +122,18 @@ static SpanDataAssert s3(SpanDataAssert span, String spanName, String bucketName equalTo(stringKey("rpc.method"), spanName.substring(3)), equalTo(stringKey("rpc.service"), "Amazon S3"), equalTo(stringKey("aws.bucket.name"), bucketName), - equalTo(stringKey("http.method"), method), - equalTo(longKey("http.status_code"), 200), - satisfies(stringKey("http.url"), val -> val.isInstanceOf(String.class)), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - satisfies(stringKey("net.peer.name"), val -> val.isInstanceOf(String.class)), - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isNull(), v -> assertThat(v).isInstanceOf(Long.class))), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, method), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + satisfies(SemanticAttributes.URL_FULL, val -> val.isInstanceOf(String.class)), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + satisfies(SemanticAttributes.SERVER_ADDRESS, val -> val.isInstanceOf(String.class)), satisfies( - stringKey("net.peer.port"), + SemanticAttributes.SERVER_PORT, val -> val.satisfiesAnyOf( v -> val.isInstanceOf(Number.class), v -> assertThat(v).isNull()))); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 static SpanDataAssert sns(SpanDataAssert span, String spanName) { return span.hasName(spanName) .hasKind(CLIENT) @@ -163,21 +143,15 @@ static SpanDataAssert sns(SpanDataAssert span, String spanName) { equalTo(stringKey("rpc.system"), "aws-api"), equalTo(stringKey("rpc.method"), spanName.substring(4)), equalTo(stringKey("rpc.service"), "AmazonSNS"), - equalTo(stringKey("http.method"), "POST"), - equalTo(longKey("http.status_code"), 200), - satisfies(stringKey("http.url"), val -> val.isInstanceOf(String.class)), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - satisfies(stringKey("net.peer.name"), val -> val.isInstanceOf(String.class)), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + satisfies(SemanticAttributes.URL_FULL, val -> val.isInstanceOf(String.class)), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + satisfies(SemanticAttributes.SERVER_ADDRESS, val -> val.isInstanceOf(String.class)), satisfies( - stringKey("net.peer.port"), + SemanticAttributes.SERVER_PORT, val -> val.satisfiesAnyOf( - v -> val.isInstanceOf(Number.class), v -> assertThat(v).isNull())), - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isNull(), v -> assertThat(v).isInstanceOf(Long.class)))); + v -> val.isInstanceOf(Number.class), v -> assertThat(v).isNull()))); } } diff --git a/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java b/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java index 8d0ee9652e05..c58f9eeb7bb8 100644 --- a/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java +++ b/instrumentation/cassandra/cassandra-3.0/javaagent/src/test/java/CassandraClientTest.java @@ -4,22 +4,16 @@ */ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import static io.opentelemetry.semconv.SemanticAttributes.DB_CASSANDRA_TABLE; -import static io.opentelemetry.semconv.SemanticAttributes.DB_NAME; -import static io.opentelemetry.semconv.SemanticAttributes.DB_OPERATION; -import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT; -import static io.opentelemetry.semconv.SemanticAttributes.DB_SYSTEM; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_ADDR; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_NAME; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_PORT; import static org.junit.jupiter.api.Named.named; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.ResultSetFuture; import com.datastax.driver.core.Session; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.semconv.SemanticAttributes; import java.net.InetSocketAddress; import java.time.Duration; import java.util.concurrent.Executor; @@ -37,7 +31,6 @@ import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public class CassandraClientTest { private static final Logger logger = LoggerFactory.getLogger(CassandraClientTest.class); @@ -92,11 +85,12 @@ void syncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(NET_SOCK_PEER_NAME, "localhost"), - equalTo(NET_SOCK_PEER_PORT, cassandraPort), - equalTo(DB_SYSTEM, "cassandra"), - equalTo(DB_STATEMENT, "USE " + parameter.keyspace))), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), + equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"), + equalTo( + SemanticAttributes.DB_STATEMENT, "USE " + parameter.keyspace))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -104,14 +98,14 @@ void syncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(NET_SOCK_PEER_NAME, "localhost"), - equalTo(NET_SOCK_PEER_PORT, cassandraPort), - equalTo(DB_SYSTEM, "cassandra"), - equalTo(DB_NAME, parameter.keyspace), - equalTo(DB_STATEMENT, parameter.expectedStatement), - equalTo(DB_OPERATION, parameter.operation), - equalTo(DB_CASSANDRA_TABLE, parameter.table)))); + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), + equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"), + equalTo(SemanticAttributes.DB_NAME, parameter.keyspace), + equalTo(SemanticAttributes.DB_STATEMENT, parameter.expectedStatement), + equalTo(SemanticAttributes.DB_OPERATION, parameter.operation), + equalTo(SemanticAttributes.DB_CASSANDRA_TABLE, parameter.table)))); } else { testing.waitAndAssertTraces( trace -> @@ -121,13 +115,13 @@ void syncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(NET_SOCK_PEER_NAME, "localhost"), - equalTo(NET_SOCK_PEER_PORT, cassandraPort), - equalTo(DB_SYSTEM, "cassandra"), - equalTo(DB_STATEMENT, parameter.expectedStatement), - equalTo(DB_OPERATION, parameter.operation), - equalTo(DB_CASSANDRA_TABLE, parameter.table)))); + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), + equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"), + equalTo(SemanticAttributes.DB_STATEMENT, parameter.expectedStatement), + equalTo(SemanticAttributes.DB_OPERATION, parameter.operation), + equalTo(SemanticAttributes.DB_CASSANDRA_TABLE, parameter.table)))); } session.close(); @@ -158,11 +152,12 @@ void asyncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(NET_SOCK_PEER_NAME, "localhost"), - equalTo(NET_SOCK_PEER_PORT, cassandraPort), - equalTo(DB_SYSTEM, "cassandra"), - equalTo(DB_STATEMENT, "USE " + parameter.keyspace))), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), + equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"), + equalTo( + SemanticAttributes.DB_STATEMENT, "USE " + parameter.keyspace))), trace -> trace.hasSpansSatisfyingExactly( span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), @@ -171,14 +166,14 @@ void asyncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(NET_SOCK_PEER_NAME, "localhost"), - equalTo(NET_SOCK_PEER_PORT, cassandraPort), - equalTo(DB_SYSTEM, "cassandra"), - equalTo(DB_NAME, parameter.keyspace), - equalTo(DB_STATEMENT, parameter.expectedStatement), - equalTo(DB_OPERATION, parameter.operation), - equalTo(DB_CASSANDRA_TABLE, parameter.table)), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), + equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"), + equalTo(SemanticAttributes.DB_NAME, parameter.keyspace), + equalTo(SemanticAttributes.DB_STATEMENT, parameter.expectedStatement), + equalTo(SemanticAttributes.DB_OPERATION, parameter.operation), + equalTo(SemanticAttributes.DB_CASSANDRA_TABLE, parameter.table)), span -> span.hasName("callbackListener") .hasKind(SpanKind.INTERNAL) @@ -193,13 +188,13 @@ void asyncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(NET_SOCK_PEER_NAME, "localhost"), - equalTo(NET_SOCK_PEER_PORT, cassandraPort), - equalTo(DB_SYSTEM, "cassandra"), - equalTo(DB_STATEMENT, parameter.expectedStatement), - equalTo(DB_OPERATION, parameter.operation), - equalTo(DB_CASSANDRA_TABLE, parameter.table)), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), + equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"), + equalTo(SemanticAttributes.DB_STATEMENT, parameter.expectedStatement), + equalTo(SemanticAttributes.DB_OPERATION, parameter.operation), + equalTo(SemanticAttributes.DB_CASSANDRA_TABLE, parameter.table)), span -> span.hasName("callbackListener") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java b/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java index 3a0920de06e4..b4abec571e64 100644 --- a/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java +++ b/instrumentation/cassandra/cassandra-4-common/testing/src/main/java/io/opentelemetry/cassandra/v4/common/AbstractCassandraTest.java @@ -18,9 +18,7 @@ import static io.opentelemetry.semconv.SemanticAttributes.DB_OPERATION; import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT; import static io.opentelemetry.semconv.SemanticAttributes.DB_SYSTEM; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_ADDR; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_NAME; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_PORT; +import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_TYPE; import static org.junit.jupiter.api.Named.named; import com.datastax.oss.driver.api.core.CqlSession; @@ -28,6 +26,7 @@ import com.datastax.oss.driver.api.core.config.DriverConfigLoader; import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import java.net.InetSocketAddress; import java.time.Duration; @@ -42,7 +41,6 @@ import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public abstract class AbstractCassandraTest { private static final Logger logger = LoggerFactory.getLogger(AbstractCassandraTest.class); @@ -92,9 +90,9 @@ void syncTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(NET_SOCK_PEER_NAME, "localhost"), - equalTo(NET_SOCK_PEER_PORT, cassandraPort), + equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), equalTo(DB_NAME, parameter.keyspace), equalTo(DB_STATEMENT, parameter.expectedStatement), @@ -139,9 +137,9 @@ void asyncTest(Parameter parameter) throws Exception { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(NET_SOCK_PEER_NAME, "localhost"), - equalTo(NET_SOCK_PEER_PORT, cassandraPort), + equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), equalTo(DB_NAME, parameter.keyspace), equalTo(DB_STATEMENT, parameter.expectedStatement), diff --git a/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java b/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java index dbea25f57d2d..37541d7b3690 100644 --- a/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java +++ b/instrumentation/cassandra/cassandra-4.4/testing/src/main/java/io/opentelemetry/testing/cassandra/v4_4/AbstractCassandra44Test.java @@ -18,14 +18,13 @@ import static io.opentelemetry.semconv.SemanticAttributes.DB_OPERATION; import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT; import static io.opentelemetry.semconv.SemanticAttributes.DB_SYSTEM; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_ADDR; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_NAME; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_PORT; +import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_TYPE; import static org.junit.jupiter.api.Named.named; import com.datastax.oss.driver.api.core.CqlSession; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.cassandra.v4.common.AbstractCassandraTest; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -36,7 +35,6 @@ public abstract class AbstractCassandra44Test extends AbstractCassandraTest { @ParameterizedTest(name = "{index}: {0}") @MethodSource("provideReactiveParameters") - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void reactiveTest(Parameter parameter) { CqlSession session = getSession(parameter.keyspace); @@ -58,9 +56,9 @@ void reactiveTest(Parameter parameter) { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(NET_SOCK_PEER_NAME, "localhost"), - equalTo(NET_SOCK_PEER_PORT, cassandraPort), + equalTo(NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort), equalTo(DB_SYSTEM, "cassandra"), equalTo(DB_NAME, parameter.keyspace), equalTo(DB_STATEMENT, parameter.expectedStatement), diff --git a/instrumentation/couchbase/couchbase-2.6/javaagent/src/test/groovy/CouchbaseSpanUtil.groovy b/instrumentation/couchbase/couchbase-2.6/javaagent/src/test/groovy/CouchbaseSpanUtil.groovy index aeadb4fd387b..83c1f2c91dbd 100644 --- a/instrumentation/couchbase/couchbase-2.6/javaagent/src/test/groovy/CouchbaseSpanUtil.groovy +++ b/instrumentation/couchbase/couchbase-2.6/javaagent/src/test/groovy/CouchbaseSpanUtil.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.semconv.SemanticAttributes @@ -34,9 +35,9 @@ class CouchbaseSpanUtil { "$SemanticAttributes.DB_OPERATION"(operation ?: spanName) // Because of caching, not all requests hit the server so these attributes may be absent - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_NAME" { it == "localhost" || it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Number } + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == null } + "$NetworkAttributes.NETWORK_PEER_PORT" { it instanceof Number || it == null } // Because of caching, not all requests hit the server so this tag may be absent "couchbase.local.address" { it == null || it instanceof String } diff --git a/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardTest.groovy b/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardTest.groovy index a5c099d99088..197d6181b2cb 100644 --- a/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardTest.groovy +++ b/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardTest.groovy @@ -10,6 +10,7 @@ import io.dropwizard.setup.Environment import io.dropwizard.testing.ConfigOverride import io.dropwizard.testing.DropwizardTestSupport import io.opentelemetry.api.trace.StatusCode +import io.opentelemetry.instrumentation.api.internal.HttpConstants import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest @@ -84,6 +85,9 @@ class DropwizardTest extends HttpServerTest implements Ag @Override String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return getContextPath() + "/*" + } switch (endpoint) { case NOT_FOUND: return getContextPath() + "/*" @@ -94,6 +98,11 @@ class DropwizardTest extends HttpServerTest implements Ag } } + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 405 + } + @Override void handlerSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint = SUCCESS) { trace.span(index) { diff --git a/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/apiclient/ElasticsearchClientTest.java b/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/apiclient/ElasticsearchClientTest.java index 07fc5e7ad6a9..c2682af1fe2d 100644 --- a/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/apiclient/ElasticsearchClientTest.java +++ b/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/apiclient/ElasticsearchClientTest.java @@ -7,7 +7,6 @@ import static io.opentelemetry.instrumentation.testing.GlobalTraceUtil.runWithSpan; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient; import co.elastic.clients.elasticsearch.ElasticsearchClient; @@ -24,7 +23,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.apache.http.HttpHost; -import org.assertj.core.api.AbstractLongAssert; import org.elasticsearch.client.RestClient; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -33,7 +31,6 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.testcontainers.elasticsearch.ElasticsearchContainer; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class ElasticsearchClientTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); @@ -90,25 +87,21 @@ public void elasticsearchStatus() throws IOException { .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"), equalTo(SemanticAttributes.DB_OPERATION, "info"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort())), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort())), span -> span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - AbstractLongAssert::isPositive)))); + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)))); } @Test @@ -130,11 +123,11 @@ public void elasticsearchIndex() throws IOException { .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"), equalTo(SemanticAttributes.DB_OPERATION, "index"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "PUT"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "PUT"), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, httpHost.toURI() + "/test-index/_doc/test-id?timeout=10s"), equalTo( AttributeKey.stringKey("db.elasticsearch.path_parts.index"), @@ -147,18 +140,14 @@ public void elasticsearchIndex() throws IOException { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "PUT"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "PUT"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, httpHost.toURI() + "/test-index/_doc/test-id?timeout=10s"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 201L), - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - AbstractLongAssert::isPositive)))); + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 201L)))); } @Test @@ -195,25 +184,21 @@ public void elasticsearchStatusAsync() throws Exception { .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"), equalTo(SemanticAttributes.DB_OPERATION, "info"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/")), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/")), span -> span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(1)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - AbstractLongAssert::isPositive)), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)), span -> span.hasName("callback") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/ElasticsearchRest5Test.java b/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/ElasticsearchRest5Test.java index 6e56904b6eee..21b20fadf796 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/ElasticsearchRest5Test.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/ElasticsearchRest5Test.java @@ -26,7 +26,6 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.testcontainers.elasticsearch.ElasticsearchContainer; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class ElasticsearchRest5Test { @RegisterExtension @@ -94,27 +93,23 @@ void elasticsearchStatus() throws IOException { .hasNoParent() .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), equalTo( - SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health")); + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health")); }, span -> { span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - response.getEntity().getContentLength())); + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)); }); }); } @@ -175,27 +170,23 @@ public void onFailure(Exception e) { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), equalTo( - SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health")); + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health")); }, span -> { span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(1)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - requestResponse[0].getEntity().getContentLength())); + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)); }, span -> { span.hasName("callback").hasKind(SpanKind.INTERNAL).hasParent(trace.getSpan(0)); diff --git a/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/ElasticsearchRest6Test.java b/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/ElasticsearchRest6Test.java index c5532be3d036..665920f2b9fe 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/ElasticsearchRest6Test.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/ElasticsearchRest6Test.java @@ -84,27 +84,23 @@ public void elasticsearchStatus() throws IOException { .hasNoParent() .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), equalTo( - SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health")); + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health")); }, span -> { span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), - equalTo( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - response.getEntity().getContentLength())); + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)); }); }); } @@ -164,27 +160,23 @@ public void onFailure(Exception e) { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), equalTo( - SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health")); + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health")); }, span -> { span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(1)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - requestResponse[0].getEntity().getContentLength())); + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)); }, span -> { span.hasName("callback").hasKind(SpanKind.INTERNAL).hasParent(trace.getSpan(0)); diff --git a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Test.java b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Test.java index 9f82c70255a3..668f4c3c55af 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Test.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Test.java @@ -7,7 +7,6 @@ import static io.opentelemetry.instrumentation.testing.GlobalTraceUtil.runWithSpan; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; @@ -17,7 +16,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.apache.http.HttpHost; -import org.assertj.core.api.AbstractLongAssert; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseListener; @@ -30,7 +28,6 @@ import org.testcontainers.elasticsearch.ElasticsearchContainer; import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class ElasticsearchRest7Test { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); @@ -85,28 +82,24 @@ public void elasticsearchStatus() throws Exception { .hasNoParent() .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health")), span -> span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), equalTo( - SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - AbstractLongAssert::isPositive)))); + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)))); } @Test @@ -162,28 +155,24 @@ public void onFailure(Exception e) { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health")), span -> span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(1)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), equalTo( - SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - AbstractLongAssert::isPositive)), + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)), span -> span.hasName("callback") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/elasticsearch/elasticsearch-rest-7.0/library/src/test/java/io/opentelemetry/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Test.java b/instrumentation/elasticsearch/elasticsearch-rest-7.0/library/src/test/java/io/opentelemetry/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Test.java index 56f754e3955f..ca7c82e0053d 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-7.0/library/src/test/java/io/opentelemetry/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Test.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-7.0/library/src/test/java/io/opentelemetry/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Test.java @@ -28,7 +28,6 @@ import org.testcontainers.elasticsearch.ElasticsearchContainer; import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class ElasticsearchRest7Test { @RegisterExtension static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); @@ -84,11 +83,11 @@ public void elasticsearchStatus() throws Exception { .hasNoParent() .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health")))); } @@ -145,11 +144,11 @@ public void onFailure(Exception e) { .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), equalTo( - SemanticAttributes.HTTP_URL, + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health")), span -> span.hasName("callback") diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchClientAttributeExtractor.java b/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchClientAttributeExtractor.java index 0d81b3c705a0..899a8ec1b3d0 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchClientAttributeExtractor.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/internal/ElasticsearchClientAttributeExtractor.java @@ -12,7 +12,6 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.api.internal.cache.Cache; import io.opentelemetry.semconv.SemanticAttributes; import java.util.HashSet; @@ -38,34 +37,20 @@ public class ElasticsearchClientAttributeExtractor this.knownMethods = new HashSet<>(knownMethods); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 private static void setServerAttributes(AttributesBuilder attributes, Response response) { HttpHost host = response.getHost(); if (host != null) { - if (SemconvStability.emitStableHttpSemconv()) { - internalSet(attributes, SemanticAttributes.SERVER_ADDRESS, host.getHostName()); - internalSet(attributes, SemanticAttributes.SERVER_PORT, (long) host.getPort()); - } - if (SemconvStability.emitOldHttpSemconv()) { - internalSet(attributes, SemanticAttributes.NET_PEER_NAME, host.getHostName()); - internalSet(attributes, SemanticAttributes.NET_PEER_PORT, (long) host.getPort()); - } + internalSet(attributes, SemanticAttributes.SERVER_ADDRESS, host.getHostName()); + internalSet(attributes, SemanticAttributes.SERVER_PORT, (long) host.getPort()); } } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 private static void setUrlAttribute(AttributesBuilder attributes, Response response) { String uri = response.getRequestLine().getUri(); uri = uri.startsWith("/") ? uri : "/" + uri; String fullUrl = response.getHost().toURI() + uri; - if (SemconvStability.emitStableHttpSemconv()) { - internalSet(attributes, SemanticAttributes.URL_FULL, fullUrl); - } - - if (SemconvStability.emitOldHttpSemconv()) { - internalSet(attributes, SemanticAttributes.HTTP_URL, fullUrl); - } + internalSet(attributes, SemanticAttributes.URL_FULL, fullUrl); } private static void setPathPartsAttributes( @@ -86,20 +71,14 @@ private static void setPathPartsAttributes( } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void onStart( AttributesBuilder attributes, Context parentContext, ElasticsearchRestRequest request) { String method = request.getMethod(); - if (SemconvStability.emitStableHttpSemconv()) { - if (method == null || knownMethods.contains(method)) { - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method); - } else { - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER); - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); - } - } - if (SemconvStability.emitOldHttpSemconv()) { - internalSet(attributes, SemanticAttributes.HTTP_METHOD, method); + if (method == null || knownMethods.contains(method)) { + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method); + } else { + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER); + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); } setPathPartsAttributes(attributes, request); } @@ -111,8 +90,8 @@ public void onEnd( ElasticsearchRestRequest request, @Nullable Response response, @Nullable Throwable error) { - if (response != null) { + if (response != null) { setUrlAttribute(attributes, response); setServerAttributes(attributes, response); } diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/test/groovy/Elasticsearch5TransportClientTest.groovy b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/test/groovy/Elasticsearch5TransportClientTest.groovy index 04d3eacca5f4..d8796d313ace 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/test/groovy/Elasticsearch5TransportClientTest.groovy +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/test/groovy/Elasticsearch5TransportClientTest.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.semconv.SemanticAttributes import org.elasticsearch.client.transport.TransportClient import org.elasticsearch.common.io.FileSystemUtils @@ -125,9 +126,8 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl name "ClusterHealthAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "ClusterHealthAction" "elasticsearch.action" "ClusterHealthAction" @@ -242,9 +242,8 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl name "CreateIndexAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "CreateIndexAction" "elasticsearch.action" "CreateIndexAction" @@ -258,9 +257,8 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl name "GetAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "GetAction" "elasticsearch.action" "GetAction" @@ -289,9 +287,8 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl name "IndexAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "IndexAction" "elasticsearch.action" "IndexAction" @@ -310,9 +307,8 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl name "GetAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "GetAction" "elasticsearch.action" "GetAction" diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53TransportClientTest.groovy b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53TransportClientTest.groovy index 969dbf62d6c2..34dbb75a0285 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53TransportClientTest.groovy +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53TransportClientTest.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.semconv.SemanticAttributes import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest import org.elasticsearch.client.transport.TransportClient @@ -131,9 +132,8 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC kind CLIENT childOf(span(0)) attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "ClusterHealthAction" "elasticsearch.action" "ClusterHealthAction" @@ -247,9 +247,8 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC name "CreateIndexAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "CreateIndexAction" "elasticsearch.action" "CreateIndexAction" @@ -263,9 +262,8 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC name "GetAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "GetAction" "elasticsearch.action" "GetAction" @@ -294,9 +292,8 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC name "IndexAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "IndexAction" "elasticsearch.action" "IndexAction" @@ -316,9 +313,8 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC name "GetAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "GetAction" "elasticsearch.action" "GetAction" diff --git a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/test/groovy/Elasticsearch6TransportClientTest.groovy b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/test/groovy/Elasticsearch6TransportClientTest.groovy index dbfde5154eb4..fd7d49eecf2a 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/test/groovy/Elasticsearch6TransportClientTest.groovy +++ b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/test/groovy/Elasticsearch6TransportClientTest.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.semconv.SemanticAttributes import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest import org.elasticsearch.client.transport.TransportClient @@ -105,10 +106,9 @@ class Elasticsearch6TransportClientTest extends AbstractElasticsearchTransportCl kind CLIENT childOf(span(0)) attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.address().hostString - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "ClusterHealthAction" "elasticsearch.action" "ClusterHealthAction" @@ -225,10 +225,9 @@ class Elasticsearch6TransportClientTest extends AbstractElasticsearchTransportCl name "CreateIndexAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.address().hostString - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "CreateIndexAction" "elasticsearch.action" "CreateIndexAction" @@ -242,10 +241,9 @@ class Elasticsearch6TransportClientTest extends AbstractElasticsearchTransportCl name "GetAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.address().hostString - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "GetAction" "elasticsearch.action" "GetAction" @@ -274,10 +272,9 @@ class Elasticsearch6TransportClientTest extends AbstractElasticsearchTransportCl name "IndexAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.address().hostString - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "IndexAction" "elasticsearch.action" "IndexAction" @@ -297,10 +294,9 @@ class Elasticsearch6TransportClientTest extends AbstractElasticsearchTransportCl name "GetAction" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address - "$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.address().hostString - "$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address + "$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port "$SemanticAttributes.DB_SYSTEM" "elasticsearch" "$SemanticAttributes.DB_OPERATION" "GetAction" "elasticsearch.action" "GetAction" diff --git a/instrumentation/finatra-2.9/javaagent/src/latestDepTest/scala/io/opentelemetry/javaagent/instrumentation/finatra/FinatraServerLatestTest.scala b/instrumentation/finatra-2.9/javaagent/src/latestDepTest/scala/io/opentelemetry/javaagent/instrumentation/finatra/FinatraServerLatestTest.scala index c83053a6f4a8..91b5ca2c10d2 100644 --- a/instrumentation/finatra-2.9/javaagent/src/latestDepTest/scala/io/opentelemetry/javaagent/instrumentation/finatra/FinatraServerLatestTest.scala +++ b/instrumentation/finatra-2.9/javaagent/src/latestDepTest/scala/io/opentelemetry/javaagent/instrumentation/finatra/FinatraServerLatestTest.scala @@ -55,6 +55,7 @@ class FinatraServerLatestTest extends AbstractHttpServerTest[HttpServer] { override def test(endpoint: ServerEndpoint): Boolean = endpoint != ServerEndpoint.NOT_FOUND }) + options.setResponseCodeOnNonStandardHttpMethod(400) } override protected def assertHandlerSpan( diff --git a/instrumentation/google-http-client-1.19/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/AbstractGoogleHttpClientTest.java b/instrumentation/google-http-client-1.19/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/AbstractGoogleHttpClientTest.java index a249df8dc7a0..bde4694f0cfb 100644 --- a/instrumentation/google-http-client-1.19/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/AbstractGoogleHttpClientTest.java +++ b/instrumentation/google-http-client-1.19/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/AbstractGoogleHttpClientTest.java @@ -18,7 +18,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; @@ -88,7 +87,6 @@ public int sendRequest(HttpRequest request, String method, URI uri, Map attributes = new ArrayList<>( Arrays.asList( - equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"), - satisfies( - getAttributeKey(SemanticAttributes.NET_PEER_PORT), - AbstractLongAssert::isPositive), - equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), uri.toString()), - equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "GET"), - equalTo(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), 500))); - if (SemconvStability.emitOldHttpSemconv()) { - attributes.add( - satisfies( - getAttributeKey(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH), - AbstractLongAssert::isPositive)); - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes.add(equalTo(HttpAttributes.ERROR_TYPE, "500")); - } + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + satisfies(SemanticAttributes.SERVER_PORT, AbstractLongAssert::isPositive), + equalTo(SemanticAttributes.URL_FULL, uri.toString()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 500), + equalTo(HttpAttributes.ERROR_TYPE, "500"))); testing.waitAndAssertTraces( trace -> @@ -128,7 +116,6 @@ void errorTracesWhenExceptionIsNotThrown() throws Exception { } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected void configure(HttpClientTestOptions.Builder optionsBuilder) { // executeAsync does not actually allow asynchronous execution since it returns a standard // Future which cannot have callbacks attached. We instrument execute and executeAsync @@ -142,15 +129,12 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { // can only use supported method optionsBuilder.disableTestNonStandardHttpMethod(); - if (SemconvStability.emitOldHttpSemconv()) { - optionsBuilder.setHttpAttributes( - uri -> { - Set> attributes = - new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); - return attributes; - }); - } + optionsBuilder.setHttpAttributes( + uri -> { + Set> attributes = + new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION); + return attributes; + }); } } diff --git a/instrumentation/grizzly-2.3/javaagent/src/test/groovy/GrizzlyFilterchainServerTest.groovy b/instrumentation/grizzly-2.3/javaagent/src/test/groovy/GrizzlyFilterchainServerTest.groovy index a5e86bc9cc1c..d4f0ed2a1b4e 100644 --- a/instrumentation/grizzly-2.3/javaagent/src/test/groovy/GrizzlyFilterchainServerTest.groovy +++ b/instrumentation/grizzly-2.3/javaagent/src/test/groovy/GrizzlyFilterchainServerTest.groovy @@ -68,7 +68,6 @@ class GrizzlyFilterchainServerTest extends HttpServerTest implements Set> httpAttributes(ServerEndpoint endpoint) { def attributes = super.httpAttributes(endpoint) attributes.remove(SemanticAttributes.HTTP_ROUTE) - attributes.remove(SemanticAttributes.NET_TRANSPORT) attributes } diff --git a/instrumentation/grizzly-2.3/javaagent/src/test/groovy/GrizzlyTest.groovy b/instrumentation/grizzly-2.3/javaagent/src/test/groovy/GrizzlyTest.groovy index 0280669f7cf7..3b3d5b224d3a 100644 --- a/instrumentation/grizzly-2.3/javaagent/src/test/groovy/GrizzlyTest.groovy +++ b/instrumentation/grizzly-2.3/javaagent/src/test/groovy/GrizzlyTest.groovy @@ -80,7 +80,6 @@ class GrizzlyTest extends HttpServerTest implements AgentTestTrait { Set> httpAttributes(ServerEndpoint endpoint) { def attributes = super.httpAttributes(endpoint) attributes.remove(SemanticAttributes.HTTP_ROUTE) - attributes.remove(SemanticAttributes.NET_TRANSPORT) attributes } diff --git a/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.java b/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.java index a19a306798f7..f842be94ef3b 100644 --- a/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.java +++ b/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.java @@ -20,6 +20,7 @@ import io.grpc.Status; import io.grpc.stub.StreamObserver; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.util.ThrowingRunnable; import io.opentelemetry.sdk.testing.assertj.EventDataAssert; @@ -37,7 +38,6 @@ import org.junit.jupiter.api.AfterEach; import org.junitpioneer.jupiter.cartesian.CartesianTest; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public abstract class AbstractGrpcStreamingTest { protected abstract ServerBuilder configureServer(ServerBuilder server); @@ -184,9 +184,9 @@ public void onCompleted() { equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, (long) server.getPort()))) + SemanticAttributes.SERVER_PORT, (long) server.getPort()))) .hasEventsSatisfyingExactly(events.toArray(new Consumer[0])), span -> span.hasName("example.Greeter/Conversation") @@ -199,14 +199,12 @@ public void onCompleted() { equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.getPort()), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> assertThat(val).isNotNull()), - satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull())) .hasEventsSatisfyingExactly(events.toArray(new Consumer[0])))); testing() @@ -224,7 +222,7 @@ public void onCompleted() { point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_HOST_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( SemanticAttributes.RPC_METHOD, "Conversation"), equalTo( @@ -249,9 +247,9 @@ public void onCompleted() { point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_PEER_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, + SemanticAttributes.SERVER_PORT, server.getPort()), equalTo( SemanticAttributes.RPC_METHOD, "Conversation"), diff --git a/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.java b/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.java index 0db883dfd939..993c3dcc68bf 100644 --- a/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.java +++ b/instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.java @@ -43,6 +43,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.util.ThrowingRunnable; import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; @@ -73,7 +74,6 @@ import org.junit.jupiter.params.provider.ValueSource; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public abstract class AbstractGrpcTest { protected static final String CLIENT_REQUEST_METADATA_KEY = "some-client-key"; @@ -140,9 +140,9 @@ public void sayHello( equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, (long) server.getPort()))) + SemanticAttributes.SERVER_PORT, (long) server.getPort()))) .hasEventsSatisfyingExactly( event -> event @@ -167,14 +167,12 @@ public void sayHello( equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.getPort()), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> assertThat(val).isNotNull()), - satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull())) .hasEventsSatisfyingExactly( event -> @@ -204,7 +202,7 @@ public void sayHello( point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_HOST_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo(SemanticAttributes.RPC_METHOD, "SayHello"), equalTo( SemanticAttributes.RPC_SERVICE, @@ -228,9 +226,9 @@ public void sayHello( point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_PEER_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, + SemanticAttributes.SERVER_PORT, server.getPort()), equalTo(SemanticAttributes.RPC_METHOD, "SayHello"), equalTo( @@ -304,9 +302,9 @@ public void sayHello( equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, (long) server.getPort()))) + SemanticAttributes.SERVER_PORT, (long) server.getPort()))) .hasEventsSatisfyingExactly( event -> event @@ -331,14 +329,12 @@ public void sayHello( equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> assertThat(val).isNotNull()), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.getPort()), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull())) .hasEventsSatisfyingExactly( event -> @@ -372,7 +368,7 @@ public void sayHello( point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_HOST_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo(SemanticAttributes.RPC_METHOD, "SayHello"), equalTo( SemanticAttributes.RPC_SERVICE, @@ -396,9 +392,9 @@ public void sayHello( point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_PEER_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, + SemanticAttributes.SERVER_PORT, server.getPort()), equalTo(SemanticAttributes.RPC_METHOD, "SayHello"), equalTo( @@ -480,9 +476,9 @@ public void onCompleted() { equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, (long) server.getPort()))) + SemanticAttributes.SERVER_PORT, (long) server.getPort()))) .hasEventsSatisfyingExactly( event -> event @@ -507,14 +503,12 @@ public void onCompleted() { equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> assertThat(val).isNotNull()), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.getPort()), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull())) .hasEventsSatisfyingExactly( event -> @@ -548,7 +542,7 @@ public void onCompleted() { point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_HOST_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo(SemanticAttributes.RPC_METHOD, "SayHello"), equalTo( SemanticAttributes.RPC_SERVICE, @@ -572,9 +566,9 @@ public void onCompleted() { point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_PEER_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, + SemanticAttributes.SERVER_PORT, server.getPort()), equalTo(SemanticAttributes.RPC_METHOD, "SayHello"), equalTo( @@ -631,9 +625,9 @@ public void sayHello( equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) status.getCode().value()), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, (long) server.getPort()))) + SemanticAttributes.SERVER_PORT, (long) server.getPort()))) .hasEventsSatisfyingExactly( event -> event @@ -653,14 +647,12 @@ public void sayHello( equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) status.getCode().value()), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.getPort()), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> assertThat(val).isNotNull()), - satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull())) .hasEventsSatisfying( events -> { @@ -692,7 +684,7 @@ public void sayHello( point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_HOST_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo(SemanticAttributes.RPC_METHOD, "SayHello"), equalTo( SemanticAttributes.RPC_SERVICE, @@ -716,9 +708,9 @@ public void sayHello( point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_PEER_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, + SemanticAttributes.SERVER_PORT, server.getPort()), equalTo(SemanticAttributes.RPC_METHOD, "SayHello"), equalTo( @@ -780,9 +772,9 @@ public void sayHello( equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.UNKNOWN.getCode().value()), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, (long) server.getPort()))) + SemanticAttributes.SERVER_PORT, (long) server.getPort()))) .hasEventsSatisfyingExactly( event -> event @@ -802,14 +794,12 @@ public void sayHello( equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.UNKNOWN.value()), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> assertThat(val).isNotNull()), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.getPort()), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull())) .hasEventsSatisfying( events -> { @@ -836,7 +826,7 @@ public void sayHello( point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_HOST_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo(SemanticAttributes.RPC_METHOD, "SayHello"), equalTo( SemanticAttributes.RPC_SERVICE, @@ -860,9 +850,9 @@ public void sayHello( point -> point.hasAttributesSatisfying( equalTo( - SemanticAttributes.NET_PEER_NAME, "localhost"), + SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, + SemanticAttributes.SERVER_PORT, server.getPort()), equalTo(SemanticAttributes.RPC_METHOD, "SayHello"), equalTo( @@ -1028,9 +1018,9 @@ public void onCompleted() { equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, (long) server.getPort()))) + SemanticAttributes.SERVER_PORT, (long) server.getPort()))) .hasEventsSatisfyingExactly( event -> event @@ -1055,14 +1045,12 @@ public void onCompleted() { equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.getPort()), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> assertThat(val).isNotNull()), - satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull())) .hasEventsSatisfyingExactly( event -> @@ -1148,9 +1136,9 @@ public void onCompleted() { equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.CANCELLED.value()), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, (long) server.getPort()))) + SemanticAttributes.SERVER_PORT, (long) server.getPort()))) .hasEventsSatisfying( events -> { assertThat(events).hasSize(3); @@ -1177,14 +1165,12 @@ public void onCompleted() { equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.CANCELLED.value()), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> assertThat(val).isNotNull()), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.getPort()), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull())) .hasEventsSatisfyingExactly( event -> @@ -1268,9 +1254,9 @@ public void onCompleted() { equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, (long) server.getPort()))) + SemanticAttributes.SERVER_PORT, (long) server.getPort()))) .hasEventsSatisfyingExactly( event -> event @@ -1298,14 +1284,12 @@ public void onCompleted() { equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> assertThat(val).isNotNull()), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.getPort()), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull())) .hasEventsSatisfyingExactly( event -> @@ -1375,9 +1359,9 @@ public void sayHello( equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), equalTo( - SemanticAttributes.NET_PEER_PORT, (long) server.getPort()))) + SemanticAttributes.SERVER_PORT, (long) server.getPort()))) .hasEventsSatisfyingExactly( event -> event @@ -1402,14 +1386,12 @@ public void sayHello( equalTo( SemanticAttributes.RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.getPort()), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> assertThat(val).isNotNull()), - satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull())) .hasEventsSatisfyingExactly( event -> @@ -1664,11 +1646,10 @@ static List addExtraClientAttributes(AttributeAssertion... a List result = new ArrayList<>(); result.addAll(Arrays.asList(assertions)); if (Boolean.getBoolean("testLatestDeps")) { - result.add(equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")); - result.add( - satisfies(SemanticAttributes.NET_SOCK_PEER_NAME, val -> assertThat(val).isNotNull())); + result.add(equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")); + result.add(equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1")); result.add( - satisfies(SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull())); + satisfies(NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull())); } return result; } diff --git a/instrumentation/hibernate/hibernate-reactive-1.0/javaagent/src/hibernateReactive1Test/java/io/opentelemetry/javaagent/instrumentation/hibernate/reactive/v1_0/HibernateReactiveTest.java b/instrumentation/hibernate/hibernate-reactive-1.0/javaagent/src/hibernateReactive1Test/java/io/opentelemetry/javaagent/instrumentation/hibernate/reactive/v1_0/HibernateReactiveTest.java index 42f02c9e8299..30db6c73e591 100644 --- a/instrumentation/hibernate/hibernate-reactive-1.0/javaagent/src/hibernateReactive1Test/java/io/opentelemetry/javaagent/instrumentation/hibernate/reactive/v1_0/HibernateReactiveTest.java +++ b/instrumentation/hibernate/hibernate-reactive-1.0/javaagent/src/hibernateReactive1Test/java/io/opentelemetry/javaagent/instrumentation/hibernate/reactive/v1_0/HibernateReactiveTest.java @@ -11,8 +11,8 @@ import static io.opentelemetry.semconv.SemanticAttributes.DB_SQL_TABLE; import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT; import static io.opentelemetry.semconv.SemanticAttributes.DB_USER; -import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_NAME; -import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_PORT; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_ADDRESS; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_PORT; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanKind; @@ -291,7 +291,6 @@ private static void complete( } } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 private static void assertTrace() { testing.waitAndAssertTraces( trace -> @@ -309,8 +308,8 @@ private static void assertTrace() { "select value0_.id as id1_0_0_, value0_.name as name2_0_0_ from Value value0_ where value0_.id=$?"), equalTo(DB_OPERATION, "SELECT"), equalTo(DB_SQL_TABLE, "Value"), - equalTo(NET_PEER_NAME, "localhost"), - equalTo(NET_PEER_PORT, port)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, port)), span -> span.hasName("callback") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/hibernate/hibernate-reactive-1.0/javaagent/src/hibernateReactive2Test/java/io/opentelemetry/javaagent/instrumentation/hibernate/reactive/v2_0/HibernateReactiveTest.java b/instrumentation/hibernate/hibernate-reactive-1.0/javaagent/src/hibernateReactive2Test/java/io/opentelemetry/javaagent/instrumentation/hibernate/reactive/v2_0/HibernateReactiveTest.java index c036efd31162..630f1e0fe590 100644 --- a/instrumentation/hibernate/hibernate-reactive-1.0/javaagent/src/hibernateReactive2Test/java/io/opentelemetry/javaagent/instrumentation/hibernate/reactive/v2_0/HibernateReactiveTest.java +++ b/instrumentation/hibernate/hibernate-reactive-1.0/javaagent/src/hibernateReactive2Test/java/io/opentelemetry/javaagent/instrumentation/hibernate/reactive/v2_0/HibernateReactiveTest.java @@ -11,8 +11,8 @@ import static io.opentelemetry.semconv.SemanticAttributes.DB_SQL_TABLE; import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT; import static io.opentelemetry.semconv.SemanticAttributes.DB_USER; -import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_NAME; -import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_PORT; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_ADDRESS; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_PORT; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanKind; @@ -283,7 +283,6 @@ private static void complete( } } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 private static void assertTrace() { testing.waitAndAssertTraces( trace -> @@ -301,8 +300,8 @@ private static void assertTrace() { "select v1_0.id,v1_0.name from Value v1_0 where v1_0.id=$?"), equalTo(DB_OPERATION, "SELECT"), equalTo(DB_SQL_TABLE, "Value"), - equalTo(NET_PEER_NAME, "localhost"), - equalTo(NET_PEER_PORT, port)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, port)), span -> span.hasName("callback") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpMethodAttributeExtractor.java b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpMethodAttributeExtractor.java index fc988d4eeed8..318db6c725b5 100644 --- a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpMethodAttributeExtractor.java +++ b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpMethodAttributeExtractor.java @@ -12,7 +12,6 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.semconv.SemanticAttributes; import java.net.HttpURLConnection; import java.util.Set; @@ -38,7 +37,6 @@ public void onStart( AttributesBuilder attributes, Context parentContext, HttpURLConnection connection) {} @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void onEnd( AttributesBuilder attributes, Context context, @@ -51,17 +49,12 @@ public void onEnd( if (getOutputStreamContext.isOutputStreamMethodOfSunConnectionCalled()) { String method = connection.getRequestMethod(); // The getOutputStream() has transformed "GET" into "POST" - if (SemconvStability.emitStableHttpSemconv()) { - if (knownMethods.contains(method)) { - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method); - attributes.remove(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL); - } else { - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER); - internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); - } - } - if (SemconvStability.emitOldHttpSemconv()) { - internalSet(attributes, SemanticAttributes.HTTP_METHOD, method); + if (knownMethods.contains(method)) { + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method); + attributes.remove(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL); + } else { + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER); + internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); } Span span = Span.fromContext(context); span.updateName(method); diff --git a/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionTest.java b/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionTest.java index ea8df5e87086..488a9c226cd2 100644 --- a/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionTest.java +++ b/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionTest.java @@ -10,13 +10,11 @@ import static io.opentelemetry.api.trace.SpanKind.SERVER; import static io.opentelemetry.javaagent.instrumentation.httpurlconnection.StreamUtils.readLines; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; import io.opentelemetry.api.trace.Span; import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.test.utils.PortUtils; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; @@ -37,7 +35,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import org.assertj.core.api.AbstractLongAssert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; @@ -92,7 +89,6 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { @ParameterizedTest @ValueSource(booleans = {false, true}) - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void traceRequest(boolean useCache) throws IOException { URL url = resolveAddress("/success").toURL(); @@ -124,18 +120,12 @@ public void traceRequest(boolean useCache) throws IOException { List attributes = new ArrayList<>( Arrays.asList( - equalTo(getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION), "1.1"), - equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"), - equalTo(getAttributeKey(SemanticAttributes.NET_PEER_PORT), url.getPort()), - equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), url.toString()), - equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "GET"), - equalTo(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), STATUS))); - if (SemconvStability.emitOldHttpSemconv()) { - attributes.add(equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http")); - attributes.add( - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, AbstractLongAssert::isNotNegative)); - } + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, url.getPort()), + equalTo(SemanticAttributes.URL_FULL, url.toString()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, STATUS))); testing.waitAndAssertTraces( trace -> @@ -159,7 +149,6 @@ public void traceRequest(boolean useCache) throws IOException { @ParameterizedTest @ValueSource(ints = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void testBrokenApiUsage() throws IOException { URL url = resolveAddress("/success").toURL(); HttpURLConnection connection = @@ -176,18 +165,12 @@ public void testBrokenApiUsage() throws IOException { List attributes = new ArrayList<>( Arrays.asList( - equalTo(getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION), "1.1"), - equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"), - equalTo(getAttributeKey(SemanticAttributes.NET_PEER_PORT), url.getPort()), - equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), url.toString()), - equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "GET"), - equalTo(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), STATUS))); - if (SemconvStability.emitOldHttpSemconv()) { - attributes.add(equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http")); - attributes.add( - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, AbstractLongAssert::isNotNegative)); - } + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, url.getPort()), + equalTo(SemanticAttributes.URL_FULL, url.toString()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, STATUS))); testing.waitAndAssertTraces( trace -> @@ -205,7 +188,6 @@ public void testBrokenApiUsage() throws IOException { } @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void testPostRequest() throws IOException { URL url = resolveAddress("/success").toURL(); testing.runWithSpan( @@ -234,21 +216,12 @@ public void testPostRequest() throws IOException { List attributes = new ArrayList<>( Arrays.asList( - equalTo(getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION), "1.1"), - equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"), - equalTo(getAttributeKey(SemanticAttributes.NET_PEER_PORT), url.getPort()), - equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), url.toString()), - equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "POST"), - equalTo(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), STATUS))); - if (SemconvStability.emitOldHttpSemconv()) { - attributes.add(equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http")); - attributes.add( - satisfies( - SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, AbstractLongAssert::isNotNegative)); - attributes.add( - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, AbstractLongAssert::isNotNegative)); - } + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, url.getPort()), + equalTo(SemanticAttributes.URL_FULL, url.toString()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, STATUS))); testing.waitAndAssertTraces( trace -> @@ -264,7 +237,6 @@ public void testPostRequest() throws IOException { } @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void getOutputStreamShouldTransformGetIntoPost() throws IOException { URL url = resolveAddress("/success").toURL(); testing.runWithSpan( @@ -297,21 +269,12 @@ public void getOutputStreamShouldTransformGetIntoPost() throws IOException { List attributes = new ArrayList<>( Arrays.asList( - equalTo(getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION), "1.1"), - equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"), - equalTo(getAttributeKey(SemanticAttributes.NET_PEER_PORT), url.getPort()), - equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), url.toString()), - equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "POST"), - equalTo(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), STATUS))); - if (SemconvStability.emitOldHttpSemconv()) { - attributes.add(equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http")); - attributes.add( - satisfies( - SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, AbstractLongAssert::isNotNegative)); - attributes.add( - satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, AbstractLongAssert::isNotNegative)); - } + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, url.getPort()), + equalTo(SemanticAttributes.URL_FULL, url.toString()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, STATUS))); testing.waitAndAssertTraces( trace -> @@ -328,7 +291,6 @@ public void getOutputStreamShouldTransformGetIntoPost() throws IOException { @ParameterizedTest @ValueSource(strings = {"http", "https"}) - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public void traceRequestWithConnectionFailure(String scheme) { String uri = scheme + "://localhost:" + PortUtils.UNUSABLE_PORT; @@ -349,17 +311,12 @@ public void traceRequestWithConnectionFailure(String scheme) { List attributes = new ArrayList<>( Arrays.asList( - equalTo(getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION), "1.1"), - equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"), - equalTo(getAttributeKey(SemanticAttributes.NET_PEER_PORT), PortUtils.UNUSABLE_PORT), - equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), uri), - equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "GET"))); - if (SemconvStability.emitOldHttpSemconv()) { - attributes.add(equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http")); - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes.add(equalTo(HttpAttributes.ERROR_TYPE, "java.net.ConnectException")); - } + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, PortUtils.UNUSABLE_PORT), + equalTo(SemanticAttributes.URL_FULL, uri), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(HttpAttributes.ERROR_TYPE, "java.net.ConnectException"))); testing.waitAndAssertTraces( trace -> diff --git a/instrumentation/java-http-client/testing/src/main/java/io/opentelemetry/instrumentation/httpclient/AbstractJavaHttpClientTest.java b/instrumentation/java-http-client/testing/src/main/java/io/opentelemetry/instrumentation/httpclient/AbstractJavaHttpClientTest.java index 2b6afe1e0196..e47bd7f12d19 100644 --- a/instrumentation/java-http-client/testing/src/main/java/io/opentelemetry/instrumentation/httpclient/AbstractJavaHttpClientTest.java +++ b/instrumentation/java-http-client/testing/src/main/java/io/opentelemetry/instrumentation/httpclient/AbstractJavaHttpClientTest.java @@ -6,7 +6,6 @@ package io.opentelemetry.instrumentation.httpclient; import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; @@ -78,27 +77,23 @@ public void sendRequestWithCallback( } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.disableTestCircularRedirects(); // TODO nested client span is not created, but context is still injected // which is not what the test expects optionsBuilder.disableTestWithClientParent(); - if (SemconvStability.emitOldHttpSemconv()) { - optionsBuilder.setHttpAttributes( - uri -> { - Set> attributes = - new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - // unopened port or non routable address; or timeout - if ("http://localhost:61/".equals(uri.toString()) - || "https://192.0.2.1/".equals(uri.toString()) - || uri.toString().contains("/read-timeout")) { - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); - } - return attributes; - }); - } + optionsBuilder.setHttpAttributes( + uri -> { + Set> attributes = + new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); + // unopened port or non routable address; or timeout + if ("http://localhost:61/".equals(uri.toString()) + || "https://192.0.2.1/".equals(uri.toString()) + || uri.toString().contains("/read-timeout")) { + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION); + } + return attributes; + }); } } diff --git a/instrumentation/jaxrs-client/jaxrs-client-1.1-testing/src/test/groovy/JaxRsClientV1Test.groovy b/instrumentation/jaxrs-client/jaxrs-client-1.1-testing/src/test/groovy/JaxRsClientV1Test.groovy index a430fe2c0a7b..8243a58e73a2 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-1.1-testing/src/test/groovy/JaxRsClientV1Test.groovy +++ b/instrumentation/jaxrs-client/jaxrs-client-1.1-testing/src/test/groovy/JaxRsClientV1Test.groovy @@ -79,8 +79,12 @@ class JaxRsClientV1Test extends HttpClientTest implements A @Override Set> httpAttributes(URI uri) { def attributes = super.httpAttributes(uri) - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME) - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION) + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION) return attributes } + + @Override + boolean testNonStandardHttpMethod() { + false + } } diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/JaxRsClientTest.groovy b/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/JaxRsClientTest.groovy index 1ab19154bbf8..890be20bdd45 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/JaxRsClientTest.groovy +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/JaxRsClientTest.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpClientTest import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult @@ -33,6 +35,11 @@ abstract class JaxRsClientTest extends HttpClientTest implem false } + @Override + boolean testNonStandardHttpMethod() { + false + } + @Override Invocation.Builder buildRequest(String method, URI uri, Map headers) { return internalBuildRequest(uri, headers) @@ -107,15 +114,14 @@ abstract class JaxRsClientTest extends HttpClientTest implem kind CLIENT status ERROR attributes { - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port > 0 ? uri.port : { it == null || it == 443 } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.HTTP_URL" "${uri}" - "$SemanticAttributes.HTTP_METHOD" method - "$SemanticAttributes.HTTP_STATUS_CODE" statusCode - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port > 0 ? uri.port : { it == null || it == 443 } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == null } + "$SemanticAttributes.URL_FULL" "${uri}" + "$SemanticAttributes.HTTP_REQUEST_METHOD" method + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" statusCode + "$HttpAttributes.ERROR_TYPE" "$statusCode" } } serverSpan(it, 1, span(0)) diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/ResteasyProxyClientTest.groovy b/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/ResteasyProxyClientTest.groovy index d106a7f94efc..d4a5e4556a2b 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/ResteasyProxyClientTest.groovy +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/ResteasyProxyClientTest.groovy @@ -84,6 +84,11 @@ class ResteasyProxyClientTest extends HttpClientTest impl boolean testReadTimeout() { return false } + + @Override + boolean testNonStandardHttpMethod() { + false + } } @Path("") diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy index 3920053b7c74..f91b5807de25 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import spock.lang.Unroll @@ -35,8 +36,9 @@ class JaxRsAnnotations1InstrumentationTest extends AgentInstrumentationSpecifica kind SERVER hasNoParent() attributes { - "$SemanticAttributes.HTTP_METHOD" "GET" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" "$SemanticAttributes.HTTP_ROUTE" paramName + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(1) { @@ -124,7 +126,8 @@ class JaxRsAnnotations1InstrumentationTest extends AgentInstrumentationSpecifica name "GET" kind SERVER attributes { - "$SemanticAttributes.HTTP_METHOD" "GET" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } } diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JerseyTest.groovy b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JerseyTest.groovy index 418b8eef385d..f9f3048ef726 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JerseyTest.groovy +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JerseyTest.groovy @@ -4,6 +4,7 @@ */ import io.dropwizard.testing.junit.ResourceTestRule +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import org.junit.ClassRule @@ -40,8 +41,9 @@ class JerseyTest extends AgentInstrumentationSpecification { name "GET " + expectedRoute kind SERVER attributes { - "$SemanticAttributes.HTTP_METHOD" "GET" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" "$SemanticAttributes.HTTP_ROUTE" expectedRoute + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } @@ -80,8 +82,9 @@ class JerseyTest extends AgentInstrumentationSpecification { name "GET " + expectedRoute kind SERVER attributes { - "$SemanticAttributes.HTTP_METHOD" "GET" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" "$SemanticAttributes.HTTP_ROUTE" expectedRoute + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(1) { diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy index 600c68469749..276f78e3a9e3 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import spock.lang.Unroll @@ -35,8 +36,9 @@ class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecificat kind SERVER hasNoParent() attributes { - "$SemanticAttributes.HTTP_METHOD" "GET" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" "$SemanticAttributes.HTTP_ROUTE" paramName + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(1) { @@ -124,7 +126,8 @@ class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecificat name "GET" kind SERVER attributes { - "$SemanticAttributes.HTTP_METHOD" "GET" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/JaxRsJettyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/JaxRsJettyHttpServerTest.groovy index 4e310fcaa266..e817cb56e050 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/JaxRsJettyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/JaxRsJettyHttpServerTest.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.internal.HttpConstants +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.eclipse.jetty.server.Server import org.eclipse.jetty.webapp.WebAppContext @@ -38,4 +40,12 @@ abstract class JaxRsJettyHttpServerTest extends JaxRsHttpServerTest { String getContextPath() { "/rest-app" } + + @Override + String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return "${getContextPath()}/*" + } + return super.expectedHttpRoute(endpoint, method) + } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/build.gradle.kts b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/build.gradle.kts index c234a6e62e70..1f4d9762fab4 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/build.gradle.kts +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/build.gradle.kts @@ -53,6 +53,8 @@ dependencies { } tasks.withType().configureEach { + systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) + // TODO run tests both with and without experimental span attributes jvmArgs("-Dotel.instrumentation.jaxrs.experimental-span-attributes=true") } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/test/groovy/CxfHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/test/groovy/CxfHttpServerTest.groovy index fe0307b581be..534816ffecdd 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/test/groovy/CxfHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/test/groovy/CxfHttpServerTest.groovy @@ -40,4 +40,9 @@ class CxfHttpServerTest extends JaxRsHttpServerTest { void stopServer(Server httpServer) { httpServer.stop() } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + Boolean.getBoolean("testLatestDeps") ? 500 : 405 + } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/test/groovy/CxfJettyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/test/groovy/CxfJettyHttpServerTest.groovy index cc2487a4dce3..7bf37d74f381 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/test/groovy/CxfJettyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/test/groovy/CxfJettyHttpServerTest.groovy @@ -4,4 +4,9 @@ */ class CxfJettyHttpServerTest extends JaxRsJettyHttpServerTest { + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + Boolean.getBoolean("testLatestDeps") ? 500 : 405 + } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyHttpServerTest.groovy index 58eea5ff8f45..05d37cd00ef2 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyHttpServerTest.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.internal.HttpConstants +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.eclipse.jetty.server.Server import org.eclipse.jetty.servlet.ServletContextHandler import org.eclipse.jetty.servlet.ServletHolder @@ -42,4 +44,17 @@ class JerseyHttpServerTest extends JaxRsHttpServerTest { // disables a test that jersey deems invalid false } + + @Override + String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return "${getContextPath()}/*" + } + return super.expectedHttpRoute(endpoint, method) + } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 500 + } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyJettyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyJettyHttpServerTest.groovy index f1af4c75b0a3..97c4c1c28642 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyJettyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyJettyHttpServerTest.groovy @@ -15,4 +15,9 @@ class JerseyJettyHttpServerTest extends JaxRsJettyHttpServerTest { // disables a test that jersey deems invalid false } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 500 + } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy index e026acb012a4..94835308b6bb 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.internal.HttpConstants +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.undertow.Undertow import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer import test.JaxRsTestApplication @@ -33,4 +35,17 @@ class ResteasyHttpServerTest extends JaxRsHttpServerTest { boolean shouldTestCompletableStageAsync() { false } + + @Override + String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return "${getContextPath()}/*" + } + return super.expectedHttpRoute(endpoint, method) + } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 500 + } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy index 55e32477f463..4691531a7292 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy @@ -9,4 +9,9 @@ class ResteasyJettyHttpServerTest extends JaxRsJettyHttpServerTest { boolean shouldTestCompletableStageAsync() { false } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 500 + } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy index 7922087750f7..113b2baab4cf 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.internal.HttpConstants +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.undertow.Undertow import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer import test.JaxRsTestApplication @@ -27,4 +29,17 @@ class ResteasyHttpServerTest extends JaxRsHttpServerTest { void stopServer(UndertowJaxrsServer server) { server.stop() } + + @Override + String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return "${getContextPath()}/*" + } + return super.expectedHttpRoute(endpoint, method) + } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 500 + } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy index 753f96cd0707..8d92d379711a 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy @@ -5,4 +5,8 @@ class ResteasyJettyHttpServerTest extends JaxRsJettyHttpServerTest { + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 500 + } } diff --git a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy index c7a2b7fcc6b2..8e52a32760b3 100644 --- a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy +++ b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import spock.lang.Unroll @@ -35,8 +36,9 @@ class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecificat kind SERVER hasNoParent() attributes { - "$SemanticAttributes.HTTP_METHOD" "GET" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" "$SemanticAttributes.HTTP_ROUTE" paramName + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } span(1) { @@ -124,7 +126,8 @@ class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecificat name "GET" kind SERVER attributes { - "$SemanticAttributes.HTTP_METHOD" "GET" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } } diff --git a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-common/testing/src/main/groovy/JaxRsJettyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-common/testing/src/main/groovy/JaxRsJettyHttpServerTest.groovy index 4e310fcaa266..e817cb56e050 100644 --- a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-common/testing/src/main/groovy/JaxRsJettyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-common/testing/src/main/groovy/JaxRsJettyHttpServerTest.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.internal.HttpConstants +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.eclipse.jetty.server.Server import org.eclipse.jetty.webapp.WebAppContext @@ -38,4 +40,12 @@ abstract class JaxRsJettyHttpServerTest extends JaxRsHttpServerTest { String getContextPath() { "/rest-app" } + + @Override + String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return "${getContextPath()}/*" + } + return super.expectedHttpRoute(endpoint, method) + } } diff --git a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-jersey-3.0/javaagent/src/test/groovy/JerseyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-jersey-3.0/javaagent/src/test/groovy/JerseyHttpServerTest.groovy index 58eea5ff8f45..05d37cd00ef2 100644 --- a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-jersey-3.0/javaagent/src/test/groovy/JerseyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-jersey-3.0/javaagent/src/test/groovy/JerseyHttpServerTest.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.internal.HttpConstants +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.eclipse.jetty.server.Server import org.eclipse.jetty.servlet.ServletContextHandler import org.eclipse.jetty.servlet.ServletHolder @@ -42,4 +44,17 @@ class JerseyHttpServerTest extends JaxRsHttpServerTest { // disables a test that jersey deems invalid false } + + @Override + String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return "${getContextPath()}/*" + } + return super.expectedHttpRoute(endpoint, method) + } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 500 + } } diff --git a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-jersey-3.0/javaagent/src/test/groovy/JerseyJettyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-jersey-3.0/javaagent/src/test/groovy/JerseyJettyHttpServerTest.groovy index f1af4c75b0a3..97c4c1c28642 100644 --- a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-jersey-3.0/javaagent/src/test/groovy/JerseyJettyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-jersey-3.0/javaagent/src/test/groovy/JerseyJettyHttpServerTest.groovy @@ -15,4 +15,9 @@ class JerseyJettyHttpServerTest extends JaxRsJettyHttpServerTest { // disables a test that jersey deems invalid false } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 500 + } } diff --git a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-resteasy-6.0/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-resteasy-6.0/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy index df3d5a11c620..1ea11b42295c 100644 --- a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-resteasy-6.0/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-resteasy-6.0/javaagent/src/test/groovy/ResteasyHttpServerTest.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.internal.HttpConstants +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.undertow.Undertow import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer import test.JaxRsTestApplication @@ -32,4 +34,17 @@ class ResteasyHttpServerTest extends JaxRsHttpServerTest { boolean shouldTestCompletableStageAsync() { false } + + @Override + String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return "${getContextPath()}/*" + } + return super.expectedHttpRoute(endpoint, method) + } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 500 + } } diff --git a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-resteasy-6.0/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-resteasy-6.0/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy index 6b1683c9dfd4..8d92d379711a 100644 --- a/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-resteasy-6.0/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-3.0/jaxrs-3.0-resteasy-6.0/javaagent/src/test/groovy/ResteasyJettyHttpServerTest.groovy @@ -4,4 +4,9 @@ */ class ResteasyJettyHttpServerTest extends JaxRsJettyHttpServerTest { + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 500 + } } diff --git a/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsFilterTest.groovy b/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsFilterTest.groovy index db1b6490a17b..c8d1be71b55d 100644 --- a/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsFilterTest.groovy +++ b/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsFilterTest.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import org.junit.jupiter.api.Assumptions @@ -130,8 +131,9 @@ abstract class AbstractJaxRsFilterTest extends AgentInstrumentationSpecification kind SERVER if (!runsOnServer()) { attributes { - "$SemanticAttributes.HTTP_METHOD" method + "$SemanticAttributes.HTTP_REQUEST_METHOD" method "$SemanticAttributes.HTTP_ROUTE" route + "$HttpAttributes.ERROR_TYPE" "_OTHER" } } } diff --git a/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsHttpServerTest.groovy index 270c1cc7b556..3b11525d211b 100644 --- a/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-common/testing/src/main/groovy/AbstractJaxRsHttpServerTest.groovy @@ -3,7 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import io.opentelemetry.instrumentation.api.internal.SemconvStability +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest @@ -279,32 +280,26 @@ abstract class AbstractJaxRsHttpServerTest extends HttpServerTest implemen spanId spanID } attributes { - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" fullUrl.host - "$SemanticAttributes.NET_HOST_PORT" fullUrl.port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" { it instanceof Long || it == null } - "$SemanticAttributes.HTTP_SCHEME" fullUrl.getScheme() - "$SemanticAttributes.HTTP_TARGET" fullUrl.getPath() + (fullUrl.getQuery() != null ? "?" + fullUrl.getQuery() : "") - "$SemanticAttributes.HTTP_METHOD" method - "$SemanticAttributes.HTTP_STATUS_CODE" statusCode + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" fullUrl.host + "$SemanticAttributes.SERVER_PORT" fullUrl.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.URL_SCHEME" fullUrl.getScheme() + "$SemanticAttributes.URL_PATH" fullUrl.getPath() + "$SemanticAttributes.URL_QUERY" fullUrl.getQuery() + "$SemanticAttributes.HTTP_REQUEST_METHOD" method + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" statusCode "$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT - "$SemanticAttributes.HTTP_CLIENT_IP" TEST_CLIENT_IP + "$SemanticAttributes.CLIENT_ADDRESS" TEST_CLIENT_IP // Optional - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } "$SemanticAttributes.HTTP_ROUTE" path if (fullUrl.getPath().endsWith(ServerEndpoint.CAPTURE_HEADERS.getPath())) { - if (SemconvStability.emitOldHttpSemconv()) { - "http.request.header.x_test_request" { it == ["test"] } - "http.response.header.x_test_response" { it == ["test"] } - } - if (SemconvStability.emitStableHttpSemconv()) { - "http.request.header.x-test-request" { it == ["test"] } - "http.response.header.x-test-response" { it == ["test"] } - } + "http.request.header.x-test-request" { it == ["test"] } + "http.response.header.x-test-response" { it == ["test"] } + } + if (statusCode >= 500) { + "$HttpAttributes.ERROR_TYPE" "$statusCode" } } } diff --git a/instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy b/instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy index 9c131695cee2..0463b6bf4d53 100644 --- a/instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy +++ b/instrumentation/jdbc/javaagent/src/test/groovy/JdbcInstrumentationTest.groovy @@ -647,7 +647,7 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification { "$SemanticAttributes.DB_SYSTEM" "other_sql" "$SemanticAttributes.DB_STATEMENT" "testing ?" "$SemanticAttributes.DB_CONNECTION_STRING" "testdb://localhost" - "$SemanticAttributes.NET_PEER_NAME" "localhost" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" } } } @@ -691,7 +691,7 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification { "$SemanticAttributes.DB_STATEMENT" sanitizedQuery "$SemanticAttributes.DB_OPERATION" operation "$SemanticAttributes.DB_SQL_TABLE" table - "$SemanticAttributes.NET_PEER_NAME" "localhost" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" } } } @@ -796,7 +796,7 @@ class JdbcInstrumentationTest extends AgentInstrumentationSpecification { "$SemanticAttributes.DB_STATEMENT" "SELECT * FROM table" "$SemanticAttributes.DB_OPERATION" "SELECT" "$SemanticAttributes.DB_SQL_TABLE" "table" - "$SemanticAttributes.NET_PEER_NAME" "localhost" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" } } } diff --git a/instrumentation/jdbc/library/src/test/groovy/io/opentelemetry/instrumentation/jdbc/OpenTelemetryConnectionTest.groovy b/instrumentation/jdbc/library/src/test/groovy/io/opentelemetry/instrumentation/jdbc/OpenTelemetryConnectionTest.groovy index 5cdae21e5858..c5f8d5bb0d35 100644 --- a/instrumentation/jdbc/library/src/test/groovy/io/opentelemetry/instrumentation/jdbc/OpenTelemetryConnectionTest.groovy +++ b/instrumentation/jdbc/library/src/test/groovy/io/opentelemetry/instrumentation/jdbc/OpenTelemetryConnectionTest.groovy @@ -51,8 +51,8 @@ class OpenTelemetryConnectionTest extends InstrumentationSpecification implement "$SemanticAttributes.DB_NAME" dbInfo.name "$SemanticAttributes.DB_USER" dbInfo.user "$SemanticAttributes.DB_CONNECTION_STRING" dbInfo.shortUrl - "$SemanticAttributes.NET_PEER_NAME" dbInfo.host - "$SemanticAttributes.NET_PEER_PORT" dbInfo.port + "$SemanticAttributes.SERVER_ADDRESS" dbInfo.host + "$SemanticAttributes.SERVER_PORT" dbInfo.port "$SemanticAttributes.DB_STATEMENT" query "$SemanticAttributes.DB_OPERATION" "SELECT" "$SemanticAttributes.DB_SQL_TABLE" "users" @@ -107,8 +107,8 @@ class OpenTelemetryConnectionTest extends InstrumentationSpecification implement "$SemanticAttributes.DB_NAME" dbInfo.name "$SemanticAttributes.DB_USER" dbInfo.user "$SemanticAttributes.DB_CONNECTION_STRING" dbInfo.shortUrl - "$SemanticAttributes.NET_PEER_NAME" dbInfo.host - "$SemanticAttributes.NET_PEER_PORT" dbInfo.port + "$SemanticAttributes.SERVER_ADDRESS" dbInfo.host + "$SemanticAttributes.SERVER_PORT" dbInfo.port "$SemanticAttributes.DB_STATEMENT" query "$SemanticAttributes.DB_OPERATION" "SELECT" "$SemanticAttributes.DB_SQL_TABLE" "users" @@ -167,8 +167,8 @@ class OpenTelemetryConnectionTest extends InstrumentationSpecification implement "$SemanticAttributes.DB_NAME" dbInfo.name "$SemanticAttributes.DB_USER" dbInfo.user "$SemanticAttributes.DB_CONNECTION_STRING" dbInfo.shortUrl - "$SemanticAttributes.NET_PEER_NAME" dbInfo.host - "$SemanticAttributes.NET_PEER_PORT" dbInfo.port + "$SemanticAttributes.SERVER_ADDRESS" dbInfo.host + "$SemanticAttributes.SERVER_PORT" dbInfo.port "$SemanticAttributes.DB_STATEMENT" query "$SemanticAttributes.DB_OPERATION" "SELECT" "$SemanticAttributes.DB_SQL_TABLE" "users" diff --git a/instrumentation/jedis/jedis-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisClientTest.java b/instrumentation/jedis/jedis-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisClientTest.java index b07d892c4fa5..52ca88dc4f76 100644 --- a/instrumentation/jedis/jedis-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisClientTest.java +++ b/instrumentation/jedis/jedis-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisClientTest.java @@ -20,7 +20,6 @@ import org.testcontainers.containers.GenericContainer; import redis.clients.jedis.Jedis; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class JedisClientTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); @@ -64,8 +63,8 @@ void setCommand() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, port)))); + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, port)))); } @Test @@ -85,8 +84,8 @@ void getCommand() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, port))), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, port))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -96,8 +95,8 @@ void getCommand() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "GET foo"), equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, port)))); + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, port)))); } @Test @@ -117,8 +116,8 @@ void commandWithNoArguments() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, port))), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, port))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -128,7 +127,7 @@ void commandWithNoArguments() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "RANDOMKEY"), equalTo(SemanticAttributes.DB_OPERATION, "RANDOMKEY"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, port)))); + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, port)))); } } diff --git a/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java b/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java index d01a8f8dbadf..c9863de857e5 100644 --- a/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java +++ b/instrumentation/jedis/jedis-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v3_0/Jedis30ClientTest.java @@ -10,6 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.semconv.SemanticAttributes; @@ -22,7 +23,6 @@ import org.testcontainers.containers.GenericContainer; import redis.clients.jedis.Jedis; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class Jedis30ClientTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); @@ -67,14 +67,12 @@ void setCommand() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1")), - satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)))); } @@ -95,14 +93,12 @@ void getCommand() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1")), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative))), trace -> trace.hasSpansSatisfyingExactly( @@ -113,14 +109,12 @@ void getCommand() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "GET foo"), equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1")), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)))); } @@ -141,14 +135,12 @@ void commandWithNoArguments() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1")), - satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative))), trace -> trace.hasSpansSatisfyingExactly( @@ -159,14 +151,12 @@ void commandWithNoArguments() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "RANDOMKEY"), equalTo(SemanticAttributes.DB_OPERATION, "RANDOMKEY"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1")), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)))); } } diff --git a/instrumentation/jedis/jedis-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/Jedis40ClientTest.java b/instrumentation/jedis/jedis-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/Jedis40ClientTest.java index ac484a80ceab..1a0fc1f0906f 100644 --- a/instrumentation/jedis/jedis-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/Jedis40ClientTest.java +++ b/instrumentation/jedis/jedis-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/Jedis40ClientTest.java @@ -6,10 +6,10 @@ package io.opentelemetry.javaagent.instrumentation.jedis.v4_0; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.semconv.SemanticAttributes; @@ -21,7 +21,6 @@ import org.testcontainers.containers.GenericContainer; import redis.clients.jedis.Jedis; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class Jedis40ClientTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); @@ -66,11 +65,9 @@ void setCommand() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1"))))); + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1")))); } @Test @@ -90,11 +87,9 @@ void getCommand() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1")))), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -104,11 +99,9 @@ void getCommand() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "GET foo"), equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1"))))); + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1")))); } @Test @@ -128,11 +121,9 @@ void commandWithNoArguments() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1")))), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -142,10 +133,8 @@ void commandWithNoArguments() { equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "RANDOMKEY"), equalTo(SemanticAttributes.DB_OPERATION, "RANDOMKEY"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1"))))); + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1")))); } } diff --git a/instrumentation/jsf/jsf-jakarta-common/testing/src/main/groovy/BaseJsfTest.groovy b/instrumentation/jsf/jsf-jakarta-common/testing/src/main/groovy/BaseJsfTest.groovy index e4925d6ec945..89d4a22e41dc 100644 --- a/instrumentation/jsf/jsf-jakarta-common/testing/src/main/groovy/BaseJsfTest.groovy +++ b/instrumentation/jsf/jsf-jakarta-common/testing/src/main/groovy/BaseJsfTest.groovy @@ -4,6 +4,7 @@ */ import io.opentelemetry.api.trace.SpanKind +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTestTrait @@ -86,21 +87,18 @@ abstract class BaseJsfTest extends AgentInstrumentationSpecification implements kind SpanKind.SERVER hasNoParent() attributes { - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" "/jetty-context/" + path + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" "/jetty-context/" + path "$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.HTTP_ROUTE" "/jetty-context/" + route - "$SemanticAttributes.HTTP_CLIENT_IP" { it == null || it == TEST_CLIENT_IP } + "$SemanticAttributes.CLIENT_ADDRESS" { it == null || it == TEST_CLIENT_IP } } } } diff --git a/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy b/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy index a5e9d3546f7a..0b4063b8f002 100644 --- a/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy +++ b/instrumentation/jsf/jsf-javax-common/testing/src/main/groovy/BaseJsfTest.groovy @@ -4,6 +4,7 @@ */ import io.opentelemetry.api.trace.SpanKind +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTestTrait @@ -97,21 +98,18 @@ abstract class BaseJsfTest extends AgentInstrumentationSpecification implements kind SpanKind.SERVER hasNoParent() attributes { - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" "/jetty-context/" + path + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" "/jetty-context/" + path "$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.HTTP_ROUTE" "/jetty-context/" + route - "$SemanticAttributes.HTTP_CLIENT_IP" { it == null || it == TEST_CLIENT_IP } + "$SemanticAttributes.CLIENT_ADDRESS" { it == null || it == TEST_CLIENT_IP } } } } diff --git a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy index 07a9f0b8a8e7..4de94d7e823e 100644 --- a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy +++ b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.SemanticAttributes @@ -89,21 +91,17 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { name "GET $route" kind SERVER attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.USER_AGENT_ORIGINAL" String - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { @@ -149,20 +147,18 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { name "GET $route" kind SERVER attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" "$route?$queryString" - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.URL_QUERY" queryString + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { @@ -204,21 +200,17 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { name "POST $route" kind SERVER attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "POST" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "POST" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.USER_AGENT_ORIGINAL" String - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" Long "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { @@ -269,20 +261,18 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { } } attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 500 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 500 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$HttpAttributes.ERROR_TYPE" "500" } } span(1) { @@ -338,20 +328,17 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { name "GET $route" kind SERVER attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { @@ -388,20 +375,17 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { name "GET $route" kind SERVER attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { @@ -470,20 +454,18 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { status ERROR errorEvent(JasperException, String) attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 500 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 500 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$HttpAttributes.ERROR_TYPE" "500" } } span(1) { @@ -521,20 +503,17 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { name "GET $route" kind SERVER attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" "/$jspWebappContext/$staticFile" - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" "/$jspWebappContext/$staticFile" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } } diff --git a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy index 647fd85c1ab6..29f64521a23d 100644 --- a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy +++ b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.SemanticAttributes @@ -87,20 +89,17 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { name "GET $route" kind SERVER attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { @@ -158,20 +157,17 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { name "GET $route" kind SERVER attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { @@ -208,20 +204,17 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { name "GET $route" kind SERVER attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { @@ -306,20 +299,17 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { name "GET $route" kind SERVER attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { @@ -390,20 +380,18 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { status ERROR errorEvent(JasperException, String) attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 500 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 500 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$HttpAttributes.ERROR_TYPE" "500" } } span(1) { @@ -453,20 +441,17 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { kind SERVER status UNSET attributes { - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" route - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 404 + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" route + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 404 "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" route - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { diff --git a/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.kt b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.kt index 336b2db73758..b6d3d4a8f866 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.kt @@ -121,12 +121,11 @@ class KtorHttpServerTest : AbstractHttpServerTest() { } } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 override fun configure(options: HttpServerTestOptions) { options.setTestPathParam(true) options.setHttpAttributes { - HttpServerTestOptions.DEFAULT_HTTP_ATTRIBUTES - SemanticAttributes.NET_PEER_PORT + HttpServerTestOptions.DEFAULT_HTTP_ATTRIBUTES - SemanticAttributes.SERVER_PORT } options.setExpectedHttpRoute { endpoint, method -> @@ -138,5 +137,7 @@ class KtorHttpServerTest : AbstractHttpServerTest() { // ktor does not have a controller lifecycle so the server span ends immediately when the // response is sent, which is before the controller span finishes. options.setVerifyServerSpanEndTime(false) + + options.setResponseCodeOnNonStandardHttpMethod(404) } } diff --git a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/AbstractKtorHttpClientTest.kt b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/AbstractKtorHttpClientTest.kt index 37ef4d56d86c..68bfd5c989ee 100644 --- a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/AbstractKtorHttpClientTest.kt +++ b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/AbstractKtorHttpClientTest.kt @@ -57,7 +57,6 @@ abstract class AbstractKtorHttpClientTest : AbstractHttpClientTest KtorHttpClientSingleConnection(host, port) { installTracing() } diff --git a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/AbstractKtorHttpServerTest.kt b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/AbstractKtorHttpServerTest.kt index 42eb2007a7c8..f3c00d656f6e 100644 --- a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/AbstractKtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/AbstractKtorHttpServerTest.kt @@ -118,12 +118,11 @@ abstract class AbstractKtorHttpServerTest : AbstractHttpServerTest @@ -136,5 +135,7 @@ abstract class AbstractKtorHttpServerTest : AbstractHttpServerTest diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceSyncClientTest.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceSyncClientTest.java index 4b040a858471..ae440f779dda 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceSyncClientTest.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceSyncClientTest.java @@ -26,7 +26,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class LettuceSyncClientTest extends AbstractLettuceClientTest { private static int incorrectPort; private static String dbUriNonExistent; @@ -86,8 +85,8 @@ void testConnect() { span.hasName("CONNECT") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PEER_NAME, host), - equalTo(SemanticAttributes.NET_PEER_PORT, port), + equalTo(SemanticAttributes.SERVER_ADDRESS, host), + equalTo(SemanticAttributes.SERVER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis")))); } @@ -108,8 +107,8 @@ void testConnectException() { .hasKind(SpanKind.CLIENT) .hasStatus(StatusData.error()) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PEER_NAME, host), - equalTo(SemanticAttributes.NET_PEER_PORT, incorrectPort), + equalTo(SemanticAttributes.SERVER_ADDRESS, host), + equalTo(SemanticAttributes.SERVER_PORT, incorrectPort), equalTo(SemanticAttributes.DB_SYSTEM, "redis")) .hasEventsSatisfyingExactly( event -> diff --git a/instrumentation/lettuce/lettuce-5.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java b/instrumentation/lettuce/lettuce-5.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java index 14c2aef33a09..6795a1a3143c 100644 --- a/instrumentation/lettuce/lettuce-5.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java @@ -10,6 +10,7 @@ import io.lettuce.core.RedisClient; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.lettuce.v5_1.AbstractLettuceReactiveClientTest; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -17,7 +18,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class LettuceReactiveClientTest extends AbstractLettuceReactiveClientTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); @@ -51,11 +51,9 @@ void testAsyncSubscriberWithSpecificThreadPool() { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET a ?")) .hasEventsSatisfyingExactly( @@ -66,11 +64,9 @@ void testAsyncSubscriberWithSpecificThreadPool() { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "GET a")) .hasEventsSatisfyingExactly( diff --git a/instrumentation/lettuce/lettuce-5.1/library/src/test/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java b/instrumentation/lettuce/lettuce-5.1/library/src/test/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java index 11e00606023e..5a256549e18b 100644 --- a/instrumentation/lettuce/lettuce-5.1/library/src/test/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/library/src/test/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceReactiveClientTest.java @@ -14,7 +14,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class LettuceReactiveClientTest extends AbstractLettuceReactiveClientTest { @RegisterExtension static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/groovy/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.groovy b/instrumentation/lettuce/lettuce-5.1/testing/src/main/groovy/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.groovy index c2ca6050bcb8..c9a58c9f1449 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/groovy/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.groovy +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/groovy/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.groovy @@ -13,6 +13,7 @@ import io.lettuce.core.api.StatefulConnection import io.lettuce.core.api.async.RedisAsyncCommands import io.lettuce.core.api.sync.RedisCommands import io.lettuce.core.codec.StringCodec +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.SemanticAttributes @@ -158,9 +159,9 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati name "SET" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_NAME" expectedHostAttributeValue - "$SemanticAttributes.NET_SOCK_PEER_PORT" port + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" port "$SemanticAttributes.DB_SYSTEM" "redis" "$SemanticAttributes.DB_STATEMENT" "SET TESTSETKEY ?" } @@ -208,9 +209,9 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati name "GET" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_NAME" expectedHostAttributeValue - "$SemanticAttributes.NET_SOCK_PEER_PORT" port + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" port "$SemanticAttributes.DB_SYSTEM" "redis" "$SemanticAttributes.DB_STATEMENT" "GET TESTKEY" } @@ -282,9 +283,9 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati kind CLIENT childOf(span(0)) attributes { - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_NAME" expectedHostAttributeValue - "$SemanticAttributes.NET_SOCK_PEER_PORT" port + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" port "$SemanticAttributes.DB_SYSTEM" "redis" "$SemanticAttributes.DB_STATEMENT" "GET NON_EXISTENT_KEY" } @@ -345,9 +346,9 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati kind CLIENT childOf(span(0)) attributes { - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_NAME" expectedHostAttributeValue - "$SemanticAttributes.NET_SOCK_PEER_PORT" port + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" port "$SemanticAttributes.DB_STATEMENT" "RANDOMKEY" "$SemanticAttributes.DB_SYSTEM" "redis" } @@ -411,9 +412,9 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati name "HMSET" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_NAME" expectedHostAttributeValue - "$SemanticAttributes.NET_SOCK_PEER_PORT" port + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" port "$SemanticAttributes.DB_SYSTEM" "redis" "$SemanticAttributes.DB_STATEMENT" "HMSET TESTHM firstname ? lastname ? age ?" } @@ -430,9 +431,9 @@ abstract class AbstractLettuceAsyncClientTest extends InstrumentationSpecificati name "HGETALL" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_NAME" expectedHostAttributeValue - "$SemanticAttributes.NET_SOCK_PEER_PORT" port + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" port "$SemanticAttributes.DB_SYSTEM" "redis" "$SemanticAttributes.DB_STATEMENT" "HGETALL TESTHM" } diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/groovy/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientAuthTest.groovy b/instrumentation/lettuce/lettuce-5.1/testing/src/main/groovy/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientAuthTest.groovy index 5b983556b32c..839d1b9707f4 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/groovy/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientAuthTest.groovy +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/groovy/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientAuthTest.groovy @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.lettuce.v5_1 import io.lettuce.core.RedisClient +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import org.testcontainers.containers.GenericContainer @@ -66,9 +67,9 @@ abstract class AbstractLettuceSyncClientAuthTest extends InstrumentationSpecific name "AUTH" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_NAME" expectedHostAttributeValue - "$SemanticAttributes.NET_SOCK_PEER_PORT" port + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" port "$SemanticAttributes.DB_SYSTEM" "redis" "$SemanticAttributes.DB_STATEMENT" "AUTH ?" } diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java index 2bd5c67f353b..044153db9043 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java @@ -12,6 +12,7 @@ import io.lettuce.core.api.sync.RedisCommands; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes; import java.util.Objects; import java.util.concurrent.CompletableFuture; @@ -21,10 +22,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -@SuppressWarnings({ - "deprecation", - "InterruptedExceptionSwallowed" -}) // until old http semconv are dropped in 2.0 +@SuppressWarnings({"InterruptedExceptionSwallowed"}) public abstract class AbstractLettuceReactiveClientTest extends AbstractLettuceClientTest { protected static String expectedHostAttributeValue; @@ -91,11 +89,9 @@ void testSetCommandWithSubscribeOnDefinedConsumer() throws Exception { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET TESTSETKEY ?")) .hasEventsSatisfyingExactly( @@ -129,11 +125,9 @@ void testGetCommandWithLambdaFunction() throws Exception { span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "GET TESTKEY")) .hasEventsSatisfyingExactly( @@ -178,11 +172,9 @@ void testGetNonExistentKeyCommand() throws Exception { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "GET NON_EXISTENT_KEY")) .hasEventsSatisfyingExactly( @@ -215,11 +207,9 @@ void testCommandWithNoArguments() throws Exception { span.hasName("RANDOMKEY") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "RANDOMKEY")) .hasEventsSatisfyingExactly( @@ -239,11 +229,9 @@ void testCommandFluxPublisher() { span.hasName("COMMAND") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "COMMAND")) .hasEventsSatisfyingExactly( @@ -284,11 +272,9 @@ void testBlockingSubscriber() { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET a ?")) .hasEventsSatisfyingExactly( @@ -299,11 +285,9 @@ void testBlockingSubscriber() { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "GET a")) .hasEventsSatisfyingExactly( @@ -328,11 +312,9 @@ void testAsyncSubscriber() { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET a ?")) .hasEventsSatisfyingExactly( @@ -343,11 +325,9 @@ void testAsyncSubscriber() { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "GET a")) .hasEventsSatisfyingExactly( diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java index 9bdc0d4d8583..f4e6e54045be 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java @@ -19,6 +19,7 @@ import io.lettuce.core.api.sync.RedisCommands; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.test.utils.PortUtils; import io.opentelemetry.semconv.SemanticAttributes; import java.util.Base64; @@ -27,12 +28,10 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public abstract class AbstractLettuceSyncClientTest extends AbstractLettuceClientTest { private static String dbUriNonExistent; private static String embeddedDbLocalhostUri; - private static String expectedHostAttributeValue; private static final ImmutableMap testHashMap = ImmutableMap.of( @@ -50,7 +49,6 @@ void setUp() { port = redisServer.getMappedPort(6379); embeddedDbUri = "redis://" + host + ":" + port + "/" + DB_INDEX; embeddedDbLocalhostUri = "redis://localhost:" + port + "/" + DB_INDEX; - expectedHostAttributeValue = "127.0.0.1".equals(host) ? null : host; int incorrectPort = PortUtils.findOpenPort(); dbUriNonExistent = "redis://" + host + ":" + incorrectPort + "/" + DB_INDEX; @@ -112,11 +110,9 @@ void testSetCommand() { span.hasName("SET") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET TESTSETKEY ?")) .hasEventsSatisfyingExactly( @@ -144,11 +140,9 @@ void testSetCommandLocalhost() { span.hasName("SET") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET TESTSETKEY ?")) .hasEventsSatisfyingExactly( @@ -169,11 +163,9 @@ void testGetCommand() { span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "GET TESTKEY")) .hasEventsSatisfyingExactly( @@ -194,11 +186,9 @@ void testGetNonExistentKeyCommand() { span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "GET NON_EXISTENT_KEY")) .hasEventsSatisfyingExactly( @@ -219,11 +209,9 @@ void testCommandWithNoArguments() { span.hasName("RANDOMKEY") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "RANDOMKEY")) .hasEventsSatisfyingExactly( @@ -248,13 +236,10 @@ void testListCommand() { span.hasName("LPUSH") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), equalTo( - SemanticAttributes.NET_SOCK_PEER_PORT, - containerConnection.port), + NetworkAttributes.NETWORK_PEER_PORT, containerConnection.port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "LPUSH TESTLIST ?")) .hasEventsSatisfyingExactly( @@ -275,11 +260,9 @@ void testHashSetCommand() { span.hasName("HMSET") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo( SemanticAttributes.DB_STATEMENT, @@ -302,11 +285,9 @@ void testHashGetallCommand() { span.hasName("HGETALL") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "HGETALL TESTHM")) .hasEventsSatisfyingExactly( @@ -334,11 +315,9 @@ void testEvalCommand() { span.hasName("EVAL") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo( SemanticAttributes.DB_STATEMENT, @@ -362,11 +341,9 @@ void testMsetCommand() { span.hasName("MSET") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "MSET key1 ? key2 ?")) .hasEventsSatisfyingExactly( @@ -391,13 +368,10 @@ void testDebugSegfaultCommandWithNoArgumentProducesNoSpan() { span.hasName("DEBUG") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), equalTo( - SemanticAttributes.NET_SOCK_PEER_PORT, - containerConnection.port), + NetworkAttributes.NETWORK_PEER_PORT, containerConnection.port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "DEBUG SEGFAULT"))); } else { @@ -406,13 +380,10 @@ void testDebugSegfaultCommandWithNoArgumentProducesNoSpan() { span.hasName("DEBUG") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), - equalTo( - SemanticAttributes.NET_SOCK_PEER_PORT, - containerConnection.port), + NetworkAttributes.NETWORK_PEER_PORT, containerConnection.port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "DEBUG SEGFAULT")) // these are no longer recorded since Lettuce 6.1.6 @@ -442,13 +413,10 @@ void testShutdownCommandProducesNoSpan() { // Seems to only be treated as an error with Lettuce 6+ .hasException(new RedisException("Connection disconnected")) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), equalTo( - SemanticAttributes.NET_SOCK_PEER_PORT, - containerConnection.port), + NetworkAttributes.NETWORK_PEER_PORT, containerConnection.port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SHUTDOWN NOSAVE"))); } else { @@ -458,13 +426,10 @@ void testShutdownCommandProducesNoSpan() { .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( equalTo(AttributeKey.stringKey("error"), "Connection disconnected"), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, - expectedHostAttributeValue), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), equalTo( - SemanticAttributes.NET_SOCK_PEER_PORT, - containerConnection.port), + NetworkAttributes.NETWORK_PEER_PORT, containerConnection.port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SHUTDOWN NOSAVE")) .hasEventsSatisfyingExactly( diff --git a/instrumentation/mongo/mongo-common/testing/src/main/groovy/io/opentelemetry/instrumentation/mongo/testing/AbstractMongoClientTest.groovy b/instrumentation/mongo/mongo-common/testing/src/main/groovy/io/opentelemetry/instrumentation/mongo/testing/AbstractMongoClientTest.groovy index ec1bbd50b888..776d2714ca44 100644 --- a/instrumentation/mongo/mongo-common/testing/src/main/groovy/io/opentelemetry/instrumentation/mongo/testing/AbstractMongoClientTest.groovy +++ b/instrumentation/mongo/mongo-common/testing/src/main/groovy/io/opentelemetry/instrumentation/mongo/testing/AbstractMongoClientTest.groovy @@ -411,8 +411,8 @@ abstract class AbstractMongoClientTest extends InstrumentationSpecification { childOf((SpanData) parentSpan) } attributes { - "$SemanticAttributes.NET_PEER_NAME" "localhost" - "$SemanticAttributes.NET_PEER_PORT" port + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" port "$SemanticAttributes.DB_STATEMENT" { statementEval.call(it.replaceAll(" ", "")) } diff --git a/instrumentation/netty/netty-3.8/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/Netty38ClientTest.java b/instrumentation/netty/netty-3.8/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/Netty38ClientTest.java index 183c796e470c..a195bec4219e 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/Netty38ClientTest.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/Netty38ClientTest.java @@ -21,7 +21,6 @@ import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; -import io.opentelemetry.instrumentation.testing.junit.http.SemconvStabilityUtil; import io.opentelemetry.semconv.SemanticAttributes; import java.lang.reflect.Method; import java.net.ConnectException; @@ -134,7 +133,6 @@ public void onThrowable(Throwable throwable) { } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.disableTestRedirects(); optionsBuilder.disableTestHttps(); @@ -172,8 +170,8 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { } Set> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_NAME)); - attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_PORT)); + attributes.remove(SemanticAttributes.SERVER_ADDRESS); + attributes.remove(SemanticAttributes.SERVER_PORT); return attributes; }); } diff --git a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy index fea30f99cfc1..3e5f3f38a98d 100644 --- a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy +++ b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy @@ -19,7 +19,6 @@ import io.netty.handler.codec.http.HttpMethod import io.netty.handler.codec.http.HttpVersion import io.netty.handler.ssl.SslHandler import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes -import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestServer import io.opentelemetry.semconv.SemanticAttributes @@ -35,7 +34,6 @@ import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.INTERNAL import static io.opentelemetry.api.trace.SpanKind.SERVER import static io.opentelemetry.api.trace.StatusCode.ERROR -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP class Netty40ClientSslTest extends AgentInstrumentationSpecification { @@ -90,24 +88,13 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification { name "CONNECT" kind INTERNAL childOf span(0) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_PORT" {it instanceof Long || it == null } - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } span(2) { @@ -117,21 +104,11 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification { status ERROR // netty swallows the exception, it doesn't make any sense to hard-code the message errorEventWithAnyMessage(SSLHandshakeException) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_NAME" uri.host - "$SemanticAttributes.NET_SOCK_PEER_PORT" uri.port - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$NetworkAttributes.NETWORK_PEER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } @@ -169,45 +146,24 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification { name "CONNECT" kind INTERNAL childOf span(0) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_PORT" {it instanceof Long || it == null } - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } span(2) { name "SSL handshake" kind INTERNAL childOf span(0) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_NAME" uri.host - "$SemanticAttributes.NET_SOCK_PEER_PORT" uri.port - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$NetworkAttributes.NETWORK_PEER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } span(3) { diff --git a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientTest.groovy b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientTest.groovy index 6ee25ed8233c..96a369417966 100644 --- a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientTest.groovy +++ b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientTest.groovy @@ -128,8 +128,8 @@ class Netty40ClientTest extends HttpClientTest implement return [] } def attributes = super.httpAttributes(uri) - attributes.remove(SemanticAttributes.NET_PEER_NAME) - attributes.remove(SemanticAttributes.NET_PEER_PORT) + attributes.remove(SemanticAttributes.SERVER_ADDRESS) + attributes.remove(SemanticAttributes.SERVER_PORT) return attributes } diff --git a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy index 34469662fd2d..0ee7fd698f01 100644 --- a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy +++ b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy @@ -17,7 +17,6 @@ import io.netty.handler.codec.http.HttpHeaders import io.netty.handler.codec.http.HttpMethod import io.netty.handler.codec.http.HttpVersion import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes -import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils @@ -32,7 +31,6 @@ import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.INTERNAL import static io.opentelemetry.api.trace.SpanKind.SERVER import static io.opentelemetry.api.trace.StatusCode.ERROR -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP class Netty40ConnectionSpanTest extends InstrumentationSpecification implements AgentTestTrait { @@ -106,24 +104,13 @@ class Netty40ConnectionSpanTest extends InstrumentationSpecification implements name "CONNECT" kind INTERNAL childOf(span(0)) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } span(2) { @@ -167,24 +154,13 @@ class Netty40ConnectionSpanTest extends InstrumentationSpecification implements childOf(span(0)) status ERROR errorEvent(thrownException.class, thrownException.message) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_PORT" {it instanceof Long || it == null } - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == null } - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == null } - "$NetworkAttributes.NETWORK_PEER_PORT" { it == uri.port || it == null } - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == null } + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == null } + "$NetworkAttributes.NETWORK_PEER_PORT" { it == uri.port || it == null } } } } diff --git a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy index 9f5fb181c17a..557d775a727a 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy +++ b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy @@ -21,7 +21,6 @@ import io.netty.handler.ssl.SslContext import io.netty.handler.ssl.SslContextBuilder import io.netty.handler.ssl.SslHandler import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes -import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.netty.v4_1.ClientHandler import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestServer @@ -38,7 +37,6 @@ import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.INTERNAL import static io.opentelemetry.api.trace.SpanKind.SERVER import static io.opentelemetry.api.trace.StatusCode.ERROR -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP class Netty41ClientSslTest extends AgentInstrumentationSpecification { @@ -95,42 +93,22 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification { name "RESOLVE" kind INTERNAL childOf span(0) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - } + attributes { + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port } } span(2) { name "CONNECT" kind INTERNAL childOf span(0) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_PORT" { it instanceof Long || it == null } - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } span(3) { @@ -140,21 +118,11 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification { status ERROR // netty swallows the exception, it doesn't make any sense to hard-code the message errorEventWithAnyMessage(SSLHandshakeException) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_NAME" uri.host - "$SemanticAttributes.NET_SOCK_PEER_PORT" uri.port - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$NetworkAttributes.NETWORK_PEER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } } @@ -194,63 +162,33 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification { name "RESOLVE" kind INTERNAL childOf span(0) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - } + attributes { + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port } } span(2) { name "CONNECT" kind INTERNAL childOf span(0) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_PORT" { it instanceof Long || it == null } - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } span(3) { name "SSL handshake" kind INTERNAL childOf span(0) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_NAME" uri.host - "$SemanticAttributes.NET_SOCK_PEER_PORT" uri.port - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$NetworkAttributes.NETWORK_PEER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } span(4) { diff --git a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy index 25a1ed14eaa5..ea1285702b09 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy +++ b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy @@ -17,7 +17,6 @@ import io.netty.handler.codec.http.HttpHeaderNames import io.netty.handler.codec.http.HttpMethod import io.netty.handler.codec.http.HttpVersion import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes -import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.netty.v4_1.ClientHandler import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.InstrumentationSpecification @@ -33,7 +32,6 @@ import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.INTERNAL import static io.opentelemetry.api.trace.SpanKind.SERVER import static io.opentelemetry.api.trace.StatusCode.ERROR -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP class Netty41ConnectionSpanTest extends InstrumentationSpecification implements AgentTestTrait { @@ -109,42 +107,22 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements name "RESOLVE" kind INTERNAL childOf span(0) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - } + attributes { + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port } } span(2) { name "CONNECT" kind INTERNAL childOf(span(0)) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" "ipv4" - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" "ipv4" + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" } } span(3) { @@ -188,18 +166,9 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements name "RESOLVE" kind INTERNAL childOf span(0) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - } + attributes { + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port } } span(2) { @@ -208,24 +177,13 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements childOf span(0) status ERROR errorEvent(thrownException.class, thrownException.message) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - "$SemanticAttributes.NET_PEER_NAME" uri.host - "$SemanticAttributes.NET_PEER_PORT" uri.port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_PORT" { it instanceof Long || it == null } - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" - "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == null } - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == null } - "$NetworkAttributes.NETWORK_PEER_PORT" { it == uri.port || it == null } - } + attributes { + "$SemanticAttributes.NETWORK_TRANSPORT" "tcp" + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == null } + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == null } + "$NetworkAttributes.NETWORK_PEER_PORT" { it == uri.port || it == null } } } } diff --git a/instrumentation/netty/netty-4.1/testing/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/AbstractNetty41ClientTest.java b/instrumentation/netty/netty-4.1/testing/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/AbstractNetty41ClientTest.java index e7aa60277b10..b925d66510b4 100644 --- a/instrumentation/netty/netty-4.1/testing/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/AbstractNetty41ClientTest.java +++ b/instrumentation/netty/netty-4.1/testing/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/AbstractNetty41ClientTest.java @@ -19,7 +19,6 @@ import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; -import io.opentelemetry.instrumentation.testing.junit.http.SemconvStabilityUtil; import io.opentelemetry.semconv.SemanticAttributes; import java.net.URI; import java.util.Collections; @@ -115,7 +114,6 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.disableTestRedirects(); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 private static Set> getHttpAttributes(URI uri) { String uriString = uri.toString(); // http://localhost:61/ => unopened port, https://192.0.2.1/ => non routable address @@ -123,8 +121,8 @@ private static Set> getHttpAttributes(URI uri) { return Collections.emptySet(); } Set> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_NAME)); - attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_PORT)); + attributes.remove(SemanticAttributes.SERVER_ADDRESS); + attributes.remove(SemanticAttributes.SERVER_PORT); return attributes; } diff --git a/instrumentation/okhttp/okhttp-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Test.java b/instrumentation/okhttp/okhttp-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Test.java index b22fceb984df..b83dd0c253d0 100644 --- a/instrumentation/okhttp/okhttp-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Test.java +++ b/instrumentation/okhttp/okhttp-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/okhttp/v2_2/OkHttp2Test.java @@ -13,7 +13,6 @@ import com.squareup.okhttp.Response; import com.squareup.okhttp.internal.http.HttpMethod; import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; @@ -93,7 +92,6 @@ private static OkHttpClient getClient(URI uri) { } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.disableTestCircularRedirects(); @@ -101,18 +99,13 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { uri -> { Set> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - - if (SemconvStability.emitOldHttpSemconv()) { - // protocol is extracted from the response, and those URLs cause exceptions (= null - // response) - if ("http://localhost:61/".equals(uri.toString()) - || "https://192.0.2.1/".equals(uri.toString()) - || resolveAddress("/read-timeout").toString().equals(uri.toString())) { - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); - } + // protocol is extracted from the response, and those URLs cause exceptions (= null + // response) + if ("http://localhost:61/".equals(uri.toString()) + || "https://192.0.2.1/".equals(uri.toString()) + || resolveAddress("/read-timeout").toString().equals(uri.toString())) { + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION); } - return attributes; }); } diff --git a/instrumentation/okhttp/okhttp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/AbstractOkHttp3Test.java b/instrumentation/okhttp/okhttp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/AbstractOkHttp3Test.java index 4b2a095ae7bb..0c2e0e2c4d3d 100644 --- a/instrumentation/okhttp/okhttp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/AbstractOkHttp3Test.java +++ b/instrumentation/okhttp/okhttp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/AbstractOkHttp3Test.java @@ -10,7 +10,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; @@ -113,7 +112,6 @@ private Call.Factory getClient(URI uri) { } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.markAsLowLevelInstrumentation(); optionsBuilder.setMaxRedirects(21); // 1st send + 20 retries @@ -123,15 +121,12 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { Set> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - if (SemconvStability.emitOldHttpSemconv()) { - // protocol is extracted from the response, and those URLs cause exceptions (= null - // response) - if ("http://localhost:61/".equals(uri.toString()) - || "https://192.0.2.1/".equals(uri.toString()) - || resolveAddress("/read-timeout").toString().equals(uri.toString())) { - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); - } + // protocol is extracted from the response, and those URLs cause exceptions (= null + // response) + if ("http://localhost:61/".equals(uri.toString()) + || "https://192.0.2.1/".equals(uri.toString()) + || resolveAddress("/read-timeout").toString().equals(uri.toString())) { + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION); } return attributes; diff --git a/instrumentation/opensearch/opensearch-rest-1.0/javaagent/src/test/java/OpenSearchRestTest.java b/instrumentation/opensearch/opensearch-rest-1.0/javaagent/src/test/java/OpenSearchRestTest.java index e0915051b000..b94f5e7b483d 100644 --- a/instrumentation/opensearch/opensearch-rest-1.0/javaagent/src/test/java/OpenSearchRestTest.java +++ b/instrumentation/opensearch/opensearch-rest-1.0/javaagent/src/test/java/OpenSearchRestTest.java @@ -33,7 +33,6 @@ import org.opensearch.testcontainers.OpensearchContainer; import org.testcontainers.utility.DockerImageName; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public class OpenSearchRestTest { @RegisterExtension static final AgentInstrumentationExtension testing = AgentInstrumentationExtension.create(); @@ -98,15 +97,13 @@ void shouldGetStatusWithTraces() throws IOException { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo( - SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), - equalTo(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 415L)))); + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)))); } @Test @@ -166,15 +163,13 @@ public void onFailure(Exception e) { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(1)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()), - equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()), + equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo( - SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L), - equalTo(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 415L)), + SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)), span -> span.hasName("callback") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/opentelemetry-instrumentation-api/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/instrumentationapi/ContextBridgeTest.java b/instrumentation/opentelemetry-instrumentation-api/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/instrumentationapi/ContextBridgeTest.java index 5c2c5f48e3a2..680ebb8a74a4 100644 --- a/instrumentation/opentelemetry-instrumentation-api/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/instrumentationapi/ContextBridgeTest.java +++ b/instrumentation/opentelemetry-instrumentation-api/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/instrumentationapi/ContextBridgeTest.java @@ -14,6 +14,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRoute; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRouteSource; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; import io.opentelemetry.instrumentation.api.internal.SpanKey; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -76,7 +77,6 @@ void testSpanKeyBridge() { } @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void testHttpRouteHolder_SameSourceAsServerInstrumentationDoesNotOverrideRoute() { AgentSpanTesting.runWithHttpServerSpan( "server", @@ -92,12 +92,12 @@ void testHttpRouteHolder_SameSourceAsServerInstrumentationDoesNotOverrideRoute() .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_ROUTE, "/test/server/*")))); + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.HTTP_ROUTE, "/test/server/*"), + equalTo(HttpAttributes.ERROR_TYPE, "_OTHER")))); } @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void testHttpRouteHolder_SourceWithHigherOrderValueOverridesRoute() { AgentSpanTesting.runWithHttpServerSpan( "server", @@ -113,7 +113,8 @@ void testHttpRouteHolder_SourceWithHigherOrderValueOverridesRoute() { .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_ROUTE, "/test/controller/:id")))); + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.HTTP_ROUTE, "/test/controller/:id"), + equalTo(HttpAttributes.ERROR_TYPE, "_OTHER")))); } } diff --git a/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/play24Test/groovy/client/PlayWsClientTest.groovy b/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/play24Test/groovy/client/PlayWsClientTest.groovy index 04c405ce7721..b6638ea8c555 100644 --- a/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/play24Test/groovy/client/PlayWsClientTest.groovy +++ b/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/play24Test/groovy/client/PlayWsClientTest.groovy @@ -79,8 +79,7 @@ class PlayWsClientTest extends HttpClientTest implements AgentTestTra @Override Set> httpAttributes(URI uri) { def attributes = super.httpAttributes(uri) - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME) - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION) + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION) attributes } diff --git a/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/play24Test/groovy/server/PlayServerTest.groovy b/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/play24Test/groovy/server/PlayServerTest.groovy index 30a37252a219..72177ac32a14 100644 --- a/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/play24Test/groovy/server/PlayServerTest.groovy +++ b/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/play24Test/groovy/server/PlayServerTest.groovy @@ -120,4 +120,9 @@ class PlayServerTest extends HttpServerTest implements AgentTestTrait { attributes.remove(SemanticAttributes.HTTP_ROUTE) attributes } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 404 + } } diff --git a/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/test/groovy/client/PlayWsClientTest.groovy b/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/test/groovy/client/PlayWsClientTest.groovy index 8a079de9199d..4d10e1ed4fbc 100644 --- a/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/test/groovy/client/PlayWsClientTest.groovy +++ b/instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/test/groovy/client/PlayWsClientTest.groovy @@ -5,12 +5,11 @@ package client -import io.opentelemetry.api.common.AttributeKey + import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpClientTest import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult import io.opentelemetry.instrumentation.testing.junit.http.SingleConnection -import io.opentelemetry.semconv.SemanticAttributes import play.libs.ws.WS import play.libs.ws.WSRequest import play.libs.ws.WSResponse @@ -63,15 +62,6 @@ class PlayWsClientTest extends HttpClientTest implements AgentTestTra return false } - @Override - Set> httpAttributes(URI uri) { - Set> extra = [ - SemanticAttributes.HTTP_SCHEME, - SemanticAttributes.HTTP_TARGET - ] - super.httpAttributes(uri) + extra - } - @Override SingleConnection createSingleConnection(String host, int port) { // Play HTTP client uses AsyncHttpClient internally which does not support HTTP 1.1 pipelining diff --git a/instrumentation/play/play-mvc/play-mvc-2.6/javaagent/src/latestDepTest/groovy/server/PlayServerTest.groovy b/instrumentation/play/play-mvc/play-mvc-2.6/javaagent/src/latestDepTest/groovy/server/PlayServerTest.groovy index a377b8f87e73..2119ec65217a 100644 --- a/instrumentation/play/play-mvc/play-mvc-2.6/javaagent/src/latestDepTest/groovy/server/PlayServerTest.groovy +++ b/instrumentation/play/play-mvc/play-mvc-2.6/javaagent/src/latestDepTest/groovy/server/PlayServerTest.groovy @@ -92,6 +92,12 @@ class PlayServerTest extends HttpServerTest implements AgentTestTrait { false } + // play does not emit a span at all when a non standard HTTP method is used + @Override + boolean testNonStandardHttpMethod() { + false + } + @Override void handlerSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint = SUCCESS) { trace.span(index) { diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBaseBase.groovy b/instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBaseBase.groovy index 44c70a84eda4..383f3e016f7e 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBaseBase.groovy +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBaseBase.groovy @@ -85,11 +85,10 @@ abstract class PlayWsClientTestBaseBase extends HttpClientTest @Override Set> httpAttributes(URI uri) { def attributes = super.httpAttributes(uri) - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME) - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION) + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION) if (uri.toString().endsWith("/circular-redirect")) { - attributes.remove(SemanticAttributes.NET_PEER_NAME) - attributes.remove(SemanticAttributes.NET_PEER_PORT) + attributes.remove(SemanticAttributes.SERVER_ADDRESS) + attributes.remove(SemanticAttributes.SERVER_PORT) } return attributes } diff --git a/instrumentation/pulsar/pulsar-2.8/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/pulsar/v2_8/PulsarClientTest.groovy b/instrumentation/pulsar/pulsar-2.8/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/pulsar/v2_8/PulsarClientTest.groovy index fe7c1d88b2f3..8b220334dd62 100644 --- a/instrumentation/pulsar/pulsar-2.8/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/pulsar/v2_8/PulsarClientTest.groovy +++ b/instrumentation/pulsar/pulsar-2.8/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/pulsar/v2_8/PulsarClientTest.groovy @@ -584,8 +584,8 @@ class PulsarClientTest extends AgentInstrumentationSpecification { childOf parentSpan attributes { "$SemanticAttributes.MESSAGING_SYSTEM" "pulsar" - "$SemanticAttributes.NET_PEER_NAME" brokerHost - "$SemanticAttributes.NET_PEER_PORT" brokerPort + "$SemanticAttributes.SERVER_ADDRESS" brokerHost + "$SemanticAttributes.SERVER_PORT" brokerPort "$SemanticAttributes.MESSAGING_DESTINATION_NAME" destination "$SemanticAttributes.MESSAGING_OPERATION" "publish" if (msgId == String) { @@ -622,8 +622,8 @@ class PulsarClientTest extends AgentInstrumentationSpecification { } attributes { "$SemanticAttributes.MESSAGING_SYSTEM" "pulsar" - "$SemanticAttributes.NET_PEER_NAME" brokerHost - "$SemanticAttributes.NET_PEER_PORT" brokerPort + "$SemanticAttributes.SERVER_ADDRESS" brokerHost + "$SemanticAttributes.SERVER_PORT" brokerPort "$SemanticAttributes.MESSAGING_DESTINATION_NAME" destination if (msgId == String) { "$SemanticAttributes.MESSAGING_MESSAGE_ID" String diff --git a/instrumentation/r2dbc-1.0/testing/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/AbstractR2dbcStatementTest.java b/instrumentation/r2dbc-1.0/testing/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/AbstractR2dbcStatementTest.java index 9e61f4e8d5a2..50a458a9bb1e 100644 --- a/instrumentation/r2dbc-1.0/testing/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/AbstractR2dbcStatementTest.java +++ b/instrumentation/r2dbc-1.0/testing/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/AbstractR2dbcStatementTest.java @@ -13,8 +13,8 @@ import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT; import static io.opentelemetry.semconv.SemanticAttributes.DB_SYSTEM; import static io.opentelemetry.semconv.SemanticAttributes.DB_USER; -import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_NAME; -import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_PORT; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_ADDRESS; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_PORT; import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE; import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER; import static io.r2dbc.spi.ConnectionFactoryOptions.HOST; @@ -126,7 +126,6 @@ void startContainer(DbSystemProps props) { @ParameterizedTest(name = "{index}: {0}") @MethodSource("provideParameters") - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void testQueries(Parameter parameter) { DbSystemProps props = SYSTEMS.get(parameter.system); startContainer(props); @@ -175,8 +174,8 @@ void testQueries(Parameter parameter) { equalTo(DB_STATEMENT, parameter.expectedStatement), equalTo(DB_OPERATION, parameter.operation), equalTo(DB_SQL_TABLE, parameter.table), - equalTo(NET_PEER_NAME, "localhost"), - equalTo(NET_PEER_PORT, port)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, port)), span -> span.hasName("child") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitChannelNetAttributesGetter.java b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitChannelNetAttributesGetter.java index f459d5339bdc..d94d6240cafd 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitChannelNetAttributesGetter.java +++ b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitChannelNetAttributesGetter.java @@ -29,7 +29,7 @@ public String getSockFamily(ChannelAndMethod channelAndMethod, @Nullable Void un public String getNetworkType(ChannelAndMethod channelAndMethod, @Nullable Void unused) { InetAddress address = channelAndMethod.getChannel().getConnection().getAddress(); if (address instanceof Inet4Address) { - return "ipv6"; + return "ipv4"; } else if (address instanceof Inet6Address) { return "ipv6"; } diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitMqTest.java b/instrumentation/rabbitmq-2.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitMqTest.java index ed882a6b069e..f6c0e201be29 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitMqTest.java +++ b/instrumentation/rabbitmq-2.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitMqTest.java @@ -22,6 +22,7 @@ import com.rabbitmq.client.ShutdownSignalException; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; @@ -912,25 +913,22 @@ private static SpanKind captureSpanKind(String rabbitCommand) { return spanKind; } - // Ignoring deprecation warning for use of SemanticAttributes - @SuppressWarnings("deprecation") private static void verifyNetAttributes(SpanDataAssert span) { span.hasAttributesSatisfying( attributes -> { assertThat(attributes) .satisfies( attrs -> { - String peerAddr = attrs.get(SemanticAttributes.NET_SOCK_PEER_ADDR); + String peerAddr = attrs.get(NetworkAttributes.NETWORK_PEER_ADDRESS); assertTrue( "127.0.0.1".equals(peerAddr) || "0:0:0:0:0:0:0:1".equals(peerAddr) || peerAddr == null); - String sockFamily = attrs.get(SemanticAttributes.NET_SOCK_FAMILY); - assertTrue( - SemanticAttributes.NetSockFamilyValues.INET6.equals(sockFamily) - || sockFamily == null); - assertNotNull(attrs.get(SemanticAttributes.NET_SOCK_PEER_PORT)); + String networkType = attrs.get(SemanticAttributes.NETWORK_TYPE); + assertThat(networkType).isIn("ipv4", "ipv6", null); + + assertNotNull(attrs.get(NetworkAttributes.NETWORK_PEER_PORT)); }); }); } diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/ReactorRabbitMqTest.java b/instrumentation/rabbitmq-2.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/ReactorRabbitMqTest.java index 44ae749cb7cd..79fbb4414995 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/ReactorRabbitMqTest.java +++ b/instrumentation/rabbitmq-2.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/ReactorRabbitMqTest.java @@ -7,10 +7,10 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.semconv.SemanticAttributes; @@ -26,8 +26,6 @@ class ReactorRabbitMqTest extends AbstractRabbitMqTest { @RegisterExtension private static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); - // Ignoring deprecation warning for use of SemanticAttributes - @SuppressWarnings("deprecation") @Test void testShouldNotFailDeclaringExchange() { Sender sender = @@ -56,20 +54,16 @@ void testShouldNotFailDeclaringExchange() { .satisfies( attrs -> { String peerAddr = - attrs.get(SemanticAttributes.NET_SOCK_PEER_ADDR); - assertTrue( - "127.0.0.1".equals(peerAddr) - || "0:0:0:0:0:0:0:1".equals(peerAddr) - || peerAddr == null); + attrs.get(NetworkAttributes.NETWORK_PEER_ADDRESS); + assertThat(peerAddr) + .isIn("127.0.0.1", "0:0:0:0:0:0:0:1", null); + + String networkType = + attrs.get(SemanticAttributes.NETWORK_TYPE); + assertThat(networkType).isIn("ipv4", "ipv6", null); - String sockFamily = - attrs.get(SemanticAttributes.NET_SOCK_FAMILY); - assertTrue( - SemanticAttributes.NetSockFamilyValues.INET6.equals( - sockFamily) - || sockFamily == null); assertNotNull( - attrs.get(SemanticAttributes.NET_SOCK_PEER_PORT)); + attrs.get(NetworkAttributes.NETWORK_PEER_PORT)); })); })); } diff --git a/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackForkedHttpClientTest.java b/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackForkedHttpClientTest.java index 7cd8dab05f8f..a3141f40651c 100644 --- a/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackForkedHttpClientTest.java +++ b/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackForkedHttpClientTest.java @@ -21,12 +21,11 @@ class RatpackForkedHttpClientTest extends AbstractRatpackForkedHttpClientTest { static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent(); @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected Set> computeHttpAttributes(URI uri) { Set> attributes = new HashSet<>(super.computeHttpAttributes(uri)); // underlying netty instrumentation does not provide these - attributes.remove(SemanticAttributes.NET_PEER_NAME); - attributes.remove(SemanticAttributes.NET_PEER_PORT); + attributes.remove(SemanticAttributes.SERVER_ADDRESS); + attributes.remove(SemanticAttributes.SERVER_PORT); return attributes; } } diff --git a/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackHttpClientTest.java b/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackHttpClientTest.java index d65f07b5a1ca..9f6348a16322 100644 --- a/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackHttpClientTest.java +++ b/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackHttpClientTest.java @@ -21,12 +21,11 @@ class RatpackHttpClientTest extends AbstractRatpackHttpClientTest { static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent(); @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected Set> computeHttpAttributes(URI uri) { Set> attributes = new HashSet<>(super.computeHttpAttributes(uri)); // underlying netty instrumentation does not provide these - attributes.remove(SemanticAttributes.NET_PEER_NAME); - attributes.remove(SemanticAttributes.NET_PEER_PORT); + attributes.remove(SemanticAttributes.SERVER_ADDRESS); + attributes.remove(SemanticAttributes.SERVER_PORT); return attributes; } } diff --git a/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackPooledHttpClientTest.java b/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackPooledHttpClientTest.java index c1eb8976c9bf..0223c126edfc 100644 --- a/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackPooledHttpClientTest.java +++ b/instrumentation/ratpack/ratpack-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackPooledHttpClientTest.java @@ -21,12 +21,11 @@ class RatpackPooledHttpClientTest extends AbstractRatpackPooledHttpClientTest { static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent(); @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected Set> computeHttpAttributes(URI uri) { Set> attributes = new HashSet<>(super.computeHttpAttributes(uri)); // underlying netty instrumentation does not provide these - attributes.remove(SemanticAttributes.NET_PEER_NAME); - attributes.remove(SemanticAttributes.NET_PEER_PORT); + attributes.remove(SemanticAttributes.SERVER_ADDRESS); + attributes.remove(SemanticAttributes.SERVER_PORT); return attributes; } } diff --git a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackRoutesTest.groovy b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackRoutesTest.groovy index d8468057234d..341fba10968b 100644 --- a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackRoutesTest.groovy +++ b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackRoutesTest.groovy @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.ratpack.server +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.SemanticAttributes @@ -17,7 +18,6 @@ import spock.lang.Unroll import static io.opentelemetry.api.trace.SpanKind.INTERNAL import static io.opentelemetry.api.trace.SpanKind.SERVER -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP @Unroll abstract class AbstractRatpackRoutesTest extends InstrumentationSpecification { @@ -95,22 +95,18 @@ abstract class AbstractRatpackRoutesTest extends InstrumentationSpecification { kind SERVER hasNoParent() attributes { - "$SemanticAttributes.NET_TRANSPORT" {it == null || it == IP_TCP } - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" { it == "localhost" || it == null } - "$SemanticAttributes.NET_HOST_PORT" { it == app.bindPort || it == null } - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_PORT" { it instanceof Long || it == null } - "$SemanticAttributes.NET_SOCK_HOST_ADDR" { it == "127.0.0.1" || it == null } - "$SemanticAttributes.NET_SOCK_HOST_PORT" { it instanceof Long || it == null } - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" { it == "localhost" || it == null } + "$SemanticAttributes.SERVER_PORT" { it == app.bindPort || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == null } + "$NetworkAttributes.NETWORK_PEER_PORT" { it instanceof Long || it == null } + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.USER_AGENT_ORIGINAL" String - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" "/$path" + "$SemanticAttributes.URL_SCHEME" "http" + "$SemanticAttributes.URL_PATH" "/$path" + "$SemanticAttributes.URL_QUERY" { it == "" || it == null } "$SemanticAttributes.HTTP_ROUTE" "/$route" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long } } if (hasHandlerSpan()) { diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/client/InstrumentedHttpClientTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/client/InstrumentedHttpClientTest.groovy index d79fa626042c..4b354b1a1199 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/client/InstrumentedHttpClientTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/client/InstrumentedHttpClientTest.groovy @@ -34,9 +34,9 @@ import java.util.concurrent.TimeUnit import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.SERVER -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_METHOD +import static io.opentelemetry.semconv.SemanticAttributes.HTTP_REQUEST_METHOD import static io.opentelemetry.semconv.SemanticAttributes.HTTP_ROUTE -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_STATUS_CODE +import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_STATUS_CODE class InstrumentedHttpClientTest extends Specification { @@ -100,20 +100,20 @@ class InstrumentedHttpClientTest extends Specification { spanClientData.kind == CLIENT def atts = spanClientData.attributes.asMap() atts[HTTP_ROUTE] == "/bar" - atts[HTTP_METHOD] == "GET" - atts[HTTP_STATUS_CODE] == 200L + atts[HTTP_REQUEST_METHOD] == "GET" + atts[HTTP_RESPONSE_STATUS_CODE] == 200L def attributes = spanData.attributes.asMap() attributes[HTTP_ROUTE] == "/foo" - attributes[SemanticAttributes.HTTP_TARGET] == "/foo" - attributes[HTTP_METHOD] == "GET" - attributes[HTTP_STATUS_CODE] == 200L + attributes[SemanticAttributes.URL_PATH] == "/foo" + attributes[HTTP_REQUEST_METHOD] == "GET" + attributes[HTTP_RESPONSE_STATUS_CODE] == 200L def attsApi = spanDataApi.attributes.asMap() attsApi[HTTP_ROUTE] == "/bar" - attsApi[SemanticAttributes.HTTP_TARGET] == "/bar" - attsApi[HTTP_METHOD] == "GET" - attsApi[HTTP_STATUS_CODE] == 200L + attsApi[SemanticAttributes.URL_PATH] == "/bar" + attsApi[HTTP_REQUEST_METHOD] == "GET" + attsApi[HTTP_RESPONSE_STATUS_CODE] == 200L } } } @@ -165,20 +165,20 @@ class InstrumentedHttpClientTest extends Specification { spanClientData1.kind == CLIENT def atts = spanClientData1.attributes.asMap() atts[HTTP_ROUTE] == "/foo" - atts[HTTP_METHOD] == "GET" - atts[HTTP_STATUS_CODE] == 200L + atts[HTTP_REQUEST_METHOD] == "GET" + atts[HTTP_RESPONSE_STATUS_CODE] == 200L spanClientData2.kind == CLIENT def atts2 = spanClientData2.attributes.asMap() atts2[HTTP_ROUTE] == "/bar" - atts2[HTTP_METHOD] == "GET" - atts2[HTTP_STATUS_CODE] == 200L + atts2[HTTP_REQUEST_METHOD] == "GET" + atts2[HTTP_RESPONSE_STATUS_CODE] == 200L def attributes = spanData.attributes.asMap() attributes[HTTP_ROUTE] == "/path-name" - attributes[SemanticAttributes.HTTP_TARGET] == "/path-name" - attributes[HTTP_METHOD] == "GET" - attributes[HTTP_STATUS_CODE] == 200L + attributes[SemanticAttributes.URL_PATH] == "/path-name" + attributes[HTTP_REQUEST_METHOD] == "GET" + attributes[HTTP_RESPONSE_STATUS_CODE] == 200L } } } @@ -227,16 +227,16 @@ class InstrumentedHttpClientTest extends Specification { spanClientData.kind == CLIENT def atts = spanClientData.attributes.asMap() atts[HTTP_ROUTE] == "/foo" - atts[HTTP_METHOD] == "GET" - atts[HTTP_STATUS_CODE] == null + atts[HTTP_REQUEST_METHOD] == "GET" + atts[HTTP_RESPONSE_STATUS_CODE] == null spanClientData.status.statusCode == StatusCode.ERROR spanClientData.events.first().name == "exception" def attributes = spanData.attributes.asMap() attributes[HTTP_ROUTE] == "/path-name" - attributes[SemanticAttributes.HTTP_TARGET] == "/path-name" - attributes[HTTP_METHOD] == "GET" - attributes[HTTP_STATUS_CODE] == 200L + attributes[SemanticAttributes.URL_PATH] == "/path-name" + attributes[HTTP_REQUEST_METHOD] == "GET" + attributes[HTTP_RESPONSE_STATUS_CODE] == 200L } } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerApplicationTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerApplicationTest.groovy index d354910bfb0b..11368b6b6111 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerApplicationTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerApplicationTest.groovy @@ -28,10 +28,10 @@ import spock.util.concurrent.PollingConditions import javax.inject.Singleton -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_METHOD +import static io.opentelemetry.semconv.SemanticAttributes.HTTP_REQUEST_METHOD +import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_STATUS_CODE import static io.opentelemetry.semconv.SemanticAttributes.HTTP_ROUTE -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_STATUS_CODE -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_TARGET +import static io.opentelemetry.semconv.SemanticAttributes.URL_PATH class RatpackServerApplicationTest extends Specification { @@ -48,9 +48,9 @@ class RatpackServerApplicationTest extends Specification { spanData.kind == SpanKind.SERVER attributes[HTTP_ROUTE] == "/foo" - attributes[HTTP_TARGET] == "/foo" - attributes[HTTP_METHOD] == "GET" - attributes[HTTP_STATUS_CODE] == 200L + attributes[URL_PATH] == "/foo" + attributes[HTTP_REQUEST_METHOD] == "GET" + attributes[HTTP_RESPONSE_STATUS_CODE] == 200L } } } @@ -69,15 +69,15 @@ class RatpackServerApplicationTest extends Specification { spanData.kind == SpanKind.SERVER attributes[HTTP_ROUTE] == "/bar" - attributes[HTTP_TARGET] == "/bar" - attributes[HTTP_METHOD] == "GET" - attributes[HTTP_STATUS_CODE] == 200L + attributes[URL_PATH] == "/bar" + attributes[HTTP_REQUEST_METHOD] == "GET" + attributes[HTTP_RESPONSE_STATUS_CODE] == 200L spanDataClient.kind == SpanKind.CLIENT def attributesClient = spanDataClient.attributes.asMap() attributesClient[HTTP_ROUTE] == "/other" - attributesClient[HTTP_METHOD] == "GET" - attributesClient[HTTP_STATUS_CODE] == 200L + attributesClient[HTTP_REQUEST_METHOD] == "GET" + attributesClient[HTTP_RESPONSE_STATUS_CODE] == 200L } } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerTest.groovy index 0e39a66aa96b..d7704feda634 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerTest.groovy @@ -56,9 +56,9 @@ class RatpackServerTest extends Specification { spanData.kind == SpanKind.SERVER attributes[SemanticAttributes.HTTP_ROUTE] == "/foo" - attributes[SemanticAttributes.HTTP_TARGET] == "/foo" - attributes[SemanticAttributes.HTTP_METHOD] == "GET" - attributes[SemanticAttributes.HTTP_STATUS_CODE] == 200L + attributes[SemanticAttributes.URL_PATH] == "/foo" + attributes[SemanticAttributes.HTTP_REQUEST_METHOD] == "GET" + attributes[SemanticAttributes.HTTP_RESPONSE_STATUS_CODE] == 200L } } } @@ -95,9 +95,9 @@ class RatpackServerTest extends Specification { def attributes = spanData.attributes.asMap() attributes[SemanticAttributes.HTTP_ROUTE] == "/foo" - attributes[SemanticAttributes.HTTP_TARGET] == "/foo" - attributes[SemanticAttributes.HTTP_METHOD] == "GET" - attributes[SemanticAttributes.HTTP_STATUS_CODE] == 200L + attributes[SemanticAttributes.URL_PATH] == "/foo" + attributes[SemanticAttributes.HTTP_REQUEST_METHOD] == "GET" + attributes[SemanticAttributes.HTTP_RESPONSE_STATUS_CODE] == 200L } } } @@ -153,9 +153,9 @@ class RatpackServerTest extends Specification { def attributes = spanData.attributes.asMap() attributes[SemanticAttributes.HTTP_ROUTE] == "/foo" - attributes[SemanticAttributes.HTTP_TARGET] == "/foo" - attributes[SemanticAttributes.HTTP_METHOD] == "GET" - attributes[SemanticAttributes.HTTP_STATUS_CODE] == 200L + attributes[SemanticAttributes.URL_PATH] == "/foo" + attributes[SemanticAttributes.HTTP_REQUEST_METHOD] == "GET" + attributes[SemanticAttributes.HTTP_RESPONSE_STATUS_CODE] == 200L } } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/AbstractRatpackHttpClientTest.java b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/AbstractRatpackHttpClientTest.java index c6585f1931e8..3eaeba04c04f 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/AbstractRatpackHttpClientTest.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/AbstractRatpackHttpClientTest.java @@ -154,11 +154,9 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.setHttpAttributes(this::getHttpAttributes); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected Set> getHttpAttributes(URI uri) { Set> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION); return attributes; } } diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.java index 62c0b32b0f86..ecf08e6b9461 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.java @@ -88,7 +88,6 @@ public void sendRequestWithCallback( } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.disableTestRedirects(); @@ -126,8 +125,8 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { Set> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - attributes.remove(SemanticAttributes.NET_PEER_NAME); - attributes.remove(SemanticAttributes.NET_PEER_PORT); + attributes.remove(SemanticAttributes.SERVER_ADDRESS); + attributes.remove(SemanticAttributes.SERVER_PORT); return attributes; }); } diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java index 17998289e9ee..26ea443e4962 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java @@ -10,10 +10,10 @@ import static io.opentelemetry.api.trace.SpanKind.SERVER; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.test.utils.PortUtils; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -27,7 +27,6 @@ import org.junit.jupiter.api.extension.RegisterExtension; import reactor.netty.http.client.HttpClient; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class ReactorNettyConnectionSpanTest { @RegisterExtension @@ -78,20 +77,20 @@ void testSuccessfulRequest() { .hasKind(INTERNAL) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort())), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpPort())), span -> span.hasName("CONNECT") .hasKind(INTERNAL) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpPort()), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)), span -> span.hasName("GET").hasKind(CLIENT).hasParent(trace.getSpan(0)), span -> @@ -138,9 +137,8 @@ void testFailingRequest() { .hasKind(INTERNAL) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, PortUtils.UNUSABLE_PORT)), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, PortUtils.UNUSABLE_PORT)), span -> span.hasName("CONNECT") .hasKind(INTERNAL) @@ -148,14 +146,16 @@ void testFailingRequest() { .hasStatus(StatusData.error()) .hasException(connectException) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, PortUtils.UNUSABLE_PORT), + equalTo(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), satisfies( - SemanticAttributes.NET_SOCK_PEER_ADDR, + SemanticAttributes.NETWORK_TYPE, val -> val.isIn(null, "ipv4")), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, PortUtils.UNUSABLE_PORT), + satisfies( + NetworkAttributes.NETWORK_PEER_ADDRESS, val -> val.isIn(null, "127.0.0.1")), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> val.isIn(null, (long) PortUtils.UNUSABLE_PORT))))); } } diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.java index a0503b9c976f..b4291921c934 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.java @@ -18,6 +18,7 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; import io.opentelemetry.instrumentation.test.utils.PortUtils; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; @@ -125,22 +126,19 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.setHttpAttributes(this::getHttpAttributes); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected Set> getHttpAttributes(URI uri) { Set> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); // unopened port or non routable address if ("http://localhost:61/".equals(uri.toString()) || "https://192.0.2.1/".equals(uri.toString())) { - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION); } if (uri.toString().contains("/read-timeout")) { - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); - attributes.remove(SemanticAttributes.NET_PEER_NAME); - attributes.remove(SemanticAttributes.NET_PEER_PORT); + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION); + attributes.remove(SemanticAttributes.SERVER_ADDRESS); + attributes.remove(SemanticAttributes.SERVER_PORT); } return attributes; } @@ -271,7 +269,6 @@ void shouldNotLeakConnections() { } @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void shouldEndSpanOnMonoTimeout() { HttpClient httpClient = createHttpClient(); @@ -309,11 +306,11 @@ void shouldEndSpanOnMonoTimeout() { .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_URL, uri.toString()), - equalTo(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 0), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, uri.getPort())), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.URL_FULL, uri.toString()), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, uri.getPort()), + equalTo(HttpAttributes.ERROR_TYPE, "_OTHER")), span -> span.hasName("test-http-server") .hasKind(SpanKind.SERVER) diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java index 14d9d565eced..979eeec709bc 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java @@ -16,6 +16,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.trace.SpanBuilder; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.test.server.http.RequestContextGetter; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -76,7 +77,6 @@ static void tearDown() { } @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void testSuccessfulRequest() { HttpClient httpClient = HttpClient.create(); String uri = "http://localhost:" + server.httpPort() + "/base"; @@ -109,20 +109,15 @@ void testSuccessfulRequest() { .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_URL, uri + "/"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 0), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.URL_FULL, uri + "/"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpPort()), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - AbstractLongAssert::isNotNegative), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)), span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(trace.getSpan(1)))); diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java index 16aeb4a4617f..aa8088cdf504 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java @@ -12,10 +12,11 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; import static org.assertj.core.api.Assertions.catchThrowable; import io.netty.handler.ssl.SslContextBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestServer; @@ -36,7 +37,6 @@ import reactor.netty.http.client.HttpClientResponse; import reactor.netty.tcp.SslProvider; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class ReactorNettyClientSslTest { @RegisterExtension @@ -91,29 +91,32 @@ void shouldFailSslHandshake() throws SSLException { // message .hasEventsSatisfying(ReactorNettyClientSslTest::isSslHandshakeException) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_URL, uri), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpsPort())), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.URL_FULL, uri), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpsPort()), + equalTo( + HttpAttributes.ERROR_TYPE, + SSLHandshakeException.class.getCanonicalName())), span -> span.hasName("RESOLVE") .hasKind(INTERNAL) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpsPort())), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpsPort())), span -> span.hasName("CONNECT") .hasKind(INTERNAL) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpsPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpsPort()), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)), span -> span.hasName("SSL handshake") @@ -124,10 +127,10 @@ void shouldFailSslHandshake() throws SSLException { // message .hasEventsSatisfying(ReactorNettyClientSslTest::isSslHandshakeException) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, server.httpsPort())))); + equalTo(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, server.httpsPort())))); } @Test @@ -157,49 +160,44 @@ void shouldSuccessfullyEstablishSslHandshake() throws SSLException { .hasKind(INTERNAL) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpsPort())), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpsPort())), span -> span.hasName("CONNECT") .hasKind(INTERNAL) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpsPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpsPort()), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)), span -> span.hasName("SSL handshake") .hasKind(INTERNAL) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, server.httpsPort())), + equalTo(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, server.httpsPort())), span -> span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_URL, uri), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 0), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.URL_FULL, uri), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpsPort()), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - AbstractLongAssert::isNotNegative), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpsPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)), span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(trace.getSpan(4)))); diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java index 96aecc5b2847..2b0e00adbee7 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java @@ -11,10 +11,11 @@ import static io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0.AbstractReactorNettyHttpClientTest.USER_AGENT; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.test.utils.PortUtils; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -28,7 +29,6 @@ import org.junit.jupiter.api.extension.RegisterExtension; import reactor.netty.http.client.HttpClient; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class ReactorNettyConnectionSpanTest { @RegisterExtension @@ -80,40 +80,35 @@ void testSuccessfulRequest() { .hasKind(INTERNAL) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort())), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpPort())), span -> span.hasName("CONNECT") .hasKind(INTERNAL) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TRANSPORT, "tcp"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpPort()), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)), span -> span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_URL, uri), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), - equalTo(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 0), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.URL_FULL, uri), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, server.httpPort()), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - AbstractLongAssert::isNotNegative), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort()), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)), span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(trace.getSpan(3)))); @@ -161,18 +156,19 @@ void testFailingRequest() { .hasStatus(StatusData.error()) .hasException(connectException) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_URL, uri), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, PortUtils.UNUSABLE_PORT)), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.URL_FULL, uri), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, PortUtils.UNUSABLE_PORT), + equalTo( + HttpAttributes.ERROR_TYPE, connectException.getClass().getName())), span -> span.hasName("RESOLVE") .hasKind(INTERNAL) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, PortUtils.UNUSABLE_PORT)), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, PortUtils.UNUSABLE_PORT)), span -> span.hasName("CONNECT") .hasKind(INTERNAL) @@ -180,11 +176,10 @@ void testFailingRequest() { .hasStatus(StatusData.error()) .hasException(connectException) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP), - equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_PEER_PORT, PortUtils.UNUSABLE_PORT), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, PortUtils.UNUSABLE_PORT), satisfies( - SemanticAttributes.NET_SOCK_PEER_ADDR, + NetworkAttributes.NETWORK_PEER_ADDRESS, val -> val.isIn(null, "127.0.0.1"))))); } } diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyHttpClientTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyHttpClientTest.java index 8165a4641ca9..f2578e55efad 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyHttpClientTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyHttpClientTest.java @@ -55,15 +55,14 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected Set> getHttpAttributes(URI uri) { if (uri.toString().contains("/success")) { // the single connection test does not report net.peer.* attributes; it only reports the // net.peer.sock.* attributes Set> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - attributes.remove(SemanticAttributes.NET_PEER_NAME); - attributes.remove(SemanticAttributes.NET_PEER_PORT); + attributes.remove(SemanticAttributes.SERVER_ADDRESS); + attributes.remove(SemanticAttributes.SERVER_PORT); return attributes; } return super.getHttpAttributes(uri); diff --git a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java index 37bd1d21ec0d..3981203d6aa1 100644 --- a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java +++ b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonAsyncClientTest.java @@ -14,6 +14,7 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.semconv.SemanticAttributes; @@ -45,7 +46,6 @@ import org.testcontainers.containers.GenericContainer; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public abstract class AbstractRedissonAsyncClientTest { @RegisterExtension @@ -109,9 +109,9 @@ void futureSet() throws ExecutionException, InterruptedException, TimeoutExcepti span.hasName("SET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET")))); @@ -142,9 +142,9 @@ void futureWhenComplete() throws ExecutionException, InterruptedException, Timeo span.hasName("SADD") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SADD set1 ?"), equalTo(SemanticAttributes.DB_OPERATION, "SADD")) @@ -216,9 +216,9 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo span.hasName("DB Query") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "MULTI;SET batch1 ?")) .hasParent(trace.getSpan(0)), @@ -226,9 +226,9 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo span.hasName("SET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET batch2 ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET")) @@ -237,9 +237,9 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo span.hasName("EXEC") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "EXEC"), equalTo(SemanticAttributes.DB_OPERATION, "EXEC")) diff --git a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java index f49b2518b2bd..71de86fb5eff 100644 --- a/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java +++ b/instrumentation/redisson/redisson-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/AbstractRedissonClientTest.java @@ -14,6 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.sdk.testing.assertj.TraceAssert; @@ -49,7 +50,6 @@ import org.testcontainers.containers.GenericContainer; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public abstract class AbstractRedissonClientTest { private static final Logger logger = LoggerFactory.getLogger(AbstractRedissonClientTest.class); @@ -112,9 +112,9 @@ void stringCommand() { span.hasName("SET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET"))), @@ -124,9 +124,9 @@ void stringCommand() { span.hasName("GET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "GET foo"), equalTo(SemanticAttributes.DB_OPERATION, "GET")))); @@ -150,9 +150,9 @@ void batchCommand() span.hasName("DB Query") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo( SemanticAttributes.DB_STATEMENT, "SET batch1 ?;SET batch2 ?")))); @@ -191,9 +191,9 @@ void atomicBatchCommand() { span.hasName("DB Query") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "MULTI;SET batch1 ?")) .hasParent(trace.getSpan(0)), @@ -201,9 +201,9 @@ void atomicBatchCommand() { span.hasName("SET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SET batch2 ?"), equalTo(SemanticAttributes.DB_OPERATION, "SET")) @@ -212,9 +212,9 @@ void atomicBatchCommand() { span.hasName("EXEC") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "EXEC"), equalTo(SemanticAttributes.DB_OPERATION, "EXEC")) @@ -234,9 +234,9 @@ void listCommand() { span.hasName("RPUSH") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "RPUSH list1 ?"), equalTo(SemanticAttributes.DB_OPERATION, "RPUSH")) @@ -259,9 +259,9 @@ void hashCommand() { span.hasName("EVAL") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo( SemanticAttributes.DB_STATEMENT, @@ -273,9 +273,9 @@ void hashCommand() { span.hasName("HGET") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "HGET map1 key1"), equalTo(SemanticAttributes.DB_OPERATION, "HGET")))); @@ -294,9 +294,9 @@ void setCommand() { span.hasName("SADD") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "SADD set1 ?"), equalTo(SemanticAttributes.DB_OPERATION, "SADD")))); @@ -322,9 +322,9 @@ void sortedSetCommand() span.hasName("ZADD") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "ZADD sort_set1 ? ? ? ? ? ?"), equalTo(SemanticAttributes.DB_OPERATION, "ZADD")))); @@ -348,9 +348,9 @@ void atomicLongCommand() { span.hasName("INCR") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_STATEMENT, "INCR AtomicLong"), equalTo(SemanticAttributes.DB_OPERATION, "INCR")))); @@ -374,9 +374,9 @@ void lockCommand() { span.hasName("EVAL") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_OPERATION, "EVAL"), satisfies( @@ -389,9 +389,9 @@ void lockCommand() { span.hasName("EVAL") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_OPERATION, "EVAL"), satisfies( @@ -405,9 +405,9 @@ void lockCommand() { span.hasName("DEL") .hasKind(CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port), equalTo(SemanticAttributes.DB_SYSTEM, "redis"), equalTo(SemanticAttributes.DB_OPERATION, "DEL"), satisfies( diff --git a/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/AbstractRestletServerTest.groovy b/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/AbstractRestletServerTest.groovy index c72f63a81092..d92f0f07c6c3 100644 --- a/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/AbstractRestletServerTest.groovy +++ b/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/AbstractRestletServerTest.groovy @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.restlet.v1_1 - +import io.opentelemetry.instrumentation.api.internal.HttpConstants import io.opentelemetry.instrumentation.test.base.HttpServerTest import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.restlet.Component @@ -169,6 +169,9 @@ abstract class AbstractRestletServerTest extends HttpServerTest { @Override String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return getContextPath() + endpoint.path + } switch (endpoint) { case PATH_PARAM: return getContextPath() + "/path/{id}/param" diff --git a/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/AbstractServletServerTest.groovy b/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/AbstractServletServerTest.groovy index 6f695ec6da71..d6655ab173db 100644 --- a/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/AbstractServletServerTest.groovy +++ b/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/AbstractServletServerTest.groovy @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.restlet.v1_1 - +import io.opentelemetry.instrumentation.api.internal.HttpConstants import io.opentelemetry.instrumentation.test.base.HttpServerTest import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.eclipse.jetty.server.Server @@ -64,6 +64,9 @@ abstract class AbstractServletServerTest extends HttpServerTest { @Override String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return getContextPath() + endpoint.path + } switch (endpoint) { case PATH_PARAM: return getContextPath() + "/path/{id}/param" @@ -74,6 +77,11 @@ abstract class AbstractServletServerTest extends HttpServerTest { } } + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 405 + } + static class TestApp extends Application { @Override diff --git a/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/spring/AbstractSpringServerTest.groovy b/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/spring/AbstractSpringServerTest.groovy index 0700158f93be..4c87a3a57cec 100644 --- a/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/spring/AbstractSpringServerTest.groovy +++ b/instrumentation/restlet/restlet-1.1/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_1/spring/AbstractSpringServerTest.groovy @@ -31,4 +31,8 @@ abstract class AbstractSpringServerTest extends AbstractRestletServerTest { host.attach(router) } + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 405 + } } diff --git a/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/AbstractRestletServerTest.groovy b/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/AbstractRestletServerTest.groovy index 6ed486bf27bd..70f9a5d42e6e 100644 --- a/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/AbstractRestletServerTest.groovy +++ b/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/AbstractRestletServerTest.groovy @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.restlet.v2_0 - +import io.opentelemetry.instrumentation.api.internal.HttpConstants import io.opentelemetry.instrumentation.test.base.HttpServerTest import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.restlet.Component @@ -177,6 +177,9 @@ abstract class AbstractRestletServerTest extends HttpServerTest { @Override String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return getContextPath() + endpoint.path + } switch (endpoint) { case PATH_PARAM: return getContextPath() + "/path/{id}/param" diff --git a/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/spring/AbstractSpringServerTest.groovy b/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/spring/AbstractSpringServerTest.groovy index ebb939190c96..ea2f8a569516 100644 --- a/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/spring/AbstractSpringServerTest.groovy +++ b/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/spring/AbstractSpringServerTest.groovy @@ -5,7 +5,9 @@ package io.opentelemetry.instrumentation.restlet.v2_0.spring +import io.opentelemetry.instrumentation.api.internal.HttpConstants import io.opentelemetry.instrumentation.restlet.v2_0.AbstractRestletServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.restlet.Component import org.restlet.Server import org.restlet.routing.Router @@ -31,4 +33,16 @@ abstract class AbstractSpringServerTest extends AbstractRestletServerTest { host.attach(router) } + @Override + String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return getContextPath() + endpoint.path + } + return super.expectedHttpRoute(endpoint, method) + } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 405 + } } diff --git a/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2HttpServletResponseInstrumentation.java b/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2HttpServletResponseInstrumentation.java index 74d65edde5e9..fbb68cf35bd9 100644 --- a/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2HttpServletResponseInstrumentation.java +++ b/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2HttpServletResponseInstrumentation.java @@ -27,8 +27,8 @@ /** * Class javax.servlet.http.HttpServletResponse got method getStatus only * in Servlet specification version 3.0. This means that we cannot set {@link - * io.opentelemetry.semconv.SemanticAttributes#HTTP_STATUS_CODE} attribute on the created span using - * just response object. + * io.opentelemetry.semconv.SemanticAttributes#HTTP_RESPONSE_STATUS_CODE} attribute on the created + * span using just response object. * *

This instrumentation intercepts status setting methods from Servlet 2.0 specification and * stores that status into context store. Then {@link Servlet2Advice#stopSpan(ServletRequest, diff --git a/instrumentation/spark-2.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/sparkjava/SparkJavaBasedTest.java b/instrumentation/spark-2.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/sparkjava/SparkJavaBasedTest.java index 03dda0edc26d..7e867b0e9620 100644 --- a/instrumentation/spark-2.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/sparkjava/SparkJavaBasedTest.java +++ b/instrumentation/spark-2.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/sparkjava/SparkJavaBasedTest.java @@ -11,6 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.test.utils.PortUtils; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -43,7 +44,6 @@ static void cleanupSpec() { } @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void generatesSpans() { AggregatedHttpResponse response = client.get("/param/asdf1234").aggregate().join(); String content = response.contentUtf8(); @@ -60,25 +60,20 @@ void generatesSpans() { .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.HTTP_SCHEME, "http"), - equalTo(SemanticAttributes.HTTP_TARGET, "/param/asdf1234"), - equalTo(SemanticAttributes.HTTP_METHOD, "GET"), - equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), + equalTo(SemanticAttributes.URL_SCHEME, "http"), + equalTo(SemanticAttributes.URL_PATH, "/param/asdf1234"), + equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"), + equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200), satisfies( SemanticAttributes.USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), equalTo(SemanticAttributes.HTTP_ROUTE, "/param/:param"), - equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"), - equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), - equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"), - equalTo(SemanticAttributes.NET_HOST_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"), + equalTo(SemanticAttributes.SERVER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, - val -> val.isInstanceOf(Long.class)), - equalTo(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"), - satisfies( - SemanticAttributes.NET_SOCK_HOST_PORT, + NetworkAttributes.NETWORK_PEER_PORT, val -> val.isInstanceOf(Long.class))))); } } diff --git a/instrumentation/spring/spring-data/spring-data-3.0/testing/src/reactiveTest/java/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/ReactiveSpringDataTest.java b/instrumentation/spring/spring-data/spring-data-3.0/testing/src/reactiveTest/java/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/ReactiveSpringDataTest.java index 14c999724650..54c8ff2ace9e 100644 --- a/instrumentation/spring/spring-data/spring-data-3.0/testing/src/reactiveTest/java/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/ReactiveSpringDataTest.java +++ b/instrumentation/spring/spring-data/spring-data-3.0/testing/src/reactiveTest/java/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/ReactiveSpringDataTest.java @@ -13,7 +13,7 @@ import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT; import static io.opentelemetry.semconv.SemanticAttributes.DB_SYSTEM; import static io.opentelemetry.semconv.SemanticAttributes.DB_USER; -import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_NAME; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_ADDRESS; import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.trace.SpanKind; @@ -30,7 +30,6 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class ReactiveSpringDataTest { @RegisterExtension @@ -88,6 +87,6 @@ void testFindAll() { equalTo(DB_OPERATION, "SELECT"), equalTo(DB_SQL_TABLE, "CUSTOMER"), equalTo(DB_CONNECTION_STRING, "h2:mem://localhost"), - equalTo(NET_PEER_NAME, "localhost")))); + equalTo(SERVER_ADDRESS, "localhost")))); } } diff --git a/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy b/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy index 14b95ae1efb5..94490e96163b 100644 --- a/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy +++ b/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes @@ -43,9 +44,9 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i childOf span(1) kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == "0:0:0:0:0:0:0:1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == "0:0:0:0:0:0:0:1" || it == null } + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } "$SemanticAttributes.MESSAGING_SYSTEM" "rabbitmq" } } @@ -55,9 +56,9 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i childOf span(1) kind PRODUCER attributes { - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == "0:0:0:0:0:0:0:1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == "0:0:0:0:0:0:0:1" || it == null } + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } "$SemanticAttributes.MESSAGING_SYSTEM" "rabbitmq" "$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testTopic" "$SemanticAttributes.MESSAGING_OPERATION" "publish" @@ -107,9 +108,9 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i name "basic.ack" kind CLIENT attributes { - "$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == "0:0:0:0:0:0:0:1" || it == null } - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null } + "$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == "0:0:0:0:0:0:0:1" || it == null } + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null } "$SemanticAttributes.MESSAGING_SYSTEM" "rabbitmq" } } diff --git a/instrumentation/spring/spring-rabbit-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/rabbit/v1_0/ContextPropagationTest.java b/instrumentation/spring/spring-rabbit-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/rabbit/v1_0/ContextPropagationTest.java index e33faca3b4bd..8428aad4f315 100644 --- a/instrumentation/spring/spring-rabbit-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/rabbit/v1_0/ContextPropagationTest.java +++ b/instrumentation/spring/spring-rabbit-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/rabbit/v1_0/ContextPropagationTest.java @@ -13,6 +13,7 @@ import com.rabbitmq.client.ConnectionFactory; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.GlobalTraceUtil; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -44,7 +45,6 @@ import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public class ContextPropagationTest { @RegisterExtension @@ -91,7 +91,7 @@ static void teardown() { private static List getAssertions( String destination, String operation, - String sockAddr, + String peerAddress, boolean routingKey, boolean testHeaders) { List assertions = @@ -105,10 +105,11 @@ private static List getAssertions( if (operation != null) { assertions.add(equalTo(SemanticAttributes.MESSAGING_OPERATION, operation)); } - if (sockAddr != null) { - assertions.add(equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, sockAddr)); + if (peerAddress != null) { + assertions.add(equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")); + assertions.add(equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, peerAddress)); assertions.add( - satisfies(SemanticAttributes.NET_SOCK_PEER_PORT, AbstractLongAssert::isNotNegative)); + satisfies(NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative)); } if (routingKey) { assertions.add( @@ -209,9 +210,10 @@ public void test(boolean testHeaders) throws Exception { span.hasName("basic.ack") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - SemanticAttributes.NET_SOCK_PEER_PORT, + NetworkAttributes.NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative), equalTo(SemanticAttributes.MESSAGING_SYSTEM, "rabbitmq"))); }); diff --git a/instrumentation/spring/spring-web/spring-web-3.1/library/src/test/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebInstrumentationTest.java b/instrumentation/spring/spring-web/spring-web-3.1/library/src/test/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebInstrumentationTest.java index 4733e4e57f31..2b161492f2db 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/library/src/test/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebInstrumentationTest.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/library/src/test/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebInstrumentationTest.java @@ -8,7 +8,6 @@ import static java.util.Collections.singletonList; import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; @@ -97,20 +96,17 @@ public void sendRequestWithCallback( } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.disableTestCircularRedirects(); optionsBuilder.disableTestReadTimeout(); optionsBuilder.disableTestNonStandardHttpMethod(); - if (SemconvStability.emitOldHttpSemconv()) { - optionsBuilder.setHttpAttributes( - uri -> { - Set> attributes = - new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); - return attributes; - }); - } + + optionsBuilder.setHttpAttributes( + uri -> { + Set> attributes = + new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION); + return attributes; + }); } } diff --git a/instrumentation/spring/spring-web/spring-web-3.1/testing/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/web/SpringRestTemplateTest.java b/instrumentation/spring/spring-web/spring-web-3.1/testing/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/web/SpringRestTemplateTest.java index d0e3112b8abc..384f04d641e8 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/testing/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/web/SpringRestTemplateTest.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/testing/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/web/SpringRestTemplateTest.java @@ -96,5 +96,8 @@ public void sendRequestWithCallback( @Override protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.setMaxRedirects(20); + + // no enum value for TEST + optionsBuilder.disableTestNonStandardHttpMethod(); } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java index 57c56683eb21..149b910e22dd 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java @@ -13,27 +13,20 @@ import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_MESSAGE; import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_STACKTRACE; import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_TYPE; -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_METHOD; -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH; -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH; +import static io.opentelemetry.semconv.SemanticAttributes.HTTP_REQUEST_METHOD; +import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_STATUS_CODE; import static io.opentelemetry.semconv.SemanticAttributes.HTTP_ROUTE; -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_SCHEME; -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_STATUS_CODE; -import static io.opentelemetry.semconv.SemanticAttributes.HTTP_TARGET; -import static io.opentelemetry.semconv.SemanticAttributes.NET_HOST_NAME; -import static io.opentelemetry.semconv.SemanticAttributes.NET_HOST_PORT; -import static io.opentelemetry.semconv.SemanticAttributes.NET_PROTOCOL_NAME; -import static io.opentelemetry.semconv.SemanticAttributes.NET_PROTOCOL_VERSION; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_HOST_ADDR; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_HOST_PORT; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_ADDR; -import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_PORT; -import static io.opentelemetry.semconv.SemanticAttributes.NET_TRANSPORT; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; +import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_PROTOCOL_VERSION; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_ADDRESS; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_PORT; +import static io.opentelemetry.semconv.SemanticAttributes.URL_PATH; +import static io.opentelemetry.semconv.SemanticAttributes.URL_SCHEME; import static io.opentelemetry.semconv.SemanticAttributes.USER_AGENT_ORIGINAL; import static org.junit.jupiter.api.Named.named; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.sdk.testing.assertj.EventDataAssert; @@ -76,7 +69,6 @@ SpringWebFluxTestApplication.class, SpringWebfluxTest.ForceNettyAutoConfiguration.class }) -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public class SpringWebfluxTest { @TestConfiguration static class ForceNettyAutoConfiguration { @@ -120,33 +112,19 @@ void basicGetTest(Parameter parameter) { .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_TRANSPORT, IP_TCP), - equalTo(NET_PROTOCOL_NAME, "http"), - equalTo(NET_PROTOCOL_VERSION, "1.1"), - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_HOST_NAME, "localhost"), - satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(HTTP_TARGET, parameter.urlPath), - equalTo(HTTP_METHOD, "GET"), - equalTo(HTTP_STATUS_CODE, 200), - equalTo(HTTP_SCHEME, "http"), - satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), - equalTo(HTTP_ROUTE, parameter.urlPathWithVariables), - satisfies( - HTTP_REQUEST_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull())), + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull()))), + NetworkAttributes.NETWORK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + equalTo(SERVER_ADDRESS, "localhost"), + satisfies(SERVER_PORT, val -> val.isInstanceOf(Long.class)), + equalTo(URL_PATH, parameter.urlPath), + equalTo(HTTP_REQUEST_METHOD, "GET"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(URL_SCHEME, "http"), + satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), + equalTo(HTTP_ROUTE, parameter.urlPathWithVariables)), span -> { if (parameter.annotatedMethod == null) { // Functional API @@ -246,33 +224,19 @@ void getAsyncResponseTest(Parameter parameter) { .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_TRANSPORT, IP_TCP), - equalTo(NET_PROTOCOL_NAME, "http"), - equalTo(NET_PROTOCOL_VERSION, "1.1"), - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_HOST_NAME, "localhost"), - satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(HTTP_TARGET, parameter.urlPath), - equalTo(HTTP_METHOD, "GET"), - equalTo(HTTP_STATUS_CODE, 200), - equalTo(HTTP_SCHEME, "http"), - satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), - equalTo(HTTP_ROUTE, parameter.urlPathWithVariables), - satisfies( - HTTP_REQUEST_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull())), + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull()))), + NetworkAttributes.NETWORK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + equalTo(SERVER_ADDRESS, "localhost"), + satisfies(SERVER_PORT, val -> val.isInstanceOf(Long.class)), + equalTo(URL_PATH, parameter.urlPath), + equalTo(HTTP_REQUEST_METHOD, "GET"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(URL_SCHEME, "http"), + satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), + equalTo(HTTP_ROUTE, parameter.urlPathWithVariables)), span -> { if (parameter.annotatedMethod == null) { // Functional API @@ -367,33 +331,19 @@ void createSpanDuringHandlerFunctionTest(Parameter parameter) { .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_TRANSPORT, IP_TCP), - equalTo(NET_PROTOCOL_NAME, "http"), - equalTo(NET_PROTOCOL_VERSION, "1.1"), - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_HOST_NAME, "localhost"), - satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(HTTP_TARGET, parameter.urlPath), - equalTo(HTTP_METHOD, "GET"), - equalTo(HTTP_STATUS_CODE, 200), - equalTo(HTTP_SCHEME, "http"), - satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), - equalTo(HTTP_ROUTE, parameter.urlPathWithVariables), - satisfies( - HTTP_REQUEST_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull())), + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull()))), + NetworkAttributes.NETWORK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + equalTo(SERVER_ADDRESS, "localhost"), + satisfies(SERVER_PORT, val -> val.isInstanceOf(Long.class)), + equalTo(URL_PATH, parameter.urlPath), + equalTo(HTTP_REQUEST_METHOD, "GET"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(URL_SCHEME, "http"), + satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), + equalTo(HTTP_ROUTE, parameter.urlPathWithVariables)), span -> { if (parameter.annotatedMethod == null) { // Functional API @@ -453,33 +403,19 @@ void get404Test() { .hasNoParent() .hasStatus(StatusData.unset()) .hasAttributesSatisfyingExactly( - equalTo(NET_TRANSPORT, IP_TCP), - equalTo(NET_PROTOCOL_NAME, "http"), - equalTo(NET_PROTOCOL_VERSION, "1.1"), - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_HOST_NAME, "localhost"), - satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(HTTP_TARGET, "/notfoundgreet"), - equalTo(HTTP_METHOD, "GET"), - equalTo(HTTP_STATUS_CODE, 404), - equalTo(HTTP_SCHEME, "http"), - satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), - equalTo(HTTP_ROUTE, "/**"), + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - HTTP_REQUEST_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull())), - satisfies( - HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull()))), + NetworkAttributes.NETWORK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + equalTo(SERVER_ADDRESS, "localhost"), + satisfies(SERVER_PORT, val -> val.isInstanceOf(Long.class)), + equalTo(URL_PATH, "/notfoundgreet"), + equalTo(HTTP_REQUEST_METHOD, "GET"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 404), + equalTo(URL_SCHEME, "http"), + satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), + equalTo(HTTP_ROUTE, "/**")), span -> span.hasName("ResourceWebHandler.handle") .hasKind(SpanKind.INTERNAL) @@ -527,33 +463,19 @@ void basicPostTest() { .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_TRANSPORT, IP_TCP), - equalTo(NET_PROTOCOL_NAME, "http"), - equalTo(NET_PROTOCOL_VERSION, "1.1"), - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_HOST_NAME, "localhost"), - satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(HTTP_TARGET, "/echo"), - equalTo(HTTP_METHOD, "POST"), - equalTo(HTTP_STATUS_CODE, 202), - equalTo(HTTP_SCHEME, "http"), - satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), - equalTo(HTTP_ROUTE, "/echo"), - satisfies( - HTTP_REQUEST_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull())), + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull()))), + NetworkAttributes.NETWORK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + equalTo(SERVER_ADDRESS, "localhost"), + satisfies(SERVER_PORT, val -> val.isInstanceOf(Long.class)), + equalTo(URL_PATH, "/echo"), + equalTo(HTTP_REQUEST_METHOD, "POST"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 202), + equalTo(URL_SCHEME, "http"), + satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), + equalTo(HTTP_ROUTE, "/echo")), span -> span.hasName(EchoHandlerFunction.class.getSimpleName() + ".handle") .hasKind(SpanKind.INTERNAL) @@ -581,33 +503,20 @@ void getToBadEndpointTest(Parameter parameter) { .hasNoParent() .hasStatus(StatusData.error()) .hasAttributesSatisfyingExactly( - equalTo(NET_TRANSPORT, IP_TCP), - equalTo(NET_PROTOCOL_NAME, "http"), - equalTo(NET_PROTOCOL_VERSION, "1.1"), - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_HOST_NAME, "localhost"), - satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(HTTP_TARGET, parameter.urlPath), - equalTo(HTTP_METHOD, "GET"), - equalTo(HTTP_STATUS_CODE, 500), - equalTo(HTTP_SCHEME, "http"), + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + satisfies( + NetworkAttributes.NETWORK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + equalTo(SERVER_ADDRESS, "localhost"), + satisfies(SERVER_PORT, val -> val.isInstanceOf(Long.class)), + equalTo(URL_PATH, parameter.urlPath), + equalTo(HTTP_REQUEST_METHOD, "GET"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 500), + equalTo(URL_SCHEME, "http"), satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), equalTo(HTTP_ROUTE, parameter.urlPathWithVariables), - satisfies( - HTTP_REQUEST_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull())), - satisfies( - HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull()))), + equalTo(HttpAttributes.ERROR_TYPE, "500")), span -> { if (parameter.annotatedMethod == null) { // Functional API @@ -674,33 +583,19 @@ void redirectTest() { .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_TRANSPORT, IP_TCP), - equalTo(NET_PROTOCOL_NAME, "http"), - equalTo(NET_PROTOCOL_VERSION, "1.1"), - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_HOST_NAME, "localhost"), - satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(HTTP_TARGET, "/double-greet-redirect"), - equalTo(HTTP_METHOD, "GET"), - equalTo(HTTP_STATUS_CODE, 307), - equalTo(HTTP_SCHEME, "http"), - satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), - equalTo(HTTP_ROUTE, "/double-greet-redirect"), + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - HTTP_REQUEST_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull())), - satisfies( - HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull()))), + NetworkAttributes.NETWORK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + equalTo(SERVER_ADDRESS, "localhost"), + satisfies(SERVER_PORT, val -> val.isInstanceOf(Long.class)), + equalTo(URL_PATH, "/double-greet-redirect"), + equalTo(HTTP_REQUEST_METHOD, "GET"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 307), + equalTo(URL_SCHEME, "http"), + satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), + equalTo(HTTP_ROUTE, "/double-greet-redirect")), span -> span.hasName("RedirectComponent$$Lambda.handle") .hasKind(SpanKind.INTERNAL) @@ -716,33 +611,19 @@ void redirectTest() { .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_TRANSPORT, IP_TCP), - equalTo(NET_PROTOCOL_NAME, "http"), - equalTo(NET_PROTOCOL_VERSION, "1.1"), - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_HOST_NAME, "localhost"), - satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(HTTP_TARGET, "/double-greet"), - equalTo(HTTP_METHOD, "GET"), - equalTo(HTTP_STATUS_CODE, 200), - equalTo(HTTP_SCHEME, "http"), - satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), - equalTo(HTTP_ROUTE, "/double-greet"), - satisfies( - HTTP_REQUEST_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull())), + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull()))), + NetworkAttributes.NETWORK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + equalTo(SERVER_ADDRESS, "localhost"), + satisfies(SERVER_PORT, val -> val.isInstanceOf(Long.class)), + equalTo(URL_PATH, "/double-greet"), + equalTo(HTTP_REQUEST_METHOD, "GET"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(URL_SCHEME, "http"), + satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), + equalTo(HTTP_ROUTE, "/double-greet")), span -> { assertThat(trace.getSpan(1).getName()) .contains(SPRING_APP_CLASS_ANON_NESTED_CLASS_PREFIX, ".handle"); @@ -781,33 +662,19 @@ void multipleGetsToDelayingRoute(Parameter parameter) { .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( - equalTo(NET_TRANSPORT, IP_TCP), - equalTo(NET_PROTOCOL_NAME, "http"), - equalTo(NET_PROTOCOL_VERSION, "1.1"), - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_HOST_NAME, "localhost"), - satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(HTTP_TARGET, parameter.urlPath), - equalTo(HTTP_METHOD, "GET"), - equalTo(HTTP_STATUS_CODE, 200), - equalTo(HTTP_SCHEME, "http"), - satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), - equalTo(HTTP_ROUTE, parameter.urlPathWithVariables), - satisfies( - HTTP_REQUEST_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull())), + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), satisfies( - HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull()))), + NetworkAttributes.NETWORK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + equalTo(SERVER_ADDRESS, "localhost"), + satisfies(SERVER_PORT, val -> val.isInstanceOf(Long.class)), + equalTo(URL_PATH, parameter.urlPath), + equalTo(HTTP_REQUEST_METHOD, "GET"), + equalTo(HTTP_RESPONSE_STATUS_CODE, 200), + equalTo(URL_SCHEME, "http"), + satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), + equalTo(HTTP_ROUTE, parameter.urlPathWithVariables)), span -> { if (parameter.annotatedMethod == null) { // Functional API @@ -876,32 +743,19 @@ void cancelRequestTest() throws Exception { .hasNoParent() .hasStatus(StatusData.unset()) .hasAttributesSatisfyingExactly( - equalTo(NET_TRANSPORT, IP_TCP), - equalTo(NET_PROTOCOL_NAME, "http"), - equalTo(NET_PROTOCOL_VERSION, "1.1"), - equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_PEER_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_SOCK_HOST_ADDR, "127.0.0.1"), - satisfies(NET_SOCK_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(NET_HOST_NAME, "localhost"), - satisfies(NET_HOST_PORT, val -> val.isInstanceOf(Long.class)), - equalTo(HTTP_TARGET, "/slow"), - equalTo(HTTP_METHOD, "GET"), - equalTo(HTTP_SCHEME, "http"), + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + satisfies( + NetworkAttributes.NETWORK_PEER_PORT, + val -> val.isInstanceOf(Long.class)), + equalTo(SERVER_ADDRESS, "localhost"), + satisfies(SERVER_PORT, val -> val.isInstanceOf(Long.class)), + equalTo(URL_PATH, "/slow"), + equalTo(HTTP_REQUEST_METHOD, "GET"), + equalTo(URL_SCHEME, "http"), satisfies(USER_AGENT_ORIGINAL, val -> val.isInstanceOf(String.class)), equalTo(HTTP_ROUTE, "/slow"), - satisfies( - HTTP_REQUEST_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull())), - satisfies( - HTTP_RESPONSE_CONTENT_LENGTH, - val -> - val.satisfiesAnyOf( - v -> assertThat(v).isInstanceOf(Long.class), - v -> assertThat(v).isNull()))), + equalTo(HttpAttributes.ERROR_TYPE, "_OTHER")), span -> span.hasName("SpringWebFluxTestApplication$$Lambda.handle") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ControllerSpringWebFluxServerTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ControllerSpringWebFluxServerTest.java index c3ac74a4af9f..9de16a7aee66 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ControllerSpringWebFluxServerTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/ControllerSpringWebFluxServerTest.java @@ -79,5 +79,12 @@ protected void configure(HttpServerTestOptions options) { // Mono that the controller returns completes) should end before the server span (which needs // the result of the Mono) options.setVerifyServerSpanEndTime(false); + + options.setResponseCodeOnNonStandardHttpMethod(405); + + // TODO fails on java 21 + // span name set to "HTTP + // org.springframework.web.reactive.function.server.RequestPredicates$$Lambda/0x00007fa574969238@4aaf6fa2" + options.disableTestNonStandardHttpMethod(); } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/HandlerSpringWebFluxServerTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/HandlerSpringWebFluxServerTest.java index d33cb788e9c7..936d4d715621 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/HandlerSpringWebFluxServerTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/base/HandlerSpringWebFluxServerTest.java @@ -15,6 +15,7 @@ import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_TYPE; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; @@ -77,5 +78,15 @@ protected void configure(HttpServerTestOptions options) { // Mono that the controller returns completes) should end before the server span (which needs // the result of the Mono) options.setVerifyServerSpanEndTime(false); + + options.setResponseCodeOnNonStandardHttpMethod(404); + } + + @Override + public String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (HttpConstants._OTHER.equals(method)) { + return getContextPath() + "/**"; + } + return super.expectedHttpRoute(endpoint, method); } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationTest.java index 58c5d08062e5..73cb904f9545 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerInstrumentationTest.java @@ -44,5 +44,7 @@ protected void configure(HttpServerTestOptions options) { } return expectedHttpRoute(endpoint, method); }); + + options.disableTestNonStandardHttpMethod(); } } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/testing/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/AbstractSpringWebfluxClientInstrumentationTest.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/testing/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/AbstractSpringWebfluxClientInstrumentationTest.java index 489d746d22f5..7d01bef49355 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/testing/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/AbstractSpringWebfluxClientInstrumentationTest.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/testing/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/AbstractSpringWebfluxClientInstrumentationTest.java @@ -8,7 +8,6 @@ import static java.util.Objects.requireNonNull; import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; @@ -65,23 +64,22 @@ public void sendRequestWithCallback( } @Override - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected void configure(HttpClientTestOptions.Builder optionsBuilder) { optionsBuilder.disableTestRedirects(); + // no enum value for non standard method + optionsBuilder.disableTestNonStandardHttpMethod(); + // timeouts leak the scope optionsBuilder.disableTestReadTimeout(); - if (SemconvStability.emitOldHttpSemconv()) { - optionsBuilder.setHttpAttributes( - uri -> { - Set> attributes = - new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); - return attributes; - }); - } + optionsBuilder.setHttpAttributes( + uri -> { + Set> attributes = + new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION); + return attributes; + }); optionsBuilder.setClientSpanErrorMapper( (uri, throwable) -> { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/build.gradle.kts b/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/build.gradle.kts index a03906d1e9b4..0cae732453e6 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/build.gradle.kts +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/build.gradle.kts @@ -43,6 +43,8 @@ dependencies { } tasks.withType().configureEach { + systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) + // TODO run tests both with and without experimental span attributes jvmArgs("-Dotel.instrumentation.spring-webmvc.experimental-span-attributes=true") // required on jdk17 diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy b/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy index eae63b7d233c..39daa0f2afa7 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy @@ -12,4 +12,9 @@ class SpringBootBasedTest extends AbstractSpringBootBasedTest { Class securityConfigClass() { SecurityConfig } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + Boolean.getBoolean("testLatestDeps") ? 500 : 200 + } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy b/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy index 7ebe6f98bdda..10bb5b57b33e 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy @@ -17,4 +17,9 @@ class ServletFilterTest extends AbstractServletFilterTest { Class filterConfigClass() { ServletFilterConfig } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + Boolean.getBoolean("testLatestDeps") ? 500 : 200 + } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/WebMvcHttpServerTest.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/WebMvcHttpServerTest.java index 040d74e1457d..c7ad71cf5e60 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/WebMvcHttpServerTest.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/WebMvcHttpServerTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.spring.webmvc.v5_3; +import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; @@ -42,6 +43,9 @@ protected void configure(HttpServerTestOptions options) { if (endpoint == ServerEndpoint.PATH_PARAM) { return CONTEXT_PATH + "/path/{id}/param"; } + if (HttpConstants._OTHER.equals(method)) { + return CONTEXT_PATH + endpoint.getPath(); + } return expectedHttpRoute(endpoint, method); }); } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/ServletFilterTest.groovy b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/ServletFilterTest.groovy index 42d94ca6ba6a..bc5c6ff11bfb 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/ServletFilterTest.groovy +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/ServletFilterTest.groovy @@ -49,4 +49,9 @@ class ServletFilterTest extends AbstractServletFilterTest { super.responseSpan(trace, index, parent, method, endpoint) } } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 400 + } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/SpringBootBasedTest.groovy b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/SpringBootBasedTest.groovy index a37e190e5194..d743de0d9d1a 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/SpringBootBasedTest.groovy +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/groovy/SpringBootBasedTest.groovy @@ -31,4 +31,9 @@ class SpringBootBasedTest extends AbstractSpringBootBasedTest { super.handlerSpan(trace, index, parent, method, endpoint) } } + + @Override + int getResponseCodeOnNonStandardHttpMethod() { + 400 + } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/test/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/WebMvcHttpServerTest.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/test/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/WebMvcHttpServerTest.java index dec3c378d93b..82cea6e4828a 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/test/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/WebMvcHttpServerTest.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/test/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/WebMvcHttpServerTest.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.spring.webmvc.v6_0; +import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; @@ -42,7 +43,12 @@ protected void configure(HttpServerTestOptions options) { if (endpoint == ServerEndpoint.PATH_PARAM) { return CONTEXT_PATH + "/path/{id}/param"; } + if (HttpConstants._OTHER.equals(method)) { + return CONTEXT_PATH + endpoint.getPath(); + } return expectedHttpRoute(endpoint, method); }); + + options.setResponseCodeOnNonStandardHttpMethod(501); } } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-common/testing/src/main/groovy/boot/AbstractSpringBootBasedTest.groovy b/instrumentation/spring/spring-webmvc/spring-webmvc-common/testing/src/main/groovy/boot/AbstractSpringBootBasedTest.groovy index 324e24605f3d..47f7082e84e8 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-common/testing/src/main/groovy/boot/AbstractSpringBootBasedTest.groovy +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-common/testing/src/main/groovy/boot/AbstractSpringBootBasedTest.groovy @@ -6,6 +6,7 @@ package boot import io.opentelemetry.api.trace.StatusCode +import io.opentelemetry.instrumentation.api.internal.HttpConstants import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest @@ -86,6 +87,9 @@ abstract class AbstractSpringBootBasedTest extends HttpServerTest implements AgentTestT } String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return getContextPath() + endpoint.path + } switch (endpoint) { case PATH_PARAM: return getContextPath() + "/path/{id}/param" diff --git a/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy b/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy index 1567b5b11598..47ea7357fee3 100644 --- a/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy +++ b/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy @@ -15,6 +15,7 @@ import com.twilio.http.TwilioRestClient import com.twilio.rest.api.v2010.account.Call import com.twilio.rest.api.v2010.account.Message import com.twilio.type.PhoneNumber +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.semconv.SemanticAttributes import org.apache.http.HttpEntity @@ -248,12 +249,11 @@ class TwilioClientTest extends AgentInstrumentationSpecification { kind CLIENT childOf span(1) attributes { - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com" - "$SemanticAttributes.HTTP_METHOD.key" "POST" - "$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" - "$SemanticAttributes.HTTP_STATUS_CODE.key" 200 + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS.key" "api.twilio.com" + "$SemanticAttributes.HTTP_REQUEST_METHOD.key" "POST" + "$SemanticAttributes.URL_FULL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE.key" 200 } } } @@ -315,12 +315,12 @@ class TwilioClientTest extends AgentInstrumentationSpecification { childOf span(1) status ERROR attributes { - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com" - "$SemanticAttributes.HTTP_METHOD.key" "POST" - "$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" - "$SemanticAttributes.HTTP_STATUS_CODE.key" 500 + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS.key" "api.twilio.com" + "$SemanticAttributes.HTTP_REQUEST_METHOD.key" "POST" + "$SemanticAttributes.URL_FULL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE.key" 500 + "$HttpAttributes.ERROR_TYPE" "500" } } span(3) { @@ -328,12 +328,11 @@ class TwilioClientTest extends AgentInstrumentationSpecification { kind CLIENT childOf span(1) attributes { - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com" - "$SemanticAttributes.HTTP_METHOD.key" "POST" - "$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" - "$SemanticAttributes.HTTP_STATUS_CODE.key" 200 + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS.key" "api.twilio.com" + "$SemanticAttributes.HTTP_REQUEST_METHOD.key" "POST" + "$SemanticAttributes.URL_FULL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE.key" 200 } } } @@ -402,12 +401,12 @@ class TwilioClientTest extends AgentInstrumentationSpecification { childOf span(1) status ERROR attributes { - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com" - "$SemanticAttributes.HTTP_METHOD.key" "POST" - "$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" - "$SemanticAttributes.HTTP_STATUS_CODE.key" 500 + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS.key" "api.twilio.com" + "$SemanticAttributes.HTTP_REQUEST_METHOD.key" "POST" + "$SemanticAttributes.URL_FULL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE.key" 500 + "$HttpAttributes.ERROR_TYPE" "500" } } span(3) { @@ -415,12 +414,11 @@ class TwilioClientTest extends AgentInstrumentationSpecification { kind CLIENT childOf span(1) attributes { - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com" - "$SemanticAttributes.HTTP_METHOD.key" "POST" - "$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" - "$SemanticAttributes.HTTP_STATUS_CODE.key" 200 + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS.key" "api.twilio.com" + "$SemanticAttributes.HTTP_REQUEST_METHOD.key" "POST" + "$SemanticAttributes.URL_FULL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE.key" 200 } } } diff --git a/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy b/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy index 7b67bd3ba17b..eca585f827fc 100644 --- a/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy +++ b/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy @@ -8,7 +8,6 @@ import io.opentelemetry.api.trace.Span import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes -import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint @@ -144,39 +143,18 @@ class UndertowServerTest extends HttpServerTest implements AgentTestTr eventName "after-event" } - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.HTTP_CLIENT_IP" TEST_CLIENT_IP - "$SemanticAttributes.HTTP_SCHEME" uri.getScheme() - "$SemanticAttributes.HTTP_TARGET" uri.getPath() - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" uri.host - "$SemanticAttributes.NET_HOST_PORT" uri.port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.CLIENT_ADDRESS" TEST_CLIENT_IP - "$SemanticAttributes.URL_SCHEME" uri.getScheme() - "$SemanticAttributes.URL_PATH" uri.getPath() - "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" - "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 - "$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT - "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - "$NetworkAttributes.NETWORK_PEER_PORT" Long - } + attributes { + "$SemanticAttributes.CLIENT_ADDRESS" TEST_CLIENT_IP + "$SemanticAttributes.URL_SCHEME" uri.getScheme() + "$SemanticAttributes.URL_PATH" uri.getPath() + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { @@ -214,39 +192,18 @@ class UndertowServerTest extends HttpServerTest implements AgentTestTr } errorEvent(Exception, "exception after sending response", 2) - if (SemconvStability.emitOldHttpSemconv()) { - attributes { - "$SemanticAttributes.HTTP_CLIENT_IP" TEST_CLIENT_IP - "$SemanticAttributes.HTTP_SCHEME" uri.getScheme() - "$SemanticAttributes.HTTP_TARGET" uri.getPath() - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_HOST_NAME" uri.host - "$SemanticAttributes.NET_HOST_PORT" uri.port - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long - } - } - if (SemconvStability.emitStableHttpSemconv()) { - attributes { - "$SemanticAttributes.CLIENT_ADDRESS" TEST_CLIENT_IP - "$SemanticAttributes.URL_SCHEME" uri.getScheme() - "$SemanticAttributes.URL_PATH" uri.getPath() - "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" - "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 - "$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT - "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.SERVER_ADDRESS" uri.host - "$SemanticAttributes.SERVER_PORT" uri.port - "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" - "$NetworkAttributes.NETWORK_PEER_PORT" Long - } + attributes { + "$SemanticAttributes.CLIENT_ADDRESS" TEST_CLIENT_IP + "$SemanticAttributes.URL_SCHEME" uri.getScheme() + "$SemanticAttributes.URL_PATH" uri.getPath() + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$SemanticAttributes.SERVER_ADDRESS" uri.host + "$SemanticAttributes.SERVER_PORT" uri.port + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long } } span(1) { diff --git a/instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/test/groovy/client/VertxHttpClientTest.groovy b/instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/test/groovy/client/VertxHttpClientTest.groovy index d184935ccaaf..4907638c5ab0 100644 --- a/instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/test/groovy/client/VertxHttpClientTest.groovy +++ b/instrumentation/vertx/vertx-http-client/vertx-http-client-3.0/javaagent/src/test/groovy/client/VertxHttpClientTest.groovy @@ -92,10 +92,9 @@ class VertxHttpClientTest extends HttpClientTest implements A @Override Set> httpAttributes(URI uri) { def attributes = super.httpAttributes(uri) - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME) - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION) - attributes.remove(SemanticAttributes.NET_PEER_NAME) - attributes.remove(SemanticAttributes.NET_PEER_PORT) + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION) + attributes.remove(SemanticAttributes.SERVER_ADDRESS) + attributes.remove(SemanticAttributes.SERVER_PORT) return attributes } diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/build.gradle.kts b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/build.gradle.kts index 5dd1a7031ccc..daaceb361662 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/build.gradle.kts +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/build.gradle.kts @@ -54,8 +54,10 @@ testing { } } +val testLatestDeps = findProperty("testLatestDeps") as Boolean + tasks { - if (findProperty("testLatestDeps") as Boolean) { + if (testLatestDeps) { // disable regular test running and compiling tasks when latest dep test task is run named("test") { enabled = false @@ -63,17 +65,21 @@ tasks { named("compileTestGroovy") { enabled = false } + } - check { - dependsOn(testing.suites) - } + named("latestDepTest") { + enabled = testLatestDeps + } - val testStableSemconv by registering(Test::class) { - jvmArgs("-Dotel.semconv-stability.opt-in=http") - } + check { + dependsOn(testing.suites) + } - check { - dependsOn(testStableSemconv) - } + val testStableSemconv by registering(Test::class) { + jvmArgs("-Dotel.semconv-stability.opt-in=http") + } + + check { + dependsOn(testStableSemconv) } } diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy index 93e948b484a5..a80d73578bb3 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy @@ -7,6 +7,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry import io.opentelemetry.api.trace.Span import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.context.Context +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.SemanticAttributes @@ -24,7 +25,6 @@ import static VertxReactiveWebServer.TEST_REQUEST_ID_PARAMETER import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.SERVER import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP class VertxReactivePropagationTest extends AgentInstrumentationSpecification { @Shared @@ -63,22 +63,17 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { kind SERVER hasNoParent() attributes { - "$SemanticAttributes.NET_TRANSPORT" { it == null || it == IP_TCP } - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" Long - "$SemanticAttributes.HTTP_TARGET" "/listProducts" - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_SCHEME" "http" + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" Long + "$SemanticAttributes.URL_PATH" "/listProducts" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" "/listProducts" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long } } span(1) { @@ -158,22 +153,18 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { kind SERVER childOf(span(0)) attributes { - "$SemanticAttributes.NET_TRANSPORT" { it == null || it == IP_TCP } - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" Long - "$SemanticAttributes.HTTP_TARGET" "$baseUrl?$TEST_REQUEST_ID_PARAMETER=$requestId" - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_SCHEME" "http" + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" Long + "$SemanticAttributes.URL_PATH" baseUrl + "$SemanticAttributes.URL_QUERY" "$TEST_REQUEST_ID_PARAMETER=$requestId" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" "/listProducts" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long "${TEST_REQUEST_ID_ATTRIBUTE}" requestId } } diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxHttpServerTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxHttpServerTest.groovy index d732601f5b7c..a8f6ad7e7fa7 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxHttpServerTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxHttpServerTest.groovy @@ -5,9 +5,10 @@ package server - +import io.opentelemetry.instrumentation.api.internal.HttpConstants import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.vertx.core.DeploymentOptions import io.vertx.core.Promise import io.vertx.core.Vertx @@ -68,6 +69,14 @@ class VertxRxHttpServerTest extends HttpServerTest implements AgentTestTr return false } + @Override + String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return getContextPath() + endpoint.path + } + return super.expectedHttpRoute(endpoint, method) + } + protected Class verticle() { return VertxReactiveWebServer } diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy index 93e948b484a5..a80d73578bb3 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy @@ -7,6 +7,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry import io.opentelemetry.api.trace.Span import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.context.Context +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.SemanticAttributes @@ -24,7 +25,6 @@ import static VertxReactiveWebServer.TEST_REQUEST_ID_PARAMETER import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.SERVER import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP class VertxReactivePropagationTest extends AgentInstrumentationSpecification { @Shared @@ -63,22 +63,17 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { kind SERVER hasNoParent() attributes { - "$SemanticAttributes.NET_TRANSPORT" { it == null || it == IP_TCP } - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" Long - "$SemanticAttributes.HTTP_TARGET" "/listProducts" - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_SCHEME" "http" + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" Long + "$SemanticAttributes.URL_PATH" "/listProducts" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" "/listProducts" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long } } span(1) { @@ -158,22 +153,18 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { kind SERVER childOf(span(0)) attributes { - "$SemanticAttributes.NET_TRANSPORT" { it == null || it == IP_TCP } - "$SemanticAttributes.NET_PROTOCOL_NAME" "http" - "$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1" - "$SemanticAttributes.NET_SOCK_PEER_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_PEER_PORT" Long - "$SemanticAttributes.NET_SOCK_HOST_ADDR" "127.0.0.1" - "$SemanticAttributes.NET_SOCK_HOST_PORT" Long - "$SemanticAttributes.NET_HOST_NAME" "localhost" - "$SemanticAttributes.NET_HOST_PORT" Long - "$SemanticAttributes.HTTP_TARGET" "$baseUrl?$TEST_REQUEST_ID_PARAMETER=$requestId" - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_SCHEME" "http" + "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1" + "$NetworkAttributes.NETWORK_PEER_ADDRESS" "127.0.0.1" + "$NetworkAttributes.NETWORK_PEER_PORT" Long + "$SemanticAttributes.SERVER_ADDRESS" "localhost" + "$SemanticAttributes.SERVER_PORT" Long + "$SemanticAttributes.URL_PATH" baseUrl + "$SemanticAttributes.URL_QUERY" "$TEST_REQUEST_ID_PARAMETER=$requestId" + "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET" + "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200 + "$SemanticAttributes.URL_SCHEME" "http" "$SemanticAttributes.USER_AGENT_ORIGINAL" String "$SemanticAttributes.HTTP_ROUTE" "/listProducts" - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long "${TEST_REQUEST_ID_ATTRIBUTE}" requestId } } diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/client/VertxRxCircuitBreakerWebClientTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/client/VertxRxCircuitBreakerWebClientTest.groovy index 5e33f8a8df93..eb48b67e07b4 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/client/VertxRxCircuitBreakerWebClientTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/client/VertxRxCircuitBreakerWebClientTest.groovy @@ -99,13 +99,17 @@ class VertxRxCircuitBreakerWebClientTest extends HttpClientTest> false } + @Override + boolean testNonStandardHttpMethod() { + false + } + @Override Set> httpAttributes(URI uri) { def attributes = super.httpAttributes(uri) - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME) - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION) - attributes.remove(SemanticAttributes.NET_PEER_NAME) - attributes.remove(SemanticAttributes.NET_PEER_PORT) + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION) + attributes.remove(SemanticAttributes.SERVER_ADDRESS) + attributes.remove(SemanticAttributes.SERVER_PORT) return attributes } diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/client/VertxRxWebClientTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/client/VertxRxWebClientTest.groovy index c120e5e94871..b8711f5d38bf 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/client/VertxRxWebClientTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/client/VertxRxWebClientTest.groovy @@ -85,13 +85,17 @@ class VertxRxWebClientTest extends HttpClientTest> implement false } + @Override + boolean testNonStandardHttpMethod() { + false + } + @Override Set> httpAttributes(URI uri) { def attributes = super.httpAttributes(uri) - attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME) - attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION) - attributes.remove(SemanticAttributes.NET_PEER_NAME) - attributes.remove(SemanticAttributes.NET_PEER_PORT) + attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION) + attributes.remove(SemanticAttributes.SERVER_ADDRESS) + attributes.remove(SemanticAttributes.SERVER_PORT) return attributes } diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxHttpServerTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxHttpServerTest.groovy index d74f7ab9e48b..c6f8077c21e7 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxHttpServerTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxHttpServerTest.groovy @@ -5,9 +5,10 @@ package server - +import io.opentelemetry.instrumentation.api.internal.HttpConstants import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.vertx.core.DeploymentOptions import io.vertx.core.Future import io.vertx.core.Vertx @@ -68,6 +69,14 @@ class VertxRxHttpServerTest extends HttpServerTest implements AgentTestTr return false } + @Override + String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return getContextPath() + endpoint.path + } + return super.expectedHttpRoute(endpoint, method) + } + protected Class verticle() { return VertxReactiveWebServer } diff --git a/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientTest.java b/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientTest.java index fedb0c944073..ca5891b4e212 100644 --- a/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientTest.java +++ b/instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientTest.java @@ -16,8 +16,8 @@ import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_MESSAGE; import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_STACKTRACE; import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_TYPE; -import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_NAME; -import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_PORT; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_ADDRESS; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_PORT; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; @@ -51,7 +51,6 @@ import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class VertxSqlClientTest { private static final Logger logger = LoggerFactory.getLogger(VertxSqlClientTest.class); @@ -142,8 +141,8 @@ void testSimpleSelect() throws Exception { equalTo(DB_STATEMENT, "select * from test"), equalTo(DB_OPERATION, "SELECT"), equalTo(DB_SQL_TABLE, "test"), - equalTo(NET_PEER_NAME, "localhost"), - equalTo(NET_PEER_PORT, port)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, port)), span -> span.hasName("callback") .hasKind(SpanKind.INTERNAL) @@ -196,8 +195,8 @@ void testInvalidQuery() throws Exception { equalTo(DB_NAME, DB), equalTo(DB_USER, USER_DB), equalTo(DB_STATEMENT, "invalid"), - equalTo(NET_PEER_NAME, "localhost"), - equalTo(NET_PEER_PORT, port)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, port)), span -> span.hasName("callback") .hasKind(SpanKind.INTERNAL) @@ -232,8 +231,8 @@ private static void assertPreparedSelect() { equalTo(DB_STATEMENT, "select * from test where id = $?"), equalTo(DB_OPERATION, "SELECT"), equalTo(DB_SQL_TABLE, "test"), - equalTo(NET_PEER_NAME, "localhost"), - equalTo(NET_PEER_PORT, port)))); + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, port)))); } @Test @@ -262,8 +261,8 @@ void testBatch() throws Exception { equalTo(DB_STATEMENT, "insert into test values ($?, $?) returning *"), equalTo(DB_OPERATION, "INSERT"), equalTo(DB_SQL_TABLE, "test"), - equalTo(NET_PEER_NAME, "localhost"), - equalTo(NET_PEER_PORT, port)))); + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, port)))); } @Test @@ -348,8 +347,8 @@ void testManyQueries() throws Exception { equalTo(DB_STATEMENT, "select * from test"), equalTo(DB_OPERATION, "SELECT"), equalTo(DB_SQL_TABLE, "test"), - equalTo(NET_PEER_NAME, "localhost"), - equalTo(NET_PEER_PORT, port)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, port)), span -> span.hasName("callback") .hasKind(SpanKind.INTERNAL) @@ -414,8 +413,8 @@ void testConcurrency() throws Exception { equalTo(DB_STATEMENT, "select * from test where id = $?"), equalTo(DB_OPERATION, "SELECT"), equalTo(DB_SQL_TABLE, "test"), - equalTo(NET_PEER_NAME, "localhost"), - equalTo(NET_PEER_PORT, port)), + equalTo(SERVER_ADDRESS, "localhost"), + equalTo(SERVER_PORT, port)), span -> span.hasName("callback") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/vertx/vertx-web-3.0/javaagent/src/latestDepTest/groovy/server/VertxLatestHttpServerTest.groovy b/instrumentation/vertx/vertx-web-3.0/javaagent/src/latestDepTest/groovy/server/VertxLatestHttpServerTest.groovy index 7a679da334b1..db274a9d8bed 100644 --- a/instrumentation/vertx/vertx-web-3.0/javaagent/src/latestDepTest/groovy/server/VertxLatestHttpServerTest.groovy +++ b/instrumentation/vertx/vertx-web-3.0/javaagent/src/latestDepTest/groovy/server/VertxLatestHttpServerTest.groovy @@ -5,6 +5,7 @@ package server + import io.vertx.core.AbstractVerticle class VertxLatestHttpServerTest extends AbstractVertxHttpServerTest { diff --git a/instrumentation/vertx/vertx-web-3.0/testing/src/main/groovy/server/AbstractVertxHttpServerTest.groovy b/instrumentation/vertx/vertx-web-3.0/testing/src/main/groovy/server/AbstractVertxHttpServerTest.groovy index 4675dba96f50..2233ed424bff 100644 --- a/instrumentation/vertx/vertx-web-3.0/testing/src/main/groovy/server/AbstractVertxHttpServerTest.groovy +++ b/instrumentation/vertx/vertx-web-3.0/testing/src/main/groovy/server/AbstractVertxHttpServerTest.groovy @@ -5,9 +5,10 @@ package server - +import io.opentelemetry.instrumentation.api.internal.HttpConstants import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.vertx.core.AbstractVerticle import io.vertx.core.DeploymentOptions import io.vertx.core.Vertx @@ -56,4 +57,12 @@ abstract class AbstractVertxHttpServerTest extends HttpServerTest impleme // server spans are ended inside of the controller spans return false } + + @Override + String expectedHttpRoute(ServerEndpoint endpoint, String method) { + if (method == HttpConstants._OTHER) { + return getContextPath() + endpoint.path + } + return super.expectedHttpRoute(endpoint, method) + } } diff --git a/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java b/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java index 8e1d74ec8d6d..9576184f3bee 100644 --- a/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java @@ -68,7 +68,6 @@ public LogRecordExporter logRecordExporter() { } @Test - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 void shouldSendTelemetry() throws InterruptedException { testRestTemplate.getForObject(OtelSpringStarterSmokeTestController.URL, String.class); @@ -96,8 +95,8 @@ void shouldSendTelemetry() throws InterruptedException { spanDataAssert -> spanDataAssert .hasKind(SpanKind.SERVER) - .hasAttribute(SemanticAttributes.HTTP_METHOD, "GET") - .hasAttribute(SemanticAttributes.HTTP_STATUS_CODE, 200L) + .hasAttribute(SemanticAttributes.HTTP_REQUEST_METHOD, "GET") + .hasAttribute(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L) .hasAttribute(SemanticAttributes.HTTP_ROUTE, "/ping"))); // Metric diff --git a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/AppServerTest.groovy b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/AppServerTest.groovy index 285cc6f7f47d..faf55ebf4f7f 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/AppServerTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/AppServerTest.groovy @@ -6,6 +6,8 @@ package io.opentelemetry.smoketest import io.opentelemetry.proto.trace.v1.Span +import io.opentelemetry.semconv.ResourceAttributes +import io.opentelemetry.semconv.SemanticAttributes import spock.lang.Shared import spock.lang.Unroll @@ -112,20 +114,19 @@ abstract class AppServerTest extends SmokeTest { traces.countSpansByName(getSpanName('/app/headers')) == 1 and: "The span for the initial web request" - traces.countFilteredAttributes("http.target", "/app/greeting") == 1 + traces.countFilteredAttributes(SemanticAttributes.URL_PATH.key, "/app/greeting") == 1 and: "Client span for the remote call" - traces.countFilteredAttributes("http.url", "http://localhost:8080/app/headers") == 1 + traces.countFilteredAttributes(SemanticAttributes.URL_FULL.key, "http://localhost:8080/app/headers") == 1 and: "Server span for the remote call" - traces.countFilteredAttributes("http.target", "/app/headers") == 1 + traces.countFilteredAttributes(SemanticAttributes.URL_PATH.key, "/app/headers") == 1 and: "Number of spans with http protocol version" - traces.countFilteredAttributes("net.protocol.name", "http") == 3 - traces.countFilteredAttributes("net.protocol.version", "1.1") == 3 + traces.countFilteredAttributes(SemanticAttributes.NETWORK_PROTOCOL_VERSION.key, "1.1") == 3 and: "Number of spans tagged with current otel library version" - traces.countFilteredResourceAttributes("telemetry.auto.version", currentAgentVersion) == 3 + traces.countFilteredResourceAttributes(ResourceAttributes.TELEMETRY_AUTO_VERSION.key, currentAgentVersion) == 3 and: "Number of spans tagged with expected OS type" traces.countFilteredResourceAttributes(OS_TYPE.key, isWindows ? WINDOWS : LINUX) == 3 @@ -157,10 +158,10 @@ abstract class AppServerTest extends SmokeTest { traces.countSpansByName(getSpanName('/app/hello.txt')) == 1 and: "The span for the initial web request" - traces.countFilteredAttributes("http.target", "/app/hello.txt") == 1 + traces.countFilteredAttributes(SemanticAttributes.URL_PATH.key, "/app/hello.txt") == 1 and: "Number of spans tagged with current otel library version" - traces.countFilteredResourceAttributes("telemetry.auto.version", currentAgentVersion) == 1 + traces.countFilteredResourceAttributes(ResourceAttributes.TELEMETRY_AUTO_VERSION.key, currentAgentVersion) == 1 and: "Number of spans tagged with expected OS type" traces.countFilteredResourceAttributes(OS_TYPE.key, isWindows ? WINDOWS : LINUX) == 1 @@ -191,10 +192,10 @@ abstract class AppServerTest extends SmokeTest { traces.countSpansByName(getSpanName('/app/file-that-does-not-exist')) == 1 and: "The span for the initial web request" - traces.countFilteredAttributes("http.target", "/app/file-that-does-not-exist") == 1 + traces.countFilteredAttributes(SemanticAttributes.URL_PATH.key, "/app/file-that-does-not-exist") == 1 and: "Number of spans tagged with current otel library version" - traces.countFilteredResourceAttributes("telemetry.auto.version", currentAgentVersion) == traces.countSpans() + traces.countFilteredResourceAttributes(ResourceAttributes.TELEMETRY_AUTO_VERSION.key, currentAgentVersion) == traces.countSpans() and: "Number of spans tagged with expected OS type" traces.countFilteredResourceAttributes(OS_TYPE.key, isWindows ? WINDOWS : LINUX) == traces.countSpans() @@ -227,14 +228,13 @@ abstract class AppServerTest extends SmokeTest { traces.countSpansByName(getSpanName('/app/WEB-INF/web.xml')) == 1 and: "The span for the initial web request" - traces.countFilteredAttributes("http.target", "/app/WEB-INF/web.xml") == 1 + traces.countFilteredAttributes(SemanticAttributes.URL_PATH.key, "/app/WEB-INF/web.xml") == 1 and: "Number of spans with http protocol version" - traces.countFilteredAttributes("net.protocol.name", "http") == 1 - traces.countFilteredAttributes("net.protocol.version", "1.1") == 1 + traces.countFilteredAttributes(SemanticAttributes.NETWORK_PROTOCOL_VERSION.key, "1.1") == 1 and: "Number of spans tagged with current otel library version" - traces.countFilteredResourceAttributes("telemetry.auto.version", currentAgentVersion) == traces.countSpans() + traces.countFilteredResourceAttributes(ResourceAttributes.TELEMETRY_AUTO_VERSION.key, currentAgentVersion) == traces.countSpans() and: "Number of spans tagged with expected OS type" traces.countFilteredResourceAttributes(OS_TYPE.key, isWindows ? WINDOWS : LINUX) == traces.countSpans() @@ -270,10 +270,10 @@ abstract class AppServerTest extends SmokeTest { traces.countFilteredEventAttributes('exception.message', 'This is expected') == 1 and: "The span for the initial web request" - traces.countFilteredAttributes("http.target", "/app/exception") == 1 + traces.countFilteredAttributes(SemanticAttributes.URL_PATH.key, "/app/exception") == 1 and: "Number of spans tagged with current otel library version" - traces.countFilteredResourceAttributes("telemetry.auto.version", currentAgentVersion) == traces.countSpans() + traces.countFilteredResourceAttributes(ResourceAttributes.TELEMETRY_AUTO_VERSION.key, currentAgentVersion) == traces.countSpans() and: "Number of spans tagged with expected OS type" traces.countFilteredResourceAttributes(OS_TYPE.key, isWindows ? WINDOWS : LINUX) == traces.countSpans() @@ -305,14 +305,13 @@ abstract class AppServerTest extends SmokeTest { traces.countSpansByName(getSpanName('/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless')) == 1 and: "The span for the initial web request" - traces.countFilteredAttributes("http.target", "/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless") == 1 + traces.countFilteredAttributes(SemanticAttributes.URL_PATH.key, "/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless") == 1 and: "Number of spans with http protocol version" - traces.countFilteredAttributes("net.protocol.name", "http") == 1 - traces.countFilteredAttributes("net.protocol.version", "1.1") == 1 + traces.countFilteredAttributes(SemanticAttributes.NETWORK_PROTOCOL_VERSION.key, "1.1") == 1 and: "Number of spans tagged with current otel library version" - traces.countFilteredResourceAttributes("telemetry.auto.version", currentAgentVersion) == traces.countSpans() + traces.countFilteredResourceAttributes(ResourceAttributes.TELEMETRY_AUTO_VERSION.key, currentAgentVersion) == traces.countSpans() and: "Number of spans tagged with expected OS type" traces.countFilteredResourceAttributes(OS_TYPE.key, isWindows ? WINDOWS : LINUX) == traces.countSpans() @@ -347,20 +346,19 @@ abstract class AppServerTest extends SmokeTest { traces.countSpansByName(getSpanName('/app/headers')) == 1 and: "The span for the initial web request" - traces.countFilteredAttributes("http.target", "/app/asyncgreeting") == 1 + traces.countFilteredAttributes(SemanticAttributes.URL_PATH.key, "/app/asyncgreeting") == 1 and: "Client span for the remote call" - traces.countFilteredAttributes("http.url", "http://localhost:8080/app/headers") == 1 + traces.countFilteredAttributes(SemanticAttributes.URL_FULL.key, "http://localhost:8080/app/headers") == 1 and: "Server span for the remote call" - traces.countFilteredAttributes("http.target", "/app/headers") == 1 + traces.countFilteredAttributes(SemanticAttributes.URL_PATH.key, "/app/headers") == 1 and: "Number of spans with http protocol version" - traces.countFilteredAttributes("net.protocol.name", "http") == 3 - traces.countFilteredAttributes("net.protocol.version", "1.1") == 3 + traces.countFilteredAttributes(SemanticAttributes.NETWORK_PROTOCOL_VERSION.key, "1.1") == 3 and: "Number of spans tagged with current otel library version" - traces.countFilteredResourceAttributes("telemetry.auto.version", currentAgentVersion) == 3 + traces.countFilteredResourceAttributes(ResourceAttributes.TELEMETRY_AUTO_VERSION.key, currentAgentVersion) == 3 and: "Number of spans tagged with expected OS type" traces.countFilteredResourceAttributes(OS_TYPE.key, isWindows ? WINDOWS : LINUX) == 3 diff --git a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy index 73b54a5e440a..24f5ab28ab5f 100644 --- a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy +++ b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy @@ -9,6 +9,7 @@ import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.api.trace.Span import io.opentelemetry.api.trace.SpanId import io.opentelemetry.api.trace.SpanKind +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes import io.opentelemetry.instrumentation.api.internal.HttpConstants import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.test.InstrumentationSpecification @@ -176,7 +177,7 @@ abstract class HttpServerTest extends InstrumentationSpecification imple Set> httpAttributes(ServerEndpoint endpoint) { [ SemanticAttributes.HTTP_ROUTE, - SemanticAttributes.NET_SOCK_PEER_PORT + NetworkAttributes.NETWORK_PEER_PORT ] as Set } 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 e279a2faf5eb..b15de4e9f0cf 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 @@ -5,11 +5,10 @@ package io.opentelemetry.instrumentation.testing.junit.http; -import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.comparingRootSpanAttribute; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; +import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.catchThrowable; import static org.junit.jupiter.api.Assumptions.assumeTrue; @@ -18,11 +17,11 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.test.utils.PortUtils; import io.opentelemetry.instrumentation.testing.InstrumentationTestRunner; -import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; import io.opentelemetry.sdk.testing.assertj.TraceAssert; import io.opentelemetry.sdk.trace.data.SpanData; @@ -33,7 +32,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -512,31 +510,18 @@ void captureHttpHeaders() throws Exception { testing.waitAndAssertTraces( trace -> { trace.hasSpansSatisfyingExactly( - span -> { - assertClientSpan(span, uri, method, responseCode, null).hasNoParent(); - List attributeAssertions = new ArrayList<>(); - if (SemconvStability.emitOldHttpSemconv()) { - attributeAssertions.add( - equalTo( - AttributeKey.stringArrayKey("http.request.header.x_test_request"), - singletonList("test"))); - attributeAssertions.add( - equalTo( - AttributeKey.stringArrayKey("http.response.header.x_test_response"), - singletonList("test"))); - } - if (SemconvStability.emitStableHttpSemconv()) { - attributeAssertions.add( - equalTo( - AttributeKey.stringArrayKey("http.request.header.x-test-request"), - singletonList("test"))); - attributeAssertions.add( - equalTo( - AttributeKey.stringArrayKey("http.response.header.x-test-response"), - singletonList("test"))); - } - span.hasAttributesSatisfying(attributeAssertions); - }, + span -> + assertClientSpan(span, uri, method, responseCode, null) + .hasNoParent() + .hasAttributesSatisfying( + asList( + equalTo( + AttributeKey.stringArrayKey("http.request.header.x-test-request"), + singletonList("test")), + equalTo( + AttributeKey.stringArrayKey( + "http.response.header.x-test-response"), + singletonList("test")))), span -> assertServerSpan(span).hasParent(trace.getSpan(0))); }); } @@ -975,132 +960,81 @@ void highConcurrencyOnSingleConnection() { } // Visible for spock bridge. - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 SpanDataAssert assertClientSpan( SpanDataAssert span, URI uri, String method, @Nullable Integer responseCode, @Nullable Integer resendCount) { - Set> httpClientAttributes = - getAttributeKeys(options.getHttpAttributes().apply(uri)); + Set> httpClientAttributes = options.getHttpAttributes().apply(uri); return span.hasName(options.getExpectedClientSpanNameMapper().apply(uri, method)) .hasKind(SpanKind.CLIENT) .hasAttributesSatisfying( attrs -> { - // TODO: Move to test knob rather than always treating as optional - if (SemconvStability.emitOldHttpSemconv() - && attrs.get(SemanticAttributes.NET_TRANSPORT) != null) { - assertThat(attrs).containsEntry(SemanticAttributes.NET_TRANSPORT, IP_TCP); - } - 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 netProtocolKey = - getAttributeKey(SemanticAttributes.NET_PROTOCOL_NAME); - if (SemconvStability.emitStableHttpSemconv()) { - // only protocol names different from "http" are emitted - assertThat(attrs).doesNotContainKey(netProtocolKey); - } else if (attrs.get(netProtocolKey) != null) { - assertThat(attrs).containsEntry(netProtocolKey, "http"); - } - AttributeKey netProtocolVersionKey = - getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION); - if (httpClientAttributes.contains(netProtocolVersionKey)) { + // we're opting out of these attributes in the new semconv + assertThat(attrs) + .doesNotContainKey(SemanticAttributes.NETWORK_TRANSPORT) + .doesNotContainKey(SemanticAttributes.NETWORK_TYPE) + .doesNotContainKey(SemanticAttributes.NETWORK_PROTOCOL_NAME); + if (httpClientAttributes.contains(SemanticAttributes.NETWORK_PROTOCOL_VERSION)) { // TODO(anuraaga): Support HTTP/2 - assertThat(attrs).containsEntry(netProtocolVersionKey, "1.1"); + assertThat(attrs).containsEntry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"); } - AttributeKey netPeerNameKey = - getAttributeKey(SemanticAttributes.NET_PEER_NAME); - if (httpClientAttributes.contains(netPeerNameKey)) { - assertThat(attrs).containsEntry(netPeerNameKey, uri.getHost()); + + if (httpClientAttributes.contains(SemanticAttributes.SERVER_ADDRESS)) { + assertThat(attrs).containsEntry(SemanticAttributes.SERVER_ADDRESS, uri.getHost()); } - AttributeKey netPeerPortKey = getAttributeKey(SemanticAttributes.NET_PEER_PORT); - if (httpClientAttributes.contains(netPeerPortKey)) { + if (httpClientAttributes.contains(SemanticAttributes.SERVER_PORT)) { int uriPort = uri.getPort(); if (uriPort <= 0) { - if (attrs.get(netPeerPortKey) != null) { + if (attrs.get(SemanticAttributes.SERVER_PORT) != null) { int effectivePort = "https".equals(uri.getScheme()) ? 443 : 80; - assertThat(attrs).containsEntry(netPeerPortKey, effectivePort); + assertThat(attrs).containsEntry(SemanticAttributes.SERVER_PORT, effectivePort); } // alternatively, peer port is not emitted -- and that's fine too } else { - assertThat(attrs).containsEntry(netPeerPortKey, uriPort); + assertThat(attrs).containsEntry(SemanticAttributes.SERVER_PORT, uriPort); } } - if (uri.getPort() == PortUtils.UNUSABLE_PORT || uri.getHost().equals("192.0.2.1")) { - // In these cases the peer connection is not established, so the HTTP client should - // not report any socket-level attributes - assertThat(attrs).doesNotContainKey("net.sock.family"); - // TODO netty sometimes reports net.sock.peer.* in connection error test - // .doesNotContainKey("net.sock.peer.addr") - // .doesNotContainKey("net.sock.peer.name") - // .doesNotContainKey("net.sock.peer.port"); - - } else { + if (uri.getPort() != PortUtils.UNUSABLE_PORT && !uri.getHost().equals("192.0.2.1")) { // TODO: Move to test knob rather than always treating as optional - AttributeKey netSockPeerAddrKey = - getAttributeKey(SemanticAttributes.NET_SOCK_PEER_ADDR); - if (attrs.get(netSockPeerAddrKey) != null) { - assertThat(attrs).containsEntry(netSockPeerAddrKey, "127.0.0.1"); + if (attrs.get(NetworkAttributes.NETWORK_PEER_ADDRESS) != null) { + assertThat(attrs) + .containsEntry(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"); } - AttributeKey netSockPeerPortKey = - getAttributeKey(SemanticAttributes.NET_SOCK_PEER_PORT); - if (attrs.get(netSockPeerPortKey) != null) { + if (attrs.get(NetworkAttributes.NETWORK_PEER_PORT) != null) { assertThat(attrs) .containsEntry( - netSockPeerPortKey, + NetworkAttributes.NETWORK_PEER_PORT, Objects.equals(uri.getScheme(), "https") ? server.httpsPort() : server.httpPort()); } } - AttributeKey httpUrlKey = getAttributeKey(SemanticAttributes.HTTP_URL); - if (httpClientAttributes.contains(httpUrlKey)) { - assertThat(attrs).containsEntry(httpUrlKey, uri.toString()); + if (httpClientAttributes.contains(SemanticAttributes.URL_FULL)) { + assertThat(attrs).containsEntry(SemanticAttributes.URL_FULL, uri.toString()); } - AttributeKey httpMethodKey = getAttributeKey(SemanticAttributes.HTTP_METHOD); - if (httpClientAttributes.contains(httpMethodKey)) { - assertThat(attrs).containsEntry(httpMethodKey, method); + if (httpClientAttributes.contains(SemanticAttributes.HTTP_REQUEST_METHOD)) { + assertThat(attrs).containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, method); } + // opt-in, not collected by default assertThat(attrs).doesNotContainKey(SemanticAttributes.USER_AGENT_ORIGINAL); - AttributeKey httpRequestLengthKey = - getAttributeKey(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH); - if (attrs.get(httpRequestLengthKey) != null) { - assertThat(attrs) - .hasEntrySatisfying( - httpRequestLengthKey, length -> assertThat(length).isNotNegative()); - } - AttributeKey httpResponseLengthKey = - getAttributeKey(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH); - if (attrs.get(httpResponseLengthKey) != null) { - assertThat(attrs) - .hasEntrySatisfying( - httpResponseLengthKey, length -> assertThat(length).isNotNegative()); - } - - AttributeKey httpResponseStatusKey = - getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE); if (responseCode != null) { - assertThat(attrs).containsEntry(httpResponseStatusKey, (long) responseCode); - if (responseCode >= 400 && SemconvStability.emitStableHttpSemconv()) { + assertThat(attrs) + .containsEntry( + SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, (long) responseCode); + if (responseCode >= 400) { assertThat(attrs) .containsEntry(HttpAttributes.ERROR_TYPE, String.valueOf(responseCode)); } } else { - assertThat(attrs).doesNotContainKey(httpResponseStatusKey); - if (SemconvStability.emitStableHttpSemconv()) { - // TODO: add more detailed assertions, per url - assertThat(attrs).containsKey(stringKey("error.type")); - } + assertThat(attrs).doesNotContainKey(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE); + // TODO: add more detailed assertions, per url + assertThat(attrs).containsKey(HttpAttributes.ERROR_TYPE); } if (resendCount != null) { @@ -1112,21 +1046,6 @@ SpanDataAssert assertClientSpan( }); } - protected static AttributeKey getAttributeKey(AttributeKey oldKey) { - return SemconvStabilityUtil.getAttributeKey(oldKey); - } - - private static Set> getAttributeKeys(Set> oldKeys) { - if (!SemconvStability.emitStableHttpSemconv()) { - return oldKeys; - } - Set> result = new HashSet<>(); - for (AttributeKey key : oldKeys) { - result.add(getAttributeKey(key)); - } - return result; - } - // Visible for spock bridge. static SpanDataAssert assertServerSpan(SpanDataAssert span) { return span.hasName("test-http-server").hasKind(SpanKind.SERVER); diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java index 852146ddfcd6..e16438c9e51e 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java @@ -16,7 +16,6 @@ import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP; import static org.junit.jupiter.api.Assumptions.assumeTrue; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -28,6 +27,7 @@ import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.context.propagation.TextMapSetter; import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.GlobalTraceUtil; @@ -719,7 +719,6 @@ protected List> errorPageSpanAssertions( } @CanIgnoreReturnValue - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected SpanDataAssert assertServerSpan( SpanDataAssert span, String method, ServerEndpoint endpoint, int statusCode) { @@ -738,38 +737,35 @@ protected SpanDataAssert assertServerSpan( span.hasAttributesSatisfying( attrs -> { - if (SemconvStability.emitOldHttpSemconv() - && attrs.get(SemanticAttributes.NET_TRANSPORT) != null) { - assertThat(attrs).containsEntry(SemanticAttributes.NET_TRANSPORT, IP_TCP); - } - if (SemconvStability.emitStableHttpSemconv()) { - // we're opting out of these attributes in the new semconv + // we're opting out of these attributes in the new semconv + assertThat(attrs) + .doesNotContainKey(SemanticAttributes.NETWORK_TRANSPORT) + .doesNotContainKey(SemanticAttributes.NETWORK_TYPE) + .doesNotContainKey(SemanticAttributes.NETWORK_PROTOCOL_NAME); + + if (attrs.get(SemanticAttributes.NETWORK_PROTOCOL_VERSION) != null) { assertThat(attrs) - .doesNotContainKey(SemanticAttributes.NETWORK_TRANSPORT) - .doesNotContainKey(SemanticAttributes.NETWORK_TYPE); + .hasEntrySatisfying( + SemanticAttributes.NETWORK_PROTOCOL_VERSION, + entry -> assertThat(entry).isIn("1.1", "2.0")); } - assertThat(attrs) - .containsEntry(getAttributeKey(SemanticAttributes.NET_HOST_NAME), "localhost"); + assertThat(attrs).containsEntry(SemanticAttributes.SERVER_ADDRESS, "localhost"); // TODO: Move to test knob rather than always treating as optional // TODO: once httpAttributes test knob is used, verify default port values - AttributeKey netHostPortKey = getAttributeKey(SemanticAttributes.NET_HOST_PORT); - if (attrs.get(netHostPortKey) != null) { - assertThat(attrs).containsEntry(netHostPortKey, port); + if (attrs.get(SemanticAttributes.SERVER_PORT) != null) { + assertThat(attrs).containsEntry(SemanticAttributes.SERVER_PORT, port); } - AttributeKey netSockPeerAddrKey = - getAttributeKey(SemanticAttributes.NET_SOCK_PEER_ADDR); - if (attrs.get(netSockPeerAddrKey) != null) { + if (attrs.get(NetworkAttributes.NETWORK_PEER_ADDRESS) != null) { assertThat(attrs) - .containsEntry(netSockPeerAddrKey, options.sockPeerAddr.apply(endpoint)); + .containsEntry( + NetworkAttributes.NETWORK_PEER_ADDRESS, options.sockPeerAddr.apply(endpoint)); } - AttributeKey netSockPeerPortKey = - getAttributeKey(SemanticAttributes.NET_SOCK_PEER_PORT); - if (attrs.get(netSockPeerPortKey) != null) { + if (attrs.get(NetworkAttributes.NETWORK_PEER_PORT) != null) { assertThat(attrs) .hasEntrySatisfying( - netSockPeerPortKey, + NetworkAttributes.NETWORK_PEER_PORT, value -> assertThat(value) .isInstanceOf(Long.class) @@ -778,133 +774,62 @@ protected SpanDataAssert assertServerSpan( assertThat(attrs) .hasEntrySatisfying( - getAttributeKey(SemanticAttributes.HTTP_CLIENT_IP), + SemanticAttributes.CLIENT_ADDRESS, entry -> assertThat(entry) .satisfiesAnyOf( value -> assertThat(value).isNull(), value -> assertThat(value).isEqualTo(TEST_CLIENT_IP))); - if (SemconvStability.emitStableHttpSemconv()) { - // client.port is opt-in - assertThat(attrs).doesNotContainKey(SemanticAttributes.CLIENT_PORT); - } - assertThat(attrs).containsEntry(getAttributeKey(SemanticAttributes.HTTP_METHOD), method); + // client.port is opt-in + assertThat(attrs).doesNotContainKey(SemanticAttributes.CLIENT_PORT); - assertThat(attrs) - .containsEntry(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), statusCode); - if (statusCode >= 500 && SemconvStability.emitStableHttpSemconv()) { + assertThat(attrs).containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, method); + + assertThat(attrs).containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, statusCode); + if (statusCode >= 500) { assertThat(attrs).containsEntry(HttpAttributes.ERROR_TYPE, String.valueOf(statusCode)); } - AttributeKey netProtocolKey = - getAttributeKey(SemanticAttributes.NET_PROTOCOL_NAME); - if (SemconvStability.emitStableHttpSemconv()) { - // only protocol names different from "http" are emitted - assertThat(attrs).doesNotContainKey(netProtocolKey); - } else if (attrs.get(netProtocolKey) != null) { - assertThat(attrs).containsEntry(netProtocolKey, "http"); - } - AttributeKey netProtocolVersionKey = - getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION); - if (attrs.get(netProtocolVersionKey) != null) { - assertThat(attrs) - .hasEntrySatisfying( - netProtocolVersionKey, entry -> assertThat(entry).isIn("1.1", "2.0")); - } assertThat(attrs).containsEntry(SemanticAttributes.USER_AGENT_ORIGINAL, TEST_USER_AGENT); - assertThat(attrs).containsEntry(getAttributeKey(SemanticAttributes.HTTP_SCHEME), "http"); + assertThat(attrs).containsEntry(SemanticAttributes.URL_SCHEME, "http"); if (endpoint != INDEXED_CHILD) { - if (SemconvStability.emitOldHttpSemconv()) { - assertThat(attrs) - .containsEntry( - SemanticAttributes.HTTP_TARGET, - endpoint.resolvePath(address).getPath() - + (endpoint.getQuery() != null ? "?" + endpoint.getQuery() : "")); - } - if (SemconvStability.emitStableHttpSemconv()) { - assertThat(attrs) - .containsEntry( - SemanticAttributes.URL_PATH, endpoint.resolvePath(address).getPath()); - if (endpoint.getQuery() != null) { - assertThat(attrs).containsEntry(SemanticAttributes.URL_QUERY, endpoint.getQuery()); - } + assertThat(attrs) + .containsEntry( + SemanticAttributes.URL_PATH, endpoint.resolvePath(address).getPath()); + if (endpoint.getQuery() != null) { + assertThat(attrs).containsEntry(SemanticAttributes.URL_QUERY, endpoint.getQuery()); } } - AttributeKey httpRequestLengthKey = - getAttributeKey(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH); - if (attrs.get(httpRequestLengthKey) != null) { - assertThat(attrs) - .hasEntrySatisfying( - httpRequestLengthKey, entry -> assertThat(entry).isNotNegative()); - } - AttributeKey httpResponseLengthKey = - getAttributeKey(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH); - if (attrs.get(httpResponseLengthKey) != null) { - assertThat(attrs) - .hasEntrySatisfying( - httpResponseLengthKey, entry -> assertThat(entry).isNotNegative()); - } if (httpAttributes.contains(SemanticAttributes.HTTP_ROUTE) && expectedRoute != null) { assertThat(attrs).containsEntry(SemanticAttributes.HTTP_ROUTE, expectedRoute); } if (endpoint == CAPTURE_HEADERS) { - if (SemconvStability.emitOldHttpSemconv()) { - assertThat(attrs) - .containsEntry("http.request.header.x_test_request", new String[] {"test"}); - assertThat(attrs) - .containsEntry("http.response.header.x_test_response", new String[] {"test"}); - } - if (SemconvStability.emitStableHttpSemconv()) { - assertThat(attrs) - .containsEntry("http.request.header.x-test-request", new String[] {"test"}); - assertThat(attrs) - .containsEntry("http.response.header.x-test-response", new String[] {"test"}); - } + assertThat(attrs) + .containsEntry("http.request.header.x-test-request", new String[] {"test"}); + assertThat(attrs) + .containsEntry("http.response.header.x-test-response", new String[] {"test"}); } if (endpoint == CAPTURE_PARAMETERS) { - if (SemconvStability.emitOldHttpSemconv()) { - assertThat(attrs) - .containsEntry( - "servlet.request.parameter.test_parameter", new String[] {"test value õäöü"}); - } - if (SemconvStability.emitStableHttpSemconv()) { - assertThat(attrs) - .containsEntry( - "servlet.request.parameter.test-parameter", new String[] {"test value õäöü"}); - } + assertThat(attrs) + .containsEntry( + "servlet.request.parameter.test-parameter", new String[] {"test value õäöü"}); } }); return span; } - protected static AttributeKey getAttributeKey(AttributeKey oldKey) { - return SemconvStabilityUtil.getAttributeKey(oldKey); - } - @CanIgnoreReturnValue - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 protected SpanDataAssert assertIndexedServerSpan(SpanDataAssert span, int requestId) { ServerEndpoint endpoint = INDEXED_CHILD; String method = "GET"; - assertServerSpan(span, method, endpoint, endpoint.status); - - if (SemconvStability.emitOldHttpSemconv()) { - span.hasAttributesSatisfying( - equalTo( - SemanticAttributes.HTTP_TARGET, - endpoint.resolvePath(address).getPath() + "?id=" + requestId)); - } - if (SemconvStability.emitStableHttpSemconv()) { - span.hasAttributesSatisfying( - equalTo(SemanticAttributes.URL_PATH, endpoint.resolvePath(address).getPath())); - span.hasAttributesSatisfying(equalTo(SemanticAttributes.URL_QUERY, "id=" + requestId)); - } - - return span; + return assertServerSpan(span, method, endpoint, endpoint.status) + .hasAttributesSatisfying( + equalTo(SemanticAttributes.URL_PATH, endpoint.resolvePath(address).getPath()), + equalTo(SemanticAttributes.URL_QUERY, "id=" + requestId)); } @CanIgnoreReturnValue diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientTestOptions.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientTestOptions.java index 1a27a7f91434..c7fa6006f44e 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientTestOptions.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientTestOptions.java @@ -23,16 +23,15 @@ @AutoValue public abstract class HttpClientTestOptions { - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public static final Set> DEFAULT_HTTP_ATTRIBUTES = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( - SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION), - SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_NAME), - SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_PORT), - SemconvStabilityUtil.getAttributeKey(SemanticAttributes.HTTP_URL), - SemconvStabilityUtil.getAttributeKey(SemanticAttributes.HTTP_METHOD)))); + SemanticAttributes.NETWORK_PROTOCOL_VERSION, + SemanticAttributes.SERVER_ADDRESS, + SemanticAttributes.SERVER_PORT, + SemanticAttributes.URL_FULL, + SemanticAttributes.HTTP_REQUEST_METHOD))); public static final BiFunction DEFAULT_EXPECTED_CLIENT_SPAN_NAME_MAPPER = (uri, method) -> HttpConstants._OTHER.equals(method) ? "HTTP" : method; diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerTestOptions.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerTestOptions.java index 2671232dc43a..957ff7dae578 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerTestOptions.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerTestOptions.java @@ -23,13 +23,10 @@ public final class HttpServerTestOptions { - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 public static final Set> DEFAULT_HTTP_ATTRIBUTES = Collections.unmodifiableSet( new HashSet<>( - Arrays.asList( - SemanticAttributes.HTTP_ROUTE, - SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_PORT)))); + Arrays.asList(SemanticAttributes.HTTP_ROUTE, SemanticAttributes.SERVER_PORT))); public static final SpanNameMapper DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER = (uri, method, route) -> { diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/SemconvStabilityUtil.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/SemconvStabilityUtil.java deleted file mode 100644 index 1384e3aaa827..000000000000 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/SemconvStabilityUtil.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.testing.junit.http; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.HashMap; -import java.util.Map; - -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 -public class SemconvStabilityUtil { - private static final Map, AttributeKey> oldToNewMap = new HashMap<>(); - - static { - addKey( - oldToNewMap, - SemanticAttributes.NET_PROTOCOL_NAME, - SemanticAttributes.NETWORK_PROTOCOL_NAME); - addKey( - oldToNewMap, - SemanticAttributes.NET_PROTOCOL_VERSION, - SemanticAttributes.NETWORK_PROTOCOL_VERSION); - addKey(oldToNewMap, SemanticAttributes.NET_PEER_NAME, SemanticAttributes.SERVER_ADDRESS); - addKey(oldToNewMap, SemanticAttributes.NET_PEER_PORT, SemanticAttributes.SERVER_PORT); - addKey( - oldToNewMap, SemanticAttributes.NET_SOCK_PEER_ADDR, NetworkAttributes.NETWORK_PEER_ADDRESS); - addKey(oldToNewMap, SemanticAttributes.NET_SOCK_PEER_PORT, NetworkAttributes.NETWORK_PEER_PORT); - addKey(oldToNewMap, SemanticAttributes.HTTP_URL, SemanticAttributes.URL_FULL); - addKey(oldToNewMap, SemanticAttributes.HTTP_METHOD, SemanticAttributes.HTTP_REQUEST_METHOD); - addKey( - oldToNewMap, - SemanticAttributes.HTTP_STATUS_CODE, - SemanticAttributes.HTTP_RESPONSE_STATUS_CODE); - addKey(oldToNewMap, SemanticAttributes.NET_HOST_NAME, SemanticAttributes.SERVER_ADDRESS); - addKey(oldToNewMap, SemanticAttributes.NET_HOST_PORT, SemanticAttributes.SERVER_PORT); - addKey(oldToNewMap, SemanticAttributes.HTTP_CLIENT_IP, SemanticAttributes.CLIENT_ADDRESS); - addKey(oldToNewMap, SemanticAttributes.HTTP_SCHEME, SemanticAttributes.URL_SCHEME); - } - - private SemconvStabilityUtil() {} - - private static void addKey( - Map, AttributeKey> map, AttributeKey oldKey, AttributeKey newKey) { - map.put(oldKey, newKey); - } - - @SuppressWarnings("unchecked") - public static AttributeKey getAttributeKey(AttributeKey oldKey) { - if (SemconvStability.emitStableHttpSemconv()) { - return (AttributeKey) oldToNewMap.get(oldKey); - } - return oldKey; - } -}