From 388af9670b03bac04bbd6371bea6fb8d023e1fb2 Mon Sep 17 00:00:00 2001 From: Jean Bisutti Date: Mon, 15 Jan 2024 15:03:22 +0100 Subject: [PATCH] Fix log replay of the Log4j 2 appender --- .../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); }