Skip to content

Commit

Permalink
Add test to quarkus-integration-test-opentelemetry module
Browse files Browse the repository at this point in the history
  • Loading branch information
mcruzdev committed Oct 22, 2024
1 parent 5a125c4 commit 0bd7b0c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.context.Scope;
import io.quarkus.opentelemetry.runtime.tracing.Traceless;

@Path("")
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -150,4 +151,21 @@ public String exception() {
LOG.error("Oh no {}", exception.getMessage(), exception);
return "Oh no! An exception";
}

@GET
@Path("/suppress-app-uri")
public TraceData suppressAppUri() {
TraceData traceData = new TraceData();
traceData.message = "Suppress me!";
return traceData;
}

@GET
@Path("/traceless")
@Traceless
public TraceData traceless() {
TraceData traceData = new TraceData();
traceData.message = "@Traceless";
return traceData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ quarkus.security.users.embedded.users.scott=reader
quarkus.security.users.embedded.plain-text=true
quarkus.security.users.embedded.enabled=true
quarkus.http.auth.basic=true


quarkus.otel.traces.suppress-application-uris=/suppress-app-uri
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.*;

import java.io.IOException;
import java.net.URI;
Expand All @@ -27,6 +22,7 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.awaitility.core.ConditionTimeoutException;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -58,6 +54,8 @@ public class TracingTest {
URL deepPathUrl;
@TestHTTPResource("param")
URL pathParamUrl;
@TestHTTPResource
URL suppressAppUrl;

@BeforeEach
@AfterEach
Expand Down Expand Up @@ -743,6 +741,34 @@ public void testNoEndUserAttributes() {
.findAny().isEmpty());
}

@Test
public void testSuppressAppUri() {
RestAssured.given()
.when().get("/suppress-app-uri")
.then()
.statusCode(200)
.body("message", Matchers.is("Suppress me!"));

// should throw because there are a configuration quarkus.otel.traces.suppress-app-uris=/suppress-app-uri
assertThrows(ConditionTimeoutException.class, () -> {
await().atMost(5, SECONDS).until(() -> !getSpans().isEmpty());
});
}

@Test
public void testTracelessResource() {
RestAssured.given()
.when().get("/traceless")
.then()
.statusCode(200)
.body("message", Matchers.is("@Traceless"));

// should throw because there is no span
assertThrows(ConditionTimeoutException.class, () -> {
await().atMost(5, SECONDS).until(() -> !getSpans().isEmpty());
});
}

private void verifyResource(Map<String, Object> spanData) {
assertEquals("opentelemetry-integration-test", spanData.get("resource_service.name"));
assertEquals("999-SNAPSHOT", spanData.get("resource_service.version"));
Expand Down

0 comments on commit 0bd7b0c

Please sign in to comment.