forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
255 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...t/src/test/java/io/quarkus/opentelemetry/deployment/common/InMemoryLogRecordExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.quarkus.opentelemetry.deployment.common; | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Queue; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.awaitility.Awaitility; | ||
|
||
import io.opentelemetry.sdk.common.CompletableResultCode; | ||
import io.opentelemetry.sdk.logs.data.LogRecordData; | ||
import io.opentelemetry.sdk.logs.export.LogRecordExporter; | ||
import io.quarkus.arc.Unremovable; | ||
|
||
@Unremovable | ||
@ApplicationScoped | ||
public class InMemoryLogRecordExporter implements LogRecordExporter { | ||
final Queue<LogRecordData> finishedLogItems = new ConcurrentLinkedQueue(); | ||
boolean isStopped = false; | ||
|
||
private InMemoryLogRecordExporter() { | ||
} | ||
|
||
public static InMemoryLogRecordExporter create() { | ||
return new InMemoryLogRecordExporter(); | ||
} | ||
|
||
public List<LogRecordData> getFinishedLogRecordItemsAtLeast(final int count) { | ||
Awaitility.await().atMost(5, SECONDS) | ||
.untilAsserted(() -> assertThat(getFinishedLogRecordItems().size()).isGreaterThanOrEqualTo(count)); | ||
return getFinishedLogRecordItems(); | ||
} | ||
|
||
private List<LogRecordData> getFinishedLogRecordItems() { | ||
return Collections.unmodifiableList(new ArrayList(this.finishedLogItems)); | ||
} | ||
|
||
public void reset() { | ||
this.finishedLogItems.clear(); | ||
} | ||
|
||
public CompletableResultCode export(Collection<LogRecordData> logs) { | ||
if (this.isStopped) { | ||
return CompletableResultCode.ofFailure(); | ||
} else { | ||
this.finishedLogItems.addAll(logs); | ||
return CompletableResultCode.ofSuccess(); | ||
} | ||
} | ||
|
||
public CompletableResultCode flush() { | ||
return CompletableResultCode.ofSuccess(); | ||
} | ||
|
||
public CompletableResultCode shutdown() { | ||
this.isStopped = true; | ||
this.finishedLogItems.clear(); | ||
return CompletableResultCode.ofSuccess(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...st/java/io/quarkus/opentelemetry/deployment/common/InMemoryLogRecordExporterProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.quarkus.opentelemetry.deployment.common; | ||
|
||
import jakarta.enterprise.inject.spi.CDI; | ||
|
||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider; | ||
import io.opentelemetry.sdk.logs.export.LogRecordExporter; | ||
import io.opentelemetry.sdk.testing.exporter.InMemoryLogRecordExporter; | ||
|
||
public class InMemoryLogRecordExporterProvider implements ConfigurableLogRecordExporterProvider { | ||
@Override | ||
public LogRecordExporter createExporter(ConfigProperties configProperties) { | ||
return CDI.current().select(InMemoryLogRecordExporter.class).get(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "in-memory"; | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
...ployment/src/test/java/io/quarkus/opentelemetry/deployment/logs/LoggingFrameworkTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package io.quarkus.opentelemetry.deployment.logs; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.opentelemetry.sdk.logs.data.LogRecordData; | ||
import io.quarkus.opentelemetry.deployment.common.InMemoryLogRecordExporter; | ||
import io.quarkus.opentelemetry.deployment.common.InMemoryLogRecordExporterProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class LoggingFrameworkTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(JBossLoggingBean.class, SLF4JBean.class, JulBean.class, Log4j2Bean.class) | ||
.addClasses(InMemoryLogRecordExporter.class, InMemoryLogRecordExporterProvider.class) | ||
.addAsResource(new StringAsset(InMemoryLogRecordExporterProvider.class.getCanonicalName()), | ||
"META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider") | ||
.add(new StringAsset( | ||
"quarkus.otel.logs.enabled=true\n" + | ||
"quarkus.otel.traces.enabled=false\n"), | ||
"application.properties")); | ||
|
||
@Inject | ||
InMemoryLogRecordExporter logRecordExporter; | ||
|
||
@Inject | ||
JBossLoggingBean jBossLoggingBean; | ||
|
||
@Inject | ||
SLF4JBean slf4jBean; | ||
|
||
@Inject | ||
JulBean julBean; | ||
|
||
@Inject | ||
Log4j2Bean log4j2Bean; | ||
|
||
@BeforeEach | ||
void setup() { | ||
logRecordExporter.reset(); | ||
} | ||
|
||
@Test | ||
public void testJBossLogging() { | ||
final String message = "JBoss Logging message"; | ||
assertEquals("hello", jBossLoggingBean.hello(message)); | ||
List<LogRecordData> finishedLogRecordItems = logRecordExporter.getFinishedLogRecordItemsAtLeast(1); | ||
LogRecordData last = finishedLogRecordItems.get(finishedLogRecordItems.size() - 1); | ||
assertThat(last.getBody().asString()).isEqualTo(message); | ||
} | ||
|
||
@Test | ||
public void testSLF4JLogging() { | ||
final String message = "SLF4J Logging message"; | ||
assertEquals("hello", slf4jBean.hello(message)); | ||
List<LogRecordData> finishedLogRecordItems = logRecordExporter.getFinishedLogRecordItemsAtLeast(1); | ||
LogRecordData last = finishedLogRecordItems.get(finishedLogRecordItems.size() - 1); | ||
assertThat(last.getBody().asString()).isEqualTo(message); | ||
} | ||
|
||
@Test | ||
public void testLog4jLogging() { | ||
final String message = "Log4j Logging message"; | ||
assertEquals("hello", log4j2Bean.hello(message)); | ||
List<LogRecordData> finishedLogRecordItems = logRecordExporter.getFinishedLogRecordItemsAtLeast(1); | ||
LogRecordData last = finishedLogRecordItems.get(finishedLogRecordItems.size() - 1); | ||
assertThat(last.getBody().asString()).isEqualTo(message); | ||
} | ||
|
||
@Test | ||
public void testJulLogging() { | ||
final String message = "JUL Logging message"; | ||
assertEquals("hello", julBean.hello(message)); | ||
List<LogRecordData> finishedLogRecordItems = logRecordExporter.getFinishedLogRecordItemsAtLeast(1); | ||
LogRecordData last = finishedLogRecordItems.get(finishedLogRecordItems.size() - 1); | ||
assertThat(last.getBody().asString()).isEqualTo(message); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class JBossLoggingBean { | ||
private static final Logger LOG = Logger.getLogger(JBossLoggingBean.class.getName()); | ||
|
||
public String hello(final String message) { | ||
LOG.info(message); | ||
return "hello"; | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
public static class SLF4JBean { | ||
// using the logger adapter: https://quarkus.io/guides/logging#add-a-logging-adapter-to-your-application | ||
private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(SLF4JBean.class); | ||
|
||
public String hello(final String message) { | ||
LOG.info(message); | ||
return "hello"; | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
public static class Log4j2Bean { | ||
// using the logger adapter: https://quarkus.io/guides/logging#add-a-logging-adapter-to-your-application | ||
private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager | ||
.getLogger(Log4j2Bean.class); | ||
|
||
public String hello(final String message) { | ||
LOG.info(message); | ||
return "hello"; | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
public static class JulBean { | ||
private static final java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(JulBean.class.getName()); | ||
|
||
public String hello(final String message) { | ||
LOG.info(message); | ||
return "hello"; | ||
} | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...-config/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.opentelemetry.deployment.common.InMemoryLogRecordExporterProvider |
8 changes: 7 additions & 1 deletion
8
extensions/opentelemetry/deployment/src/test/resources/application-default.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# Traces | ||
quarkus.otel.traces.exporter=test-span-exporter | ||
quarkus.otel.bsp.schedule.delay=50ms | ||
quarkus.otel.bsp.export.timeout=1s | ||
|
||
# Metrics | ||
quarkus.otel.metrics.exporter=in-memory | ||
quarkus.otel.metric.export.interval=300ms | ||
quarkus.otel.metric.export.interval=300ms | ||
|
||
# Logs | ||
quarkus.otel.logs.exporter=in-memory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters