Skip to content

Commit

Permalink
Add automatic tests for OTel logs on Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanbisutti committed Nov 21, 2024
1 parent e695a23 commit 4ccf063
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ quarkus.application.version=999-SNAPSHOT

applicationinsights.connection.string=InstrumentationKey=bla;IngestionEndpoint=http://127.0.0.1:53602/export

quarkus.otel.logs.enabled=true

quarkus.otel.metrics.enabled=true
quarkus.otel.metric.export.interval=1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Optional;
import java.util.concurrent.Callable;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -58,19 +59,21 @@ void connectionTest() throws InterruptedException {
.atMost(Duration.ofSeconds(10))
.until(telemetryDataContainTheHttpCall(wireMockServer));

telemetryDataContainTheOTelMetric(wireMockServer);

// Non regression test for https://github.com/Azure/azure-sdk-for-java/issues/41040
Thread.sleep(10_000);
List<LoggedRequest> telemetryExport = wireMockServer.findAll(postRequestedFor(urlEqualTo("/export/v2.1/track")));
List<String> requestBodies = telemetryExport
List<LoggedRequest> telemetryHttpRequests = wireMockServer.findAll(postRequestedFor(urlEqualTo("/export/v2.1/track")));
List<String> requestBodies = telemetryHttpRequests
.stream()
.map(request -> new String(request.getBody())).toList();
requestBodies.stream().forEach(System.out::println); // It's convenient to print the telemetry data on the console to spot potential issues
Optional<String> telemetryDataExport = requestBodies.stream()
.filter(body -> body.contains("RemoteDependency") && body.contains("POST /export/v2.1/track"))
.findAny();
assertThat(telemetryDataExport).as("Telemetry export request should not appear as a dependency.").isEmpty();

containOTeLog(telemetryHttpRequests);

containOTelMetric(telemetryHttpRequests);
}

private static Callable<Boolean> telemetryDataContainTheHttpCall(WireMockServer wireMockServer) {
Expand All @@ -80,11 +83,23 @@ private static Callable<Boolean> telemetryDataContainTheHttpCall(WireMockServer
.anyMatch(body -> body.contains("Request") && body.contains("GET /direct"));
}

private static Callable<Boolean> telemetryDataContainTheOTelMetric(WireMockServer wireMockServer) {
return () -> wireMockServer.findAll(postRequestedFor(urlEqualTo("/export/v2.1/track")))
private void containOTeLog(List<LoggedRequest> telemetryHttpRequests) {
assertThat(telemetryHttpRequests
.stream()
.map(request -> new String(request.getBody()))
.anyMatch(body -> body.contains("\"message\":\"opentelemetry-exporter-azure-integration-test")
&& body.contains("(powered by Quarkus ")
&& body.contains("started in") && body.contains(
"{\"LoggerName\":\"io.quarkus.opentelemetry\",\"LoggingLevel\":\"INFO\",\"log.logger.namespace\":\"org.jboss.logging.Logger\"")))
.as("Should contain OTel log.").isTrue();
}

private void containOTelMetric(List<LoggedRequest> telemetryHttpRequests) {
Assertions.assertThat(telemetryHttpRequests
.stream()
.map(request -> new String(request.getBody()))
.anyMatch(body -> body.contains("Metric") && body.contains("baseData\":{\"ver\":2,\"metrics\":[{\"name\":\""
+ SimpleResource.TEST_HISTOGRAM + "\",\"value\":10.0,\"count\":1,\"min\":10.0,\"max\":10.0"));
+ SimpleResource.TEST_HISTOGRAM + "\",\"value\":10.0,\"count\":1,\"min\":10.0,\"max\":10.0")))
.as("Should contain OTel metric.").isTrue();
}
}

0 comments on commit 4ccf063

Please sign in to comment.