Skip to content

Commit

Permalink
* Specific values of span name is not checked, rather absence of high…
Browse files Browse the repository at this point in the history
…-cardinality parts of requests (#96)

* `net.host.name` and `net.host.port` are required for server Rest spans
* `http.route` is required for server Rest spans
* `net.peer.name` and `net.peer.host` are required for client Rest spans
* error status of span is required for certain 4xx and 5xx requests

Add TCK tests for telemetry tracing

Co-authored-by: Patrik Dudits <patrik.dudits@payara.fish>
  • Loading branch information
yasmin-aumeeruddy and pdudits committed Jul 3, 2023
1 parent 22956d8 commit 12419b6
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2016-2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.eclipse.microprofile.telemetry.tracing.tck.cdi;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.testng.Assert;
import org.testng.annotations.Test;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import jakarta.inject.Inject;

class OpenTelemetryBeanTest extends Arquillian {

private static final String SPAN_NAME = "MySpanName";
private static final String INVALID_SPAN_ID = "0000000000000000";

@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
.addAsResource(new StringAsset("otel.sdk.disabled=false"),
"META-INF/microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Inject
OpenTelemetry openTelemetry;

@Test
void testOpenTelemetryBean() {
Assert.assertNotNull(openTelemetry);
}

@Test
void testSpanAndTracer() {
Tracer tracer = openTelemetry.getTracer("instrumentation-test", "1.0.0");
Assert.assertNotNull(tracer);
Span span = tracer.spanBuilder(SPAN_NAME).startSpan();
Assert.assertNotEquals(span.getSpanContext().getSpanId(), INVALID_SPAN_ID);
}
}
Expand Up @@ -62,6 +62,7 @@
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider;
import io.opentelemetry.sdk.trace.data.SpanData;
Expand Down Expand Up @@ -200,6 +201,30 @@ void spanError() {
assertEquals(server.getParentSpanId(), client.getSpanId());
}

@Test
void spanChildWithParameter() {
Response response = client.spanChildWithParameter("testParameterValue");
assertResponseStatus(response, OK);

spanExporter.assertSpanCount(3);

SpanData internal = spanExporter.getFirst(SpanKind.INTERNAL);
assertEquals(internal.getKind(), SpanKind.INTERNAL);
assertEquals(internal.getName(), "SpanBean.spanChildWithParameter");
assertEquals(internal.getAttributes().get(AttributeKey.stringKey("testParameter")), "testParameterValue");

SpanData server = spanExporter.getFirst(SpanKind.SERVER);
assertServerSpan(server, "span/childParameterWithParameter/testParameterValue");

SpanData client = spanExporter.getFirst(SpanKind.CLIENT);
assertClientSpan(client, "span/childParameterWithParameter/testParameterValue");

assertEquals(internal.getTraceId(), client.getTraceId());
assertEquals(server.getTraceId(), client.getTraceId());
assertEquals(server.getSpanId(), internal.getParentSpanId());
assertEquals(client.getSpanId(), server.getParentSpanId());
}

@Test
void spanChild() {
Response response = client.spanChild();
Expand Down Expand Up @@ -360,6 +385,13 @@ public Response spanChild() {
return Response.ok().build();
}

@GET
@Path("/span/childParameterWithParameter/{name}")
public Response spanChildWithParameter(@PathParam(value = "name") String name) {
spanBean.spanChildWithParameter(name);
return Response.ok().build();
}

@GET
@Path("/span/current")
public Response spanCurrent() {
Expand Down Expand Up @@ -394,6 +426,11 @@ public static class SpanBean {
void spanChild() {

}

@WithSpan
void spanChildWithParameter(@SpanAttribute("testParameter") String testParameter) {

}
}

@RegisterRestClient(configKey = "client")
Expand All @@ -415,6 +452,10 @@ public interface SpanResourceClient {
@Path("/span/child")
Response spanChild();

@GET
@Path("/span/childParameterWithParameter/{name}")
Response spanChildWithParameter(@PathParam(value = "name") String name);

@GET
@Path("/span/current")
Response spanCurrent();
Expand Down

0 comments on commit 12419b6

Please sign in to comment.