Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Dec 8, 2023
1 parent 653d5cc commit d067bfa
Show file tree
Hide file tree
Showing 20 changed files with 508 additions and 128 deletions.
10 changes: 10 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6232,6 +6232,16 @@
<version>${project.version}</version>
</dependency>
<!-- End of Relocations, please put new extensions above this list -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>logging-opentelemetry</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>logging-opentelemetry-deployment</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>
</dependencyManagement>
Expand Down
48 changes: 48 additions & 0 deletions extensions/logging-opentelemetry/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>logging-opentelemetry-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>logging-opentelemetry-deployment</artifactId>
<name>Logging Opentelemetry - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>logging-opentelemetry</artifactId>
<version>${project.version}</version> <!-- TODO add in bom-->
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.quarkus.logging.opentelemetry.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.LogHandlerBuildItem;
import io.quarkus.logging.opentelemetry.runtime.OpenTelemetryLogConfig;
import io.quarkus.logging.opentelemetry.runtime.OpenTelemetryLogRecorder;

class OpenTelemetryLogHandlerProcessor {

private static final String FEATURE = "logging-opentelemetry";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
LogHandlerBuildItem build(OpenTelemetryLogRecorder recorder, OpenTelemetryLogConfig config) {
return new LogHandlerBuildItem(recorder.initializeHandler(config));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.logging.opentelemetry.test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;

public class LoggingOpentelemetryDevModeTest {

// Start hot reload (DevMode) test with your extension loaded
@RegisterExtension
static final QuarkusDevModeTest devModeTest = new QuarkusDevModeTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Test
public void writeYourOwnDevModeTest() {
// Write your dev mode tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-hot-reload for more information
Assertions.assertTrue(true, "Add dev mode assertions to " + getClass().getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.logging.opentelemetry.test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

public class LoggingOpentelemetryTest {

// Start unit test with your extension loaded
@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Test
public void writeYourOwnUnitTest() {
// Write your unit tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-extensions for more information
Assertions.assertTrue(true, "Add some assertions to " + getClass().getName());
}
}
19 changes: 19 additions & 0 deletions extensions/logging-opentelemetry/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extensions-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>logging-opentelemetry-parent</artifactId>
<packaging>pom</packaging>
<name>Logging Opentelemetry - Parent</name>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
66 changes: 66 additions & 0 deletions extensions/logging-opentelemetry/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>logging-opentelemetry-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>logging-opentelemetry</artifactId>
<name>Logging Opentelemetry - Runtime</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-semconv</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>extension-descriptor</goal>
</goals>
<configuration>
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}</deployment>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.logging.opentelemetry.runtime;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot(phase = ConfigPhase.RUN_TIME, name = "log.handler.open-telemetry")
public class OpenTelemetryLogConfig {
/**
* Determine whether to enable the OpenTelemetry logging handler
*/
@ConfigItem
public boolean enabled;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.quarkus.logging.opentelemetry.runtime;

import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.logs.Logger;
import io.opentelemetry.api.logs.Severity;

public class OpenTelemetryLogHandler extends Handler {
private final Logger openTelemetry;

public OpenTelemetryLogHandler(OpenTelemetry openTelemetry) {
this.openTelemetry = openTelemetry.getLogsBridge().get("quarkus-log-appender");
}

@Override
public void publish(LogRecord record) {
openTelemetry.logRecordBuilder()
.setSeverity(mapSeverity(record.getLevel()))
.setSeverityText(record.getLevel().getName())
.setBody(record.getMessage()) // TODO check that we didn't need to format it
.setObservedTimestamp(record.getInstant())
// TODO add attributes
.emit();
}

private Severity mapSeverity(Level level) {
if (Level.SEVERE.equals(level)) {
return Severity.ERROR;
}
if (Level.WARNING.equals(level)) {
return Severity.WARN;
}
if (Level.INFO.equals(level) || Level.CONFIG.equals(level)) {
return Severity.INFO;
}
if (Level.FINE.equals(level)) {
return Severity.DEBUG;
}
if (Level.FINER.equals(level) || Level.FINEST.equals(level) || Level.ALL.equals(level)) {
return Severity.TRACE;
}
return Severity.UNDEFINED_SEVERITY_NUMBER;
}

@Override
public void flush() {

}

@Override
public void close() throws SecurityException {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.logging.opentelemetry.runtime;

import java.util.Optional;
import java.util.logging.Handler;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class OpenTelemetryLogRecorder {
public RuntimeValue<Optional<Handler>> initializeHandler(final OpenTelemetryLogConfig config) {
if (!config.enabled) {
return new RuntimeValue<>(Optional.empty());
}

OpenTelemetryLogHandler handler = new OpenTelemetryLogHandler(GlobalOpenTelemetry.get());

return new RuntimeValue<>(Optional.of(handler));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Logging Opentelemetry
#description: Do something useful.
metadata:
# keywords:
# - logging-opentelemetry
# guide: ... # To create and publish this guide, see https://github.com/quarkiverse/quarkiverse/wiki#documenting-your-extension
# categories:
# - "miscellaneous"
# status: "preview"
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@

<!-- JMS -->
<module>jms-spi</module>
<module>logging-opentelemetry</module>

</modules>

Expand Down
Loading

0 comments on commit d067bfa

Please sign in to comment.