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
173 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
66 changes: 66 additions & 0 deletions
66
...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,66 @@ | ||
package io.quarkus.opentelemetry.deployment.common; | ||
|
||
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; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import org.awaitility.Awaitility; | ||
|
||
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 static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@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"; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...y/deployment/src/test/java/io/quarkus/opentelemetry/deployment/logs/JBossLoggingTest.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.logs; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.instrumentation.annotations.WithSpan; | ||
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; | ||
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 java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class JBossLoggingTest { | ||
|
||
private static final String MESSAGE = "Hello from JBoss Logging"; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(HelloBean.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.exporter=none\n"), | ||
"application.properties")); | ||
|
||
@Inject | ||
InMemoryLogRecordExporter logRecordExporter; | ||
|
||
@Inject | ||
HelloBean helloBean; | ||
|
||
@BeforeEach | ||
void setup() { | ||
logRecordExporter.reset(); | ||
} | ||
|
||
@Test | ||
public void testJBossLogging() { | ||
helloBean.hello(); | ||
List<LogRecordData> finishedLogRecordItems = logRecordExporter.getFinishedLogRecordItemsAtLeast(4); | ||
assertThat(finishedLogRecordItems.getLast().getBody().asString()).isEqualTo(MESSAGE); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class HelloBean { | ||
private static final Logger LOG = Logger.getLogger(HelloBean.class.getName()); | ||
|
||
public String hello() { | ||
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