Make OpenTelemetryAppender.Builder public
Allows for programatic configuration as discussed in this [CNCF slack
thread](https://cloud-native.slack.com/archives/C01N5UCHTEH/p1673028580643009).
MODIFY
instrumentation/log4j/log4j-appender-2.17/library/src/main/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/OpenTelemetryAppender.java
instrumentation/log4j/log4j-appender-2.17/library/src/main/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/OpenTelemetryAppender.java
@@ -49,7 +49,7 @@ public class OpenTelemetryAppender extends AbstractAppender {
return new Builder<B>().asBuilder();
}
- static class Builder<B extends Builder<B>> extends AbstractAppender.Builder<B>
+ public static class Builder<B extends Builder<B>> extends AbstractAppender.Builder<B>
implements org.apache.logging.log4j.core.util.Builder<OpenTelemetryAppender> {
@PluginBuilderAttribute private boolean captureExperimentalAttributes;

MODIFY
instrumentation/log4j/log4j-appender-2.17/library/src/test/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/OpenTelemetryAppenderConfigTest.java
instrumentation/log4j/log4j-appender-2.17/library/src/test/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/OpenTelemetryAppenderConfigTest.java
@@ -32,6 +32,8 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.message.FormattedMessage;
import org.apache.logging.log4j.message.StringMapMessage;
import org.apache.logging.log4j.message.StructuredDataMessage;
import org.junit.jupiter.api.BeforeAll;
@@ -68,6 +70,22 @@ class OpenTelemetryAppenderConfigTest {
ThreadContext.clearAll();
}
+ @Test
+ void initializeWithBuilder() {
+ OpenTelemetryAppender appender =
+ OpenTelemetryAppender.builder().setName("OpenTelemetryAppender").build();
+ appender.start();
+
+ appender.append(
+ Log4jLogEvent.newBuilder()
+ .setMessage(new FormattedMessage("log message 1", (Object) null))
+ .build());
+
+ List<LogRecordData> logDataList = logRecordExporter.getFinishedLogItems();
+ assertThat(logDataList)
+ .satisfiesExactly(logRecordData -> assertThat(logDataList.get(0)).hasBody("log message 1"));
+ }
+
@Test
void logNoSpan() {
logger.info("log message 1");

Make OpenTelemetryAppender.Builder public (#7521)

Allows for programatic configuration as discussed in this [CNCF slack
thread](https://cloud-native.slack.com/archives/C01N5UCHTEH/p1673028580643009).