Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Quarkus Observability Dev Services with Grafana LGTM in OpenTelemetry Quickstart #1467

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
jcarranzan marked this conversation as resolved.
Show resolved Hide resolved
.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
jcarranzan marked this conversation as resolved.
Show resolved Hide resolved
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));
}

}
Loading