From 3d60ec6c5b8244742610ca2f2c6864aa35c8e9ea Mon Sep 17 00:00:00 2001 From: Jean Bisutti Date: Thu, 21 Nov 2024 15:29:45 +0100 Subject: [PATCH] Add automatic tests for OTel logs on Azure --- .../src/main/resources/application.properties | 2 ++ .../opentelemetry/exporter/it/AzureTest.java | 30 ++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/quarkus-opentelemetry-exporter-azure/integration-tests/src/main/resources/application.properties b/quarkus-opentelemetry-exporter-azure/integration-tests/src/main/resources/application.properties index b863af5..e954e78 100644 --- a/quarkus-opentelemetry-exporter-azure/integration-tests/src/main/resources/application.properties +++ b/quarkus-opentelemetry-exporter-azure/integration-tests/src/main/resources/application.properties @@ -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 diff --git a/quarkus-opentelemetry-exporter-azure/integration-tests/src/test/java/io/quarkiverse/opentelemetry/exporter/it/AzureTest.java b/quarkus-opentelemetry-exporter-azure/integration-tests/src/test/java/io/quarkiverse/opentelemetry/exporter/it/AzureTest.java index 9e2a419..658bafe 100644 --- a/quarkus-opentelemetry-exporter-azure/integration-tests/src/test/java/io/quarkiverse/opentelemetry/exporter/it/AzureTest.java +++ b/quarkus-opentelemetry-exporter-azure/integration-tests/src/test/java/io/quarkiverse/opentelemetry/exporter/it/AzureTest.java @@ -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; @@ -58,12 +59,10 @@ 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 telemetryExport = wireMockServer.findAll(postRequestedFor(urlEqualTo("/export/v2.1/track"))); - List requestBodies = telemetryExport + List telemetryHttpRequests = wireMockServer.findAll(postRequestedFor(urlEqualTo("/export/v2.1/track"))); + List 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 @@ -71,6 +70,10 @@ void connectionTest() throws InterruptedException { .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 telemetryDataContainTheHttpCall(WireMockServer wireMockServer) { @@ -80,11 +83,24 @@ private static Callable telemetryDataContainTheHttpCall(WireMockServer .anyMatch(body -> body.contains("Request") && body.contains("GET /direct")); } - private static Callable telemetryDataContainTheOTelMetric(WireMockServer wireMockServer) { - return () -> wireMockServer.findAll(postRequestedFor(urlEqualTo("/export/v2.1/track"))) + private void containOTeLog(List 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\",\"SourceType\":\"Logger\",\"ClassName\":\"io.quarkus.bootstrap.runner.Timing\",\"ThreadName\":\"main\",\"MethodName\":\"printStartupTime\",\"LineNumber\":")) + ) + .as("Should contain OTel log.").isTrue(); + } + + private void containOTelMetric(List 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(); } }