From 9ec6401fae2721f52c7c6bc3bafaef070d4123fd Mon Sep 17 00:00:00 2001 From: Jean Bisutti Date: Wed, 17 Jan 2024 18:55:47 +0100 Subject: [PATCH] Fix log replay of the Log4j 2 appender (#10243) --- .../log4j/appender/v2_17/OpenTelemetryAppender.java | 3 --- .../appender/v2_17/LogReplayOpenTelemetryAppenderTest.java | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/instrumentation/log4j/log4j-appender-2.17/library/src/main/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/OpenTelemetryAppender.java b/instrumentation/log4j/log4j-appender-2.17/library/src/main/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/OpenTelemetryAppender.java index 3877296fcf6f..67b396c24311 100644 --- a/instrumentation/log4j/log4j-appender-2.17/library/src/main/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/OpenTelemetryAppender.java +++ b/instrumentation/log4j/log4j-appender-2.17/library/src/main/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/OpenTelemetryAppender.java @@ -157,9 +157,6 @@ public B setOpenTelemetry(OpenTelemetry openTelemetry) { @Override public OpenTelemetryAppender build() { OpenTelemetry openTelemetry = this.openTelemetry; - if (openTelemetry == null) { - openTelemetry = OpenTelemetry.noop(); - } return new OpenTelemetryAppender( getName(), getLayout(), diff --git a/instrumentation/log4j/log4j-appender-2.17/library/src/test/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/LogReplayOpenTelemetryAppenderTest.java b/instrumentation/log4j/log4j-appender-2.17/library/src/test/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/LogReplayOpenTelemetryAppenderTest.java index 8c65f7761b6b..af14fe95a4bf 100644 --- a/instrumentation/log4j/log4j-appender-2.17/library/src/test/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/LogReplayOpenTelemetryAppenderTest.java +++ b/instrumentation/log4j/log4j-appender-2.17/library/src/test/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/LogReplayOpenTelemetryAppenderTest.java @@ -14,6 +14,7 @@ import java.util.List; import org.apache.logging.log4j.message.StringMapMessage; import org.apache.logging.log4j.message.StructuredDataMessage; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,6 +23,10 @@ class LogReplayOpenTelemetryAppenderTest extends AbstractOpenTelemetryAppenderTe @BeforeEach void setup() { generalBeforeEachSetup(); + } + + @AfterEach + void resetOpenTelemetry() { OpenTelemetryAppender.install(null); }