diff --git a/README.md b/README.md index a2693f9..5720ae2 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,62 @@ You can run your application in dev mode that enables live coding using: > **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/. +## OpenTelemetry and Metrics + +This application is instrumented with OpenTelemetry and exposes metrics in Prometheus format. + +### Metrics Endpoint + +Once the application is running, metrics are available at: +``` +http://localhost:8080/q/metrics +``` + +This endpoint provides: +- **HTTP metrics**: Request count, duration, and status codes +- **JVM metrics**: Memory usage, thread count, garbage collection statistics +- **Application metrics**: Custom LRA coordinator metrics + +### Example Usage + +To view metrics in your browser or with curl: +```shell script +curl http://localhost:8080/q/metrics +``` + +### Integration with Prometheus + +To scrape metrics with Prometheus, add the following job to your `prometheus.yml`: +```yaml +scrape_configs: + - job_name: 'lra-coordinator' + metrics_path: '/q/metrics' + static_configs: + - targets: ['localhost:8080'] +``` + +### OpenTelemetry Configuration + +The application is configured with: +- Service name: `lra-coordinator` +- Traces enabled: Yes +- Metrics enabled: Yes + +Additional OpenTelemetry configuration can be modified in `src/main/resources/application.properties`. + +### Grafana Dev Service (Optional) + +For a fully integrated observability stack in dev mode (Grafana, Loki, Tempo, Prometheus), you can add the following dependency to your `pom.xml`: +```xml + + io.quarkus + quarkus-observability-devservices-lgtm + provided + +``` + +This will automatically start a Grafana LGTM container when running in dev mode, giving you access to a pre-configured Grafana dashboard to visualize metrics, logs, and traces. + ## Packaging and running the application The application can be packaged using: diff --git a/pom.xml b/pom.xml index 486a1e0..dd787dc 100644 --- a/pom.xml +++ b/pom.xml @@ -62,6 +62,24 @@ io.quarkus quarkus-container-image-docker + + io.quarkus + quarkus-opentelemetry + + + io.quarkus + quarkus-micrometer-registry-prometheus + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b6f3257..9037a86 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -20,3 +20,14 @@ quarkus.index-dependency.microprofile-lra-api.artifact-id=microprofile-lra-api quarkus.index-dependency.lra-service-base.group-id=org.jboss.narayana.lra quarkus.index-dependency.lra-service-base.artifact-id=lra-service-base + +# OpenTelemetry +quarkus.otel.service.name=lra-coordinator +quarkus.otel.traces.enabled=true +quarkus.otel.metrics.enabled=true +quarkus.otel.logs.enabled=true + +# Metrics endpoint +quarkus.micrometer.export.prometheus.enabled=true +quarkus.micrometer.binder.http-server.enabled=true +quarkus.micrometer.binder.jvm.enabled=true diff --git a/src/test/java/org/jboss/narayana/rts/OpenTelemetryEndpointTest.java b/src/test/java/org/jboss/narayana/rts/OpenTelemetryEndpointTest.java new file mode 100644 index 0000000..2e28a1c --- /dev/null +++ b/src/test/java/org/jboss/narayana/rts/OpenTelemetryEndpointTest.java @@ -0,0 +1,30 @@ +package org.jboss.narayana.rts; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.containsString; + +@QuarkusTest +class OpenTelemetryEndpointTest { + + @Test + void metricsEndpointReturnsPrometheusData() { + given() + .when().get("/q/metrics") + .then() + .statusCode(200) + .contentType(containsString("openmetrics-text")) + .body(containsString("jvm_memory")); + } + + @Test + void metricsEndpointContainsHttpServerMetrics() { + given() + .when().get("/q/metrics") + .then() + .statusCode(200) + .body(containsString("http_server")); + } +} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties new file mode 100644 index 0000000..4e37aa1 --- /dev/null +++ b/src/test/resources/application.properties @@ -0,0 +1,3 @@ +# Disable OTLP exporter in tests (no collector available) +quarkus.otel.exporter.otlp.traces.endpoint=http://localhost:4317 +quarkus.otel.sdk.disabled=true