Skip to content

Commit

Permalink
Merge pull request #1467 from jcarranzan/dev-serv-lgtm-otel
Browse files Browse the repository at this point in the history
Enable Quarkus Observability Dev Services with Grafana LGTM in OpenTelemetry Quickstart
  • Loading branch information
rsvoboda authored Nov 4, 2024
2 parents edc470a + 45b0321 commit 9be2239
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
8 changes: 8 additions & 0 deletions opentelemetry-quickstart/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
Quarkus guide: https://quarkus.io/guides/opentelemetry

In this opentelemetry-quickstart is implemented OpenTelemetry Metrics detailed in the guide: https://quarkus.io/guides/opentelemetry-metrics .

Additionally, it integrates the LGTM DevService for telemetry visualization by adding the `quarkus-observability-devservices-lgtm` dependency.

Usage and configuration are explained in the guide: https://quarkus.io/guides/opentelemetry-tracing#grafana-otel-lgtm-option


4 changes: 4 additions & 0 deletions opentelemetry-quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devservices-lgtm</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package org.acme.opentelemetry;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.metrics.LongCounter;
import io.opentelemetry.api.metrics.Meter;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
Expand All @@ -18,6 +24,24 @@ public class TracedResource {
@Context
UriInfo uriInfo;

@Inject
OpenTelemetry openTelemetry;

@Inject
Meter meter;

private LongCounter longCounter;

@PostConstruct
public void init() {
meter = openTelemetry.getMeter("myservice");

longCounter = meter.counterBuilder("service.xvalue")
.setDescription("Current value of X in the service")
.setUnit("units")
.build();
}

@GET
@Path("/hello")
@Produces(MediaType.TEXT_PLAIN)
Expand All @@ -35,4 +59,16 @@ public String chain() {
.build(ResourceClient.class);
return "chain -> " + resourceClient.hello();
}

@GET
@Path("/metrics/set")
@Produces(MediaType.APPLICATION_JSON)
public String setMetric(@QueryParam("value") long value) {
if (value <= 0) {
return "{\"status\":\"failure\", \"message\":\"Value parameter must be positive\"}";
}
longCounter.add(value);

return "{\"status\":\"success\", \"xvalue\":" + value + "}";
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
quarkus.application.name=myservice
quarkus.otel.exporter.otlp.traces.endpoint=http://localhost:4317
quarkus.otel.metrics.enabled=true
quarkus.otel.exporter.otlp.traces.headers=Authorization=Bearer my_secret
quarkus.log.console.format=%d{HH:mm:ss} %-5p traceId=%X{traceId}, parentId=%X{parentId}, spanId=%X{spanId}, sampled=%X{sampled} [%c{2.}] (%t) %s%e%n

# jfr must be enabled if you need OpenTelemetry metrics on native mode.
quarkus.native.monitoring=jfr
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,17 @@ public void testChainEndpoint() {
.body(is("chain -> hello"));
}

@Test
public void testSetMetricEndpoint() {
long testValue = 42L;

given()
.queryParam("value", testValue)
.when().get("/metrics/set")
.then()
.statusCode(200)
.body("status", is("success"))
.body("xvalue", is((int)testValue));
}

}

0 comments on commit 9be2239

Please sign in to comment.