Skip to content

Commit

Permalink
Add logs TCK
Browse files Browse the repository at this point in the history
  • Loading branch information
yasmin-aumeeruddy committed Apr 22, 2024
1 parent fe6e10f commit 61837e9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
21 changes: 20 additions & 1 deletion tck/logs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.eclipse.microprofile.telemetry</groupId>
<artifactId>microprofile-telemetry-tck-parent</artifactId>
<version>1.2-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</parent>

<artifactId>microprofile-telemetry-logs-tck</artifactId>
Expand Down Expand Up @@ -64,6 +64,25 @@
<artifactId>opentelemetry-semconv</artifactId>
<version>${version.otel.semconv}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.opentelemetry.instrumentation/opentelemetry-logback-appender-1.0 -->
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-logback-appender-1.0</artifactId>
<version>2.2.0-alpha</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/jul-to-slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>2.0.13</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*
*/

package org.eclipse.microprofile.telemetry.logs.tck.cdi;
package org.eclipse.microprofile.telemetry.logs.tck.application;

import java.util.logging.Logger;

import org.eclipse.microprofile.telemetry.logs.tck.TestLibraries;
import org.eclipse.microprofile.telemetry.logs.tck.exporter.InMemoryLogRecordExporter;
Expand All @@ -29,12 +31,15 @@
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.slf4j.bridge.SLF4JBridgeHandler;
import org.testng.annotations.Test;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender;
import io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider;
import jakarta.inject.Inject;

public class PrintLineTest extends Arquillian {

public class LogAppenderTest extends Arquillian {
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
Expand All @@ -43,13 +48,30 @@ public static WebArchive createDeployment() {
.addAsServiceProvider(ConfigurableLogRecordExporterProvider.class,
InMemoryLogRecordExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.logs.exporter=none\notel.traces.exporter=none\notel.logs.exporter=in-memory"),
"otel.sdk.disabled=false\notel.metrics.exporter=\notel.traces.exporter=none\notel.logs.exporter=in-memory"),
"META-INF/microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Inject
private OpenTelemetry openTelemetry;

@Inject
private InMemoryLogRecordExporter memoryExporter;

private static final java.util.logging.Logger julLogger = Logger.getLogger("jul-logger");

@Test
void printLine() {
System.out.println("Test this is working");
void printLine() throws InterruptedException {
// Install OpenTelemetry in logback appender
OpenTelemetryAppender.install(openTelemetry);

// Route JUL logs to slf4j
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
julLogger.info("A JUL log message without a span");

Thread.sleep(100);
System.out.println(memoryExporter.getFinishedLogRecordItems());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
public final class InMemoryLogRecordExporter implements LogRecordExporter {
private boolean isStopped = false;
private final Queue<LogRecordData> finishedLogItems = new ConcurrentLinkedQueue<>();

public List<LogRecordData> getFinishedLogRecordItems() {
return Collections.unmodifiableList(new ArrayList<>(finishedLogItems));
}
Expand All @@ -50,6 +51,8 @@ public CompletableResultCode export(Collection<LogRecordData> logs) {
}
logs.stream()
.forEach(finishedLogItems::add);
System.out.println("EXPORTING");
System.out.println(logs);
return CompletableResultCode.ofSuccess();
}

Expand Down
2 changes: 1 addition & 1 deletion tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.eclipse.microprofile.telemetry</groupId>
<artifactId>microprofile-telemetry-parent</artifactId>
<version>1.2-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</parent>

<artifactId>microprofile-telemetry-tck-parent</artifactId>
Expand Down

0 comments on commit 61837e9

Please sign in to comment.