Skip to content

Commit

Permalink
Tck with attributes (#164)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Remove unused TestUtils import
  • Loading branch information
yasmin-aumeeruddy committed Mar 4, 2024
1 parent d3e9e0b commit 34c4e15
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 94 deletions.
2 changes: 1 addition & 1 deletion spec/src/main/asciidoc/opentelemetry-apis.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
2 changes: 1 addition & 1 deletion tck/metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv</artifactId>
<version>${version.otel.semconv}</version>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tck/tracing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv</artifactId>
<version>${version.otel.semconv}</version>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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;
Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,7 +148,7 @@ private void doAsyncTest(Function<JaxRsServerAsyncTestEndpointClient, String> 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
Expand Down Expand Up @@ -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));
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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;
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,7 +79,7 @@ public CompletableResultCode export(Collection<SpanData> 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")
Expand Down
Loading

0 comments on commit 34c4e15

Please sign in to comment.