Skip to content

Commit 9dc84c9

Browse files
committed
Micrometer to OTel Bridge
1 parent 969b378 commit 9dc84c9

File tree

17 files changed

+1228
-0
lines changed

17 files changed

+1228
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.quarkus</groupId>
9+
<artifactId>quarkus-micrometer-opentelemetry-bridge-parent</artifactId>
10+
<version>999-SNAPSHOT</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>quarkus-micrometer-opentelemetry-bridge-deployment</artifactId>
15+
<name>Quarkus - Micrometer to OpenTelemetry Bridge - Deployment</name>
16+
<description>Micrometer registry implemented by the OpenTelemetry SDK</description>
17+
18+
<dependencies>
19+
20+
<dependency>
21+
<groupId>io.quarkus</groupId>
22+
<artifactId>quarkus-micrometer-opentelemetry-bridge</artifactId>
23+
<version>${project.version}</version>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>io.quarkus</groupId>
28+
<artifactId>quarkus-micrometer-deployment</artifactId>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>io.quarkus</groupId>
33+
<artifactId>quarkus-opentelemetry-deployment</artifactId>
34+
</dependency>
35+
36+
<!--TESTS-->
37+
<dependency>
38+
<groupId>io.quarkus</groupId>
39+
<artifactId>quarkus-junit5-internal</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>io.quarkus</groupId>
45+
<artifactId>quarkus-junit5</artifactId>
46+
<scope>test</scope>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>io.rest-assured</groupId>
51+
<artifactId>rest-assured</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>org.awaitility</groupId>
57+
<artifactId>awaitility</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>org.assertj</groupId>
63+
<artifactId>assertj-core</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>io.opentelemetry</groupId>
69+
<artifactId>opentelemetry-sdk-testing</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>io.smallrye.reactive</groupId>
75+
<artifactId>smallrye-mutiny-vertx-web-client</artifactId>
76+
<scope>test</scope>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>io.quarkus</groupId>
81+
<artifactId>quarkus-rest-client-deployment</artifactId>
82+
<scope>test</scope>
83+
</dependency>
84+
85+
<dependency>
86+
<groupId>io.quarkus</groupId>
87+
<artifactId>quarkus-rest-jackson-deployment</artifactId>
88+
<scope>test</scope>
89+
</dependency>
90+
91+
<dependency>
92+
<groupId>io.quarkus</groupId>
93+
<artifactId>quarkus-vertx-http-deployment</artifactId>
94+
<scope>test</scope>
95+
</dependency>
96+
97+
<dependency>
98+
<groupId>io.quarkus</groupId>
99+
<artifactId>quarkus-reactive-routes-deployment</artifactId>
100+
<scope>test</scope>
101+
</dependency>
102+
103+
</dependencies>
104+
<build>
105+
<plugins>
106+
<plugin>
107+
<artifactId>maven-surefire-plugin</artifactId>
108+
<configuration>
109+
<systemPropertyVariables>
110+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
111+
<quarkus.log.level>INFO</quarkus.log.level>
112+
</systemPropertyVariables>
113+
</configuration>
114+
</plugin>
115+
<plugin>
116+
<artifactId>maven-compiler-plugin</artifactId>
117+
<executions>
118+
<execution>
119+
<id>default-compile</id>
120+
<configuration>
121+
<annotationProcessorPaths>
122+
<path>
123+
<groupId>io.quarkus</groupId>
124+
<artifactId>quarkus-extension-processor</artifactId>
125+
<version>${project.version}</version>
126+
</path>
127+
</annotationProcessorPaths>
128+
</configuration>
129+
</execution>
130+
</executions>
131+
</plugin>
132+
</plugins>
133+
</build>
134+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package io.quarkus.micrometer.opentelemetry.deployment;
2+
3+
import java.util.Locale;
4+
import java.util.function.BooleanSupplier;
5+
6+
import jakarta.enterprise.inject.Instance;
7+
import jakarta.inject.Singleton;
8+
9+
import org.jboss.jandex.ClassType;
10+
import org.jboss.jandex.DotName;
11+
import org.jboss.jandex.ParameterizedType;
12+
import org.jboss.jandex.Type;
13+
14+
import io.micrometer.core.instrument.MeterRegistry;
15+
import io.opentelemetry.api.OpenTelemetry;
16+
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
17+
import io.quarkus.deployment.annotations.BuildStep;
18+
import io.quarkus.deployment.annotations.BuildSteps;
19+
import io.quarkus.deployment.annotations.ExecutionTime;
20+
import io.quarkus.deployment.annotations.Record;
21+
import io.quarkus.micrometer.deployment.MicrometerProcessor;
22+
import io.quarkus.micrometer.opentelemetry.runtime.MicrometerOtelBridgeRecorder;
23+
import io.quarkus.opentelemetry.deployment.OpenTelemetryEnabled;
24+
import io.quarkus.opentelemetry.runtime.config.build.OTelBuildConfig;
25+
import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig;
26+
27+
@BuildSteps(onlyIf = {
28+
MicrometerProcessor.MicrometerEnabled.class,
29+
OpenTelemetryEnabled.class,
30+
MicrometerOtelBridgeProcessor.OtlpMetricsExporterEnabled.class })
31+
public class MicrometerOtelBridgeProcessor {
32+
33+
@BuildStep
34+
@Record(ExecutionTime.RUNTIME_INIT)
35+
SyntheticBeanBuildItem createBridgeBean(OTelRuntimeConfig otelRuntimeConfig,
36+
MicrometerOtelBridgeRecorder recorder) {
37+
38+
return SyntheticBeanBuildItem.configure(MeterRegistry.class)
39+
.defaultBean()
40+
.setRuntimeInit()
41+
.unremovable()
42+
.scope(Singleton.class)
43+
.addInjectionPoint(ParameterizedType.create(DotName.createSimple(Instance.class),
44+
new Type[] { ClassType.create(DotName.createSimple(OpenTelemetry.class.getName())) }, null))
45+
.createWith(recorder.createBridge(otelRuntimeConfig))
46+
.done();
47+
}
48+
49+
/**
50+
* No point in activating the bridge if the OTel metrics if off or the exporter is none.
51+
*/
52+
static class OtlpMetricsExporterEnabled implements BooleanSupplier {
53+
OTelBuildConfig otelBuildConfig;
54+
55+
public boolean getAsBoolean() {
56+
return otelBuildConfig.metrics().enabled().orElse(Boolean.TRUE) &&
57+
!otelBuildConfig.metrics().exporter().stream()
58+
.map(exporter -> exporter.toLowerCase(Locale.ROOT))
59+
.anyMatch(exporter -> exporter.contains("none"));
60+
}
61+
}
62+
63+
}

0 commit comments

Comments
 (0)