From 34c4e1546beaee90ee8e392690e4c8f55e0e05ef Mon Sep 17 00:00:00 2001 From: yasmin-aumeeruddy Date: Fri, 1 Mar 2024 16:44:12 +0000 Subject: [PATCH] Tck with attributes (#164) * Test metrc attributes in tck * condense iterations and streams * emit useful errors on failure * add type data to mapToString * Test metrc attributes in tck * Update semconv package * Remove unused TestUtils import --------- Co-authored-by: Benjamin Confino Remove unused TestUtils import --- .../src/main/asciidoc/opentelemetry-apis.adoc | 2 +- tck/metrics/pom.xml | 2 +- .../metrics/tck/cdi/AsyncLongCounterTest.java | 3 +- tck/tracing/pom.xml | 2 +- .../tck/async/JaxRsClientAsyncTest.java | 47 ++++++++++--------- .../tck/async/JaxRsServerAsyncTest.java | 12 ++--- .../tck/async/MpRestClientAsyncTest.java | 44 ++++++++--------- .../tck/exporter/InMemorySpanExporter.java | 4 +- .../tracing/tck/rest/RestClientSpanTest.java | 47 ++++++++++--------- .../tracing/tck/rest/RestSpanTest.java | 37 +++++++++------ 10 files changed, 106 insertions(+), 94 deletions(-) diff --git a/spec/src/main/asciidoc/opentelemetry-apis.adoc b/spec/src/main/asciidoc/opentelemetry-apis.adoc index fe51b1cb..412cf327 100644 --- a/spec/src/main/asciidoc/opentelemetry-apis.adoc +++ b/spec/src/main/asciidoc/opentelemetry-apis.adoc @@ -86,5 +86,5 @@ The above packages have dependencies on the following packages which MUST be sup These packages are not stable and MAY be subject to breaking changes in future releases. ==== -* https://www.javadoc.io/static/io.opentelemetry/opentelemetry-semconv/{otel-java-version}-alpha/io/opentelemetry/semconv/trace/attributes/package-summary.html[io.opentelemetry.semconv.trace.attributes] +* https://www.javadoc.io/static/io.opentelemetry/opentelemetry-semconv/{otel-java-version}-alpha/io/opentelemetry/semconv/trace/attributes/package-summary.html[io.opentelemetry.semconv] * https://www.javadoc.io/static/io.opentelemetry/opentelemetry-semconv/{otel-java-version}-alpha/io/opentelemetry/semconv/resource/attributes/package-summary.html[io.opentelemetry.semconv.resource.attributes] \ No newline at end of file diff --git a/tck/metrics/pom.xml b/tck/metrics/pom.xml index 7a21672f..bc21c0f4 100644 --- a/tck/metrics/pom.xml +++ b/tck/metrics/pom.xml @@ -64,7 +64,7 @@ opentelemetry-instrumentation-annotations - io.opentelemetry + io.opentelemetry.semconv opentelemetry-semconv ${version.otel.semconv} diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncLongCounterTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncLongCounterTest.java index 7ae774e4..0db3fc43 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncLongCounterTest.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncLongCounterTest.java @@ -22,7 +22,6 @@ package org.eclipse.microprofile.telemetry.metrics.tck.cdi; import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; -import org.eclipse.microprofile.telemetry.metrics.tck.TestUtils; import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporterProvider; import org.jboss.arquillian.container.test.api.Deployment; @@ -56,7 +55,7 @@ public class AsyncLongCounterTest extends Arquillian { public static WebArchive createTestArchive() { return ShrinkWrap.create(WebArchive.class) - .addClasses(InMemoryMetricExporter.class, InMemoryMetricExporterProvider.class, TestUtils.class) + .addClasses(InMemoryMetricExporter.class, InMemoryMetricExporterProvider.class) .addAsLibrary(TestLibraries.AWAITILITY_LIB) .addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class) .addAsResource(new StringAsset( diff --git a/tck/tracing/pom.xml b/tck/tracing/pom.xml index e5984bdb..8f41f0f4 100644 --- a/tck/tracing/pom.xml +++ b/tck/tracing/pom.xml @@ -60,7 +60,7 @@ opentelemetry-instrumentation-annotations - io.opentelemetry + io.opentelemetry.semconv opentelemetry-semconv ${version.otel.semconv} diff --git a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/JaxRsClientAsyncTest.java b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/JaxRsClientAsyncTest.java index 26e09d25..8a650571 100644 --- a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/JaxRsClientAsyncTest.java +++ b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/JaxRsClientAsyncTest.java @@ -20,11 +20,12 @@ package org.eclipse.microprofile.telemetry.tracing.tck.async; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_METHOD; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_SCHEME; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_STATUS_CODE; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_TARGET; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_URL; +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.URL_FULL; +import static io.opentelemetry.semconv.SemanticAttributes.URL_PATH; +import static io.opentelemetry.semconv.SemanticAttributes.URL_QUERY; +import static io.opentelemetry.semconv.SemanticAttributes.URL_SCHEME; import static java.net.HttpURLConnection.HTTP_BAD_REQUEST; import static java.net.HttpURLConnection.HTTP_OK; @@ -119,7 +120,7 @@ public void readErrorSpans() { SpanData firstURL = null; SpanData secondURL = null; for (SpanData span : serverSpans) { - if (span.getAttributes().get(HTTP_TARGET).contains("JaxRsClientAsyncTestEndpoint/jaxrsclient")) { + if (span.getAttributes().get(URL_PATH).contains("JaxRsClientAsyncTestEndpoint/jaxrsclient")) { firstURL = span; } else { secondURL = span; @@ -136,21 +137,21 @@ public void readErrorSpans() { Assert.assertEquals(httpGet.getSpanId(), secondURL.getParentSpanId()); Assert.assertEquals(firstURL.getSpanId(), httpGet.getParentSpanId()); - Assert.assertEquals(firstURL.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - Assert.assertEquals(firstURL.getAttributes().get(HTTP_SCHEME), "http"); + Assert.assertEquals(firstURL.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + Assert.assertEquals(firstURL.getAttributes().get(URL_SCHEME), "http"); // getError returns an internal server error... - Assert.assertEquals(secondURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); + Assert.assertEquals(secondURL.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); // Which gets received by the client - Assert.assertEquals(httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); + Assert.assertEquals(httpGet.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); // The exception from the client is inspected and handled so this method should return OK - Assert.assertEquals(firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK); + Assert.assertEquals(firstURL.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_OK); // There are many different URLs that will end up here. But all should contain "JaxRsClientAsyncTestEndpoint" - Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("JaxRsClientAsyncTestEndpoint")); + Assert.assertTrue(httpGet.getAttributes().get(URL_FULL).contains("JaxRsClientAsyncTestEndpoint")); - Assert.assertEquals(httpGet.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("JaxRsClientAsyncTestEndpoint")); + Assert.assertEquals(httpGet.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + Assert.assertTrue(httpGet.getAttributes().get(URL_FULL).contains("JaxRsClientAsyncTestEndpoint")); } public void readSpans() { @@ -162,7 +163,7 @@ public void readSpans() { SpanData firstURL = null; SpanData secondURL = null; for (SpanData span : serverSpans) { - if (span.getAttributes().get(HTTP_TARGET).contains("JaxRsClientAsyncTestEndpoint/jaxrsclient")) { + if (span.getAttributes().get(URL_PATH).contains("JaxRsClientAsyncTestEndpoint/jaxrsclient")) { firstURL = span; } else { secondURL = span; @@ -179,16 +180,16 @@ public void readSpans() { Assert.assertEquals(httpGet.getSpanId(), secondURL.getParentSpanId()); Assert.assertEquals(firstURL.getSpanId(), httpGet.getParentSpanId()); - Assert.assertEquals(firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK); - Assert.assertEquals(firstURL.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - Assert.assertEquals(firstURL.getAttributes().get(HTTP_SCHEME), "http"); - Assert.assertTrue(firstURL.getAttributes().get(HTTP_TARGET).contains(QUERY_VALUE)); + Assert.assertEquals(firstURL.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_OK); + Assert.assertEquals(firstURL.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + Assert.assertEquals(firstURL.getAttributes().get(URL_SCHEME), "http"); + Assert.assertTrue(firstURL.getAttributes().get(URL_QUERY).contains(QUERY_VALUE)); // There are many different URLs that will end up here. But all should contain "JaxRsClientAsyncTestEndpoint" - Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("JaxRsClientAsyncTestEndpoint")); + Assert.assertTrue(httpGet.getAttributes().get(URL_FULL).contains("JaxRsClientAsyncTestEndpoint")); - Assert.assertEquals(httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK); - Assert.assertEquals(httpGet.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("JaxRsClientAsyncTestEndpoint")); + Assert.assertEquals(httpGet.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_OK); + Assert.assertEquals(httpGet.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + Assert.assertTrue(httpGet.getAttributes().get(URL_FULL).contains("JaxRsClientAsyncTestEndpoint")); } } diff --git a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/JaxRsServerAsyncTest.java b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/JaxRsServerAsyncTest.java index 20f91d78..82bcebf3 100644 --- a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/JaxRsServerAsyncTest.java +++ b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/JaxRsServerAsyncTest.java @@ -20,8 +20,8 @@ package org.eclipse.microprofile.telemetry.tracing.tck.async; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_STATUS_CODE; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_TARGET; +import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_STATUS_CODE; +import static io.opentelemetry.semconv.SemanticAttributes.URL_QUERY; import static java.net.HttpURLConnection.HTTP_BAD_REQUEST; import static org.eclipse.microprofile.telemetry.tracing.tck.async.JaxRsServerAsyncTestEndpoint.BAGGAGE_VALUE_ATTR; import static org.testng.Assert.assertEquals; @@ -148,7 +148,7 @@ private void doAsyncTest(Function re Assert.assertTrue(subtaskSpan.getAttributes().get(BAGGAGE_VALUE_ATTR).contains(TEST_VALUE)); // Assert that query parameter was passed correctly - Assert.assertTrue(serverSpan.getAttributes().get(HTTP_TARGET).contains(QUERY_VALUE)); + Assert.assertTrue(serverSpan.getAttributes().get(URL_QUERY).contains(QUERY_VALUE)); // Assert that the server span finished after the subtask span // Even though the resource method returned quickly, the span should not end until the response is actually @@ -193,8 +193,8 @@ private void readErrorSpans() { assertEquals(clientSpan.getSpanId(), serverSpan.getParentSpanId()); // Assert the status code for the client and server spans - assertEquals(serverSpan.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); - assertEquals(clientSpan.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); + assertEquals(serverSpan.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); + assertEquals(clientSpan.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); // Assert that the expected headers were used Assert.assertTrue(serverSpan.getAttributes().get(BAGGAGE_VALUE_ATTR).contains(TEST_VALUE)); @@ -203,7 +203,7 @@ private void readErrorSpans() { Assert.assertTrue(subtaskSpan.getAttributes().get(BAGGAGE_VALUE_ATTR).contains(TEST_VALUE)); // Assert that query parameter was passed correctly - Assert.assertTrue(serverSpan.getAttributes().get(HTTP_TARGET).contains(QUERY_VALUE)); + Assert.assertTrue(serverSpan.getAttributes().get(URL_QUERY).contains(QUERY_VALUE)); // Assert that the server span finished after the subtask span // Even though the resource method returned quickly, the span should not end until the response is actually diff --git a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/MpRestClientAsyncTest.java b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/MpRestClientAsyncTest.java index 7c921274..d510548d 100644 --- a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/MpRestClientAsyncTest.java +++ b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/async/MpRestClientAsyncTest.java @@ -20,11 +20,11 @@ package org.eclipse.microprofile.telemetry.tracing.tck.async; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_METHOD; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_SCHEME; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_STATUS_CODE; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_TARGET; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_URL; +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.URL_FULL; +import static io.opentelemetry.semconv.SemanticAttributes.URL_PATH; +import static io.opentelemetry.semconv.SemanticAttributes.URL_SCHEME; import static java.net.HttpURLConnection.HTTP_BAD_REQUEST; import static java.net.HttpURLConnection.HTTP_OK; @@ -120,7 +120,7 @@ public void readSpans() { SpanData httpGet = spanExporter.getFirst(SpanKind.CLIENT); for (SpanData span : serverSpans) { - if (span.getAttributes().get(HTTP_TARGET).contains("MpRestClientAsyncTestEndpoint/mpclient")) { + if (span.getAttributes().get(URL_PATH).contains("MpRestClientAsyncTestEndpoint/mpclient")) { firstURL = span; } else { secondURL = span; @@ -135,13 +135,13 @@ public void readSpans() { Assert.assertEquals(httpGet.getSpanId(), secondURL.getParentSpanId()); Assert.assertEquals(firstURL.getSpanId(), httpGet.getParentSpanId()); - Assert.assertEquals(firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK); - Assert.assertEquals(firstURL.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - Assert.assertEquals(firstURL.getAttributes().get(HTTP_SCHEME), "http"); + Assert.assertEquals(firstURL.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_OK); + Assert.assertEquals(firstURL.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + Assert.assertEquals(firstURL.getAttributes().get(URL_SCHEME), "http"); - Assert.assertEquals(httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK); - Assert.assertEquals(httpGet.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("MpRestClientAsyncTestEndpoint")); + Assert.assertEquals(httpGet.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_OK); + Assert.assertEquals(httpGet.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + Assert.assertTrue(httpGet.getAttributes().get(URL_FULL).contains("MpRestClientAsyncTestEndpoint")); } public void readSpansError() { @@ -155,7 +155,7 @@ public void readSpansError() { SpanData httpGet = spanExporter.getFirst(SpanKind.CLIENT); for (SpanData span : serverSpans) { - if (span.getAttributes().get(HTTP_TARGET).contains("MpRestClientAsyncTestEndpoint/mpclient")) { + if (span.getAttributes().get(URL_PATH).contains("MpRestClientAsyncTestEndpoint/mpclient")) { firstURL = span; } else { secondURL = span; @@ -170,18 +170,18 @@ public void readSpansError() { Assert.assertEquals(firstURL.getSpanId(), httpGet.getParentSpanId()); // requestMpClientError() returns a BAD_REQUEST status - Assert.assertEquals(secondURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); - Assert.assertEquals(secondURL.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - Assert.assertEquals(secondURL.getAttributes().get(HTTP_SCHEME), "http"); + Assert.assertEquals(secondURL.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); + Assert.assertEquals(secondURL.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + Assert.assertEquals(secondURL.getAttributes().get(URL_SCHEME), "http"); // which is received by the client - Assert.assertEquals(httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); - Assert.assertEquals(httpGet.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("MpRestClientAsyncTestEndpoint")); + Assert.assertEquals(httpGet.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_BAD_REQUEST); + Assert.assertEquals(httpGet.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + Assert.assertTrue(httpGet.getAttributes().get(URL_FULL).contains("MpRestClientAsyncTestEndpoint")); // Exception is handled in the receiving code so the status code here should be OK - Assert.assertEquals(firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK); - Assert.assertEquals(firstURL.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - Assert.assertEquals(firstURL.getAttributes().get(HTTP_SCHEME), "http"); + Assert.assertEquals(firstURL.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), HTTP_OK); + Assert.assertEquals(firstURL.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + Assert.assertEquals(firstURL.getAttributes().get(URL_SCHEME), "http"); } } diff --git a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/exporter/InMemorySpanExporter.java b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/exporter/InMemorySpanExporter.java index a8795ab1..83836d31 100644 --- a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/exporter/InMemorySpanExporter.java +++ b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/exporter/InMemorySpanExporter.java @@ -36,7 +36,7 @@ import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.export.SpanExporter; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.semconv.SemanticAttributes; import jakarta.enterprise.context.ApplicationScoped; @ApplicationScoped @@ -79,7 +79,7 @@ public CompletableResultCode export(Collection spans) { private static boolean isArquillianSpan(SpanData span) { String path = span.getAttributes().get(SemanticAttributes.HTTP_ROUTE); if (path == null) { - path = span.getAttributes().get(SemanticAttributes.HTTP_TARGET); + path = span.getAttributes().get(SemanticAttributes.URL_QUERY); } if (path != null && (path.contains("/ArquillianServletRunner") diff --git a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/rest/RestClientSpanTest.java b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/rest/RestClientSpanTest.java index 065aa654..738e120e 100644 --- a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/rest/RestClientSpanTest.java +++ b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/rest/RestClientSpanTest.java @@ -20,16 +20,15 @@ package org.eclipse.microprofile.telemetry.tracing.tck.rest; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_METHOD; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_ROUTE; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_SCHEME; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_STATUS_CODE; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_TARGET; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_URL; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_NAME; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_PORT; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_NAME; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_PORT; +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.SERVER_ADDRESS; +import static io.opentelemetry.semconv.SemanticAttributes.SERVER_PORT; +import static io.opentelemetry.semconv.SemanticAttributes.URL_FULL; +import static io.opentelemetry.semconv.SemanticAttributes.URL_PATH; +import static io.opentelemetry.semconv.SemanticAttributes.URL_QUERY; +import static io.opentelemetry.semconv.SemanticAttributes.URL_SCHEME; import static jakarta.ws.rs.core.Response.Status.BAD_REQUEST; import static jakarta.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; import static jakarta.ws.rs.core.Response.Status.OK; @@ -322,12 +321,12 @@ private void assertClientSpan(SpanData client, String path) { private void assertClientSpan(SpanData client, String path, Response.StatusType status) { assertEquals(client.getKind(), SpanKind.CLIENT); - assertEquals(client.getAttributes().get(HTTP_STATUS_CODE).intValue(), status.getStatusCode()); - assertEquals(client.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - assertEquals(client.getAttributes().get(HTTP_URL), url.toString() + path); - assertEquals(client.getAttributes().get(NET_PEER_NAME), url.getHost()); + assertEquals(client.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), status.getStatusCode()); + assertEquals(client.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + assertEquals(client.getAttributes().get(URL_FULL), url.toString() + path); + assertEquals(client.getAttributes().get(SERVER_ADDRESS), url.getHost()); if (url.getPort() != url.getDefaultPort()) { - assertEquals(client.getAttributes().get(NET_PEER_PORT).intValue(), url.getPort()); + assertEquals(client.getAttributes().get(SERVER_PORT).intValue(), url.getPort()); } } @@ -337,16 +336,22 @@ private void assertServerSpan(SpanData server, String path) { private void assertServerSpan(SpanData server, String path, Response.StatusType status) { assertEquals(server.getKind(), SpanKind.SERVER); - assertEquals(server.getAttributes().get(HTTP_STATUS_CODE).intValue(), status.getStatusCode()); - assertEquals(server.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - assertEquals(server.getAttributes().get(HTTP_SCHEME), url.getProtocol()); - assertEquals(server.getAttributes().get(HTTP_TARGET), url.getPath() + path); + assertEquals(server.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), status.getStatusCode()); + assertEquals(server.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + assertEquals(server.getAttributes().get(URL_SCHEME), url.getProtocol()); + if (server.getAttributes().get(URL_QUERY) != null) { + Assert.assertEquals(server.getAttributes().get(URL_PATH) + "?" + server.getAttributes().get(URL_QUERY), + url.getPath() + path); + } else { + Assert.assertEquals(server.getAttributes().get(URL_PATH), + url.getPath() + path); + } // route is required when available, definitely available for REST endpoints Assert.assertNotNull(server.getAttributes().get(HTTP_ROUTE)); // not asserting specific value as it is only recommended, and should contain application prefix - assertEquals(server.getAttributes().get(NET_HOST_NAME), url.getHost()); + assertEquals(server.getAttributes().get(SERVER_ADDRESS), url.getHost()); if (url.getPort() != url.getDefaultPort()) { - assertEquals(server.getAttributes().get(NET_HOST_PORT).intValue(), url.getPort()); + assertEquals(server.getAttributes().get(SERVER_PORT).intValue(), url.getPort()); } } diff --git a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/rest/RestSpanTest.java b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/rest/RestSpanTest.java index 9e8c9f6c..81fd0631 100644 --- a/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/rest/RestSpanTest.java +++ b/tck/tracing/src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/rest/RestSpanTest.java @@ -21,15 +21,16 @@ package org.eclipse.microprofile.telemetry.tracing.tck.rest; import static io.opentelemetry.api.trace.SpanKind.SERVER; -import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME; -import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_VERSION; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_METHOD; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_ROUTE; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_SCHEME; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_STATUS_CODE; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_TARGET; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_NAME; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_PORT; +import static io.opentelemetry.semconv.ResourceAttributes.SERVICE_NAME; +import static io.opentelemetry.semconv.ResourceAttributes.SERVICE_VERSION; +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.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_QUERY; +import static io.opentelemetry.semconv.SemanticAttributes.URL_SCHEME; import static java.net.HttpURLConnection.HTTP_OK; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -110,16 +111,22 @@ private void assertServerSpan(SpanData server, String path) { } private void assertServerSpan(SpanData server, String path, int statusCode) { Assert.assertEquals(server.getKind(), SERVER); - Assert.assertEquals(server.getAttributes().get(HTTP_STATUS_CODE).intValue(), statusCode); - Assert.assertEquals(server.getAttributes().get(HTTP_METHOD), HttpMethod.GET); - Assert.assertEquals(server.getAttributes().get(HTTP_SCHEME), url.getProtocol()); - Assert.assertEquals(server.getAttributes().get(HTTP_TARGET), url.getPath() + path); + Assert.assertEquals(server.getAttributes().get(HTTP_RESPONSE_STATUS_CODE).intValue(), statusCode); + Assert.assertEquals(server.getAttributes().get(HTTP_REQUEST_METHOD), HttpMethod.GET); + Assert.assertEquals(server.getAttributes().get(URL_SCHEME), url.getProtocol()); + if (server.getAttributes().get(URL_QUERY) != null) { + Assert.assertEquals(server.getAttributes().get(URL_PATH) + "?" + server.getAttributes().get(URL_QUERY), + url.getPath() + path); + } else { + Assert.assertEquals(server.getAttributes().get(URL_PATH), + url.getPath() + path); + } // route is required when available, definitely available for REST endpoints Assert.assertNotNull(server.getAttributes().get(HTTP_ROUTE)); // not asserting specific value as it is only recommended, and should contain application prefix - Assert.assertEquals(server.getAttributes().get(NET_HOST_NAME), url.getHost()); + Assert.assertEquals(server.getAttributes().get(SERVER_ADDRESS), url.getHost()); if (url.getPort() != url.getDefaultPort()) { - Assert.assertEquals(server.getAttributes().get(NET_HOST_PORT).intValue(), url.getPort()); + Assert.assertEquals(server.getAttributes().get(SERVER_PORT).intValue(), url.getPort()); } }