Skip to content

Commit

Permalink
Rename extension and start docs
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobat committed Jan 2, 2025
1 parent c153a56 commit 35f4d7a
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 23 deletions.
53 changes: 53 additions & 0 deletions docs/src/main/asciidoc/telemetry-micrometer-to-opentelemetry.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
////
This guide is maintained in the main Quarkus repository
and pull requests should be submitted there:
https://github.com/quarkusio/quarkus/tree/main/docs/src/main/asciidoc
////
[id=telemetry-micrometer-opentelemetry]
= Micrometer and OpenTelemetry extension
include::_attributes.adoc[]
:diataxis-type: reference
:categories: observability
:summary: Guide to send Micrometer data to OpenTelemetry.
:topics: observability,opentelemetry,metrics,micrometer,tracing,logs
:extensions: io.quarkus:quarkus-micrometer-opentelemetry-bridge

This extension provides support for both `Micrometer` and `OpenTelemetry` in Quarkus applications. It streamlines integration by incorporating both extensions along with a bridge that enables sending Micrometer metrics via OpenTelemetry.

[NOTE]
====
- The xref:telemetry-micrometer.adoc[Micrometer Guide] is available for detailed information about the Micrometer extension.
- The xref:opentelemetry.adoc[OpenTelemetry Guide] provides information about the OpenTelemetry extension.
====

The bridge is much more than the simple OTLP registry found in Quarkiverse. In this extension, the OpenTelemetry SDK provides a Micrometer registry implementation.

This allows the normal use of the Micrometer API, but have the metrics handled by the OpenTelemetry extension. All the configurations of the OpenTelemetry extension are available for this bridge.

The bridge enables to forward to OpenTelemetry all the automatic instrumentation metrics generated by Micrometer in Quarkus, as well as custom user metrics.

== Usage

If you already have your Quarkus project configured, you can add the `quarkus-micrometer-opentelemetry` extension to your project by running the following command in your project base directory:

:add-extension-extensions: micrometer-opentelemetry
include::{includes}/devtools/extension-add.adoc[]

This will add the following to your build file:

[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-opentelemetry</artifactId>
</dependency>
----

[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
.build.gradle
----
implementation("io.quarkus:quarkus-micrometer-opentelemetry")
----


4 changes: 2 additions & 2 deletions extensions/micrometer-opentelemetry-bridge/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-opentelemetry-bridge-parent</artifactId>
<artifactId>quarkus-micrometer-opentelemetry-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-micrometer-opentelemetry-bridge-deployment</artifactId>
<artifactId>quarkus-micrometer-opentelemetry-deployment</artifactId>
<name>Quarkus - Micrometer to OpenTelemetry Bridge - Deployment</name>
<description>Micrometer registry implemented by the OpenTelemetry SDK</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import io.micrometer.core.annotation.Counted;
import io.micrometer.core.aop.MeterTag;
import io.quarkus.micrometer.opentelemetry.deployment.MicrometerCounterInterceptorTest;
import io.smallrye.mutiny.Uni;
import jakarta.enterprise.context.ApplicationScoped;

import java.util.concurrent.CompletableFuture;

import static io.quarkus.micrometer.opentelemetry.deployment.MicrometerCounterInterceptorTest.*;
import static io.quarkus.micrometer.opentelemetry.deployment.compatibility.MicrometerCounterInterceptorTest.*;
import static java.util.concurrent.CompletableFuture.supplyAsync;

@ApplicationScoped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public MetricDataFilter get(final String name) {
return new MetricDataFilter(this, name);
}

public MetricDataFilter find(final String name) {
return new MetricDataFilter(this, name);
}

/*
* ignore points with /export in the route
*/
Expand Down Expand Up @@ -91,7 +95,6 @@ private Integer countMaxPoints(String name, String target) {
return 0;
}
int size = metricData.get(metricData.size() - 1).getData().getPoints().size();
System.out.println("Max points: " + size);
return size;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.micrometer.opentelemetry.deployment;
package io.quarkus.micrometer.opentelemetry.deployment.compatibility;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
Expand Down Expand Up @@ -28,6 +28,9 @@
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

/**
* Copy of io.quarkus.micrometer.deployment.binder.UriTagTest
*/
public class HttpCompatibilityTest {
@RegisterExtension
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.micrometer.opentelemetry.deployment;
package io.quarkus.micrometer.opentelemetry.deployment.compatibility;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.micrometer.opentelemetry.deployment;
package io.quarkus.micrometer.opentelemetry.deployment.compatibility;

import io.micrometer.common.annotation.ValueResolver;
import io.micrometer.core.annotation.Counted;
Expand All @@ -22,7 +22,9 @@
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;


/**
* Copy of io.quarkus.micrometer.runtime.MicrometerCounterInterceptorTest
*/
public class MicrometerCounterInterceptorTest {

@RegisterExtension
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.micrometer.opentelemetry.deployment;
package io.quarkus.micrometer.opentelemetry.deployment.compatibility;

import io.opentelemetry.sdk.metrics.data.DoublePointData;
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
Expand All @@ -23,6 +23,9 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* Copy of io.quarkus.micrometer.runtime.MicrometerTimedInterceptorTest
*/
public class MicrometerTimedInterceptorTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
Expand All @@ -33,14 +36,9 @@ public class MicrometerTimedInterceptorTest {
.overrideConfigKey("quarkus.otel.logs.exporter", "none")
.overrideConfigKey("quarkus.otel.metrics.exporter", "in-memory")
.overrideConfigKey("quarkus.otel.metric.export.interval", "300ms")
// .overrideConfigKey("quarkus.micrometer.binder.http-client.enabled", "true")
// .overrideConfigKey("quarkus.micrometer.binder.http-server.enabled", "true")
.overrideConfigKey("quarkus.redis.devservices.enabled", "false")
// .overrideConfigKey("quarkus.micrometer.binder.mp-metrics.enabled", "false")
// .overrideConfigKey("quarkus.micrometer.binder.vertx.enabled", "false")
// .overrideConfigKey("quarkus.micrometer.binder.jvm", "false")
// .overrideConfigKey("quarkus.micrometer.registry-enabled-default", "false")
.overrideConfigKey("quarkus.redis.devservices.enabled", "false")
.overrideConfigKey("quarkus.micrometer.binder.mp-metrics.enabled", "false")
.overrideConfigKey("quarkus.micrometer.binder.vertx.enabled", "false")
.overrideConfigKey("quarkus.micrometer.registry-enabled-default", "false")
.withApplicationRoot((jar) -> jar
.addClass(CountedResource.class)
.addClass(TimedResource.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package io.quarkus.micrometer.opentelemetry.deployment.compatibility;

import io.opentelemetry.sdk.metrics.data.HistogramPointData;
import io.quarkus.micrometer.opentelemetry.deployment.common.InMemoryMetricExporter;
import io.quarkus.micrometer.opentelemetry.deployment.common.InMemoryMetricExporterProvider;
import io.quarkus.micrometer.opentelemetry.deployment.common.MetricDataFilter;
import io.quarkus.rest.client.reactive.Url;
import io.quarkus.test.QuarkusUnitTest;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class RestClientUriParameterTest {

@RegisterExtension
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
.withApplicationRoot(
jar -> jar.addClasses(Resource.class, Client.class)
.addClasses(InMemoryMetricExporter.class,
InMemoryMetricExporterProvider.class,
MetricDataFilter.class))
.overrideConfigKey("quarkus.redis.devservices.enabled", "false")
.overrideConfigKey("quarkus.rest-client.\"client\".url", "http://does-not-exist.io");

@Inject
InMemoryMetricExporter metricExporter;

@RestClient
Client client;

@ConfigProperty(name = "quarkus.http.test-port")
Integer testPort;

@Test
public void testOverride() {
String result = client.getById("http://localhost:" + testPort, "bar");
assertEquals("bar", result);

metricExporter.assertCountDataPointsAtLeastOrEqual("http.client.requests", null, 1);
assertEquals(1, metricExporter.find("http.client.requests")
.tag("uri", "/example/{id}")
.lastReadingDataPoint(HistogramPointData.class).getCount());
}

@Path("/example")
@RegisterRestClient(baseUri = "http://dummy")
public interface Client {

@GET
@Path("/{id}")
String getById(@Url String baseUri, @PathParam("id") String id);
}

@Path("/example")
public static class Resource {

@RestClient
Client client;

@GET
@Path("/{id}")
@Produces(MediaType.TEXT_PLAIN)
public String example() {
return "bar";
}

@GET
@Path("/call")
@Produces(MediaType.TEXT_PLAIN)
public String call() {
return client.getById("http://localhost:8080", "1");
}
}
}
2 changes: 1 addition & 1 deletion extensions/micrometer-opentelemetry-bridge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-micrometer-opentelemetry-bridge-parent</artifactId>
<artifactId>quarkus-micrometer-opentelemetry-parent</artifactId>
<name>Quarkus - Micrometer to OpenTelemetry Bridge - Parent</name>
<packaging>pom</packaging>

Expand Down
4 changes: 2 additions & 2 deletions extensions/micrometer-opentelemetry-bridge/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-opentelemetry-bridge-parent</artifactId>
<artifactId>quarkus-micrometer-opentelemetry-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-micrometer-opentelemetry-bridge</artifactId>
<artifactId>quarkus-micrometer-opentelemetry</artifactId>
<name>Quarkus - Micrometer to OpenTelemetry Bridge - Runtime</name>
<description>Micrometer registry implemented by the OpenTelemetry SDK</description>

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/micrometer-opentelemetry-bridge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
<version>999-SNAPSHOT</version>
</parent>

<artifactId>quarkus-integration-test-micrometer-opentelemetry-bridge</artifactId>
<artifactId>quarkus-integration-test-micrometer-opentelemetry</artifactId>
<name>Quarkus - Integration Tests - Micrometer to OpenTelemetry Bridge</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-opentelemetry-bridge</artifactId>
<artifactId>quarkus-micrometer-opentelemetry</artifactId>
<version>999-SNAPSHOT</version>
</dependency>

Expand Down

0 comments on commit 35f4d7a

Please sign in to comment.