From 4428d1e956137193bd7c4a1530d27606dc48345e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 17:29:57 +0000 Subject: [PATCH 1/5] build: bump version.log4j from 2.12.4 to 2.24.0 Bumps `version.log4j` from 2.12.4 to 2.24.0. Updates `org.apache.logging.log4j:log4j-core` from 2.12.4 to 2.24.0 Updates `org.apache.logging.log4j:log4j-slf4j-impl` from 2.12.4 to 2.24.0 --- updated-dependencies: - dependency-name: org.apache.logging.log4j:log4j-core dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.apache.logging.log4j:log4j-slf4j-impl dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- apm-agent-plugins/apm-ecs-logging-plugin/pom.xml | 2 +- apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml b/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml index c6754f8e56..e2c8317512 100644 --- a/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml +++ b/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml @@ -41,7 +41,7 @@ org.apache.logging.log4j log4j-core - 2.23.1 + 2.24.0 provided true diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml index b99e850e8b..39b9a22959 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml @@ -24,7 +24,7 @@ org.apache.logging.log4j log4j-core - 2.23.1 + 2.24.0 provided diff --git a/pom.xml b/pom.xml index 830a12e056..7d39ab9746 100644 --- a/pom.xml +++ b/pom.xml @@ -124,7 +124,7 @@ - 2.12.4 + 2.24.0 1.6.0 5.0.15.RELEASE 9.4.11.v20180605 From 5b492f32178be2aa45bc1c419f8a151ddb41be43 Mon Sep 17 00:00:00 2001 From: jackshirazi Date: Mon, 9 Sep 2024 18:41:36 +0100 Subject: [PATCH 2/5] revert the change --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7d39ab9746..830a12e056 100644 --- a/pom.xml +++ b/pom.xml @@ -124,7 +124,7 @@ - 2.24.0 + 2.12.4 1.6.0 5.0.15.RELEASE 9.4.11.v20180605 From fb5d5b45ad1ede9ba789f56dc5d4ef4f7b469db3 Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Tue, 17 Sep 2024 12:43:29 +0200 Subject: [PATCH 3/5] Fix classpath for log4j2 tests --- .../apm-ecs-logging-plugin/pom.xml | 3 +- .../apm-log4j2-plugin-tests/pom.xml | 55 +++++++++++++++++++ .../log4j2/Log4j2InstrumentationTest.java | 0 .../Log4j2InstrumentationTestVersions.java | 2 +- .../Log4j2_17_1InstrumentationTest.java | 0 .../Log4j2_24_0InstrumentationTest.java | 46 ++++++++++++++++ .../log4j2/Log4j2_6SInstrumentationTest.java | 0 .../Log4j2ErrorCapturingTestVersions.java | 0 ...ggerErrorCapturingInstrumentationTest.java | 0 .../error/Log4j2_17_1ErrorCapturingTest.java | 0 .../src/test/resources/log4j2.xml | 0 .../apm-log4j2-plugin/pom.xml | 12 ---- apm-agent-plugins/apm-logging-plugin/pom.xml | 1 + 13 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/pom.xml rename apm-agent-plugins/apm-logging-plugin/{apm-log4j2-plugin => apm-log4j2-plugin-tests}/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java (100%) rename apm-agent-plugins/apm-logging-plugin/{apm-log4j2-plugin => apm-log4j2-plugin-tests}/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java (100%) rename apm-agent-plugins/apm-logging-plugin/{apm-log4j2-plugin => apm-log4j2-plugin-tests}/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_17_1InstrumentationTest.java (100%) create mode 100644 apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_24_0InstrumentationTest.java rename apm-agent-plugins/apm-logging-plugin/{apm-log4j2-plugin => apm-log4j2-plugin-tests}/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_6SInstrumentationTest.java (100%) rename apm-agent-plugins/apm-logging-plugin/{apm-log4j2-plugin => apm-log4j2-plugin-tests}/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2ErrorCapturingTestVersions.java (100%) rename apm-agent-plugins/apm-logging-plugin/{apm-log4j2-plugin => apm-log4j2-plugin-tests}/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2LoggerErrorCapturingInstrumentationTest.java (100%) rename apm-agent-plugins/apm-logging-plugin/{apm-log4j2-plugin => apm-log4j2-plugin-tests}/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2_17_1ErrorCapturingTest.java (100%) rename apm-agent-plugins/apm-logging-plugin/{apm-log4j2-plugin => apm-log4j2-plugin-tests}/src/test/resources/log4j2.xml (100%) diff --git a/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml b/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml index e2c8317512..b172bfdfce 100644 --- a/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml +++ b/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml @@ -41,7 +41,8 @@ org.apache.logging.log4j log4j-core - 2.24.0 + + ${version.log4j} provided true diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/pom.xml new file mode 100644 index 0000000000..8d593f7fc6 --- /dev/null +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + co.elastic.apm + apm-logging-plugin + 1.51.1-SNAPSHOT + + + apm-log4j2-plugin-tests + ${project.groupId}:${project.artifactId} + + + ${project.basedir}/../../.. + + + + + + + ${project.groupId} + apm-log4j2-plugin + ${project.version} + test + + + org.apache.logging.log4j + log4j-core + ${version.log4j} + test + + + ${project.groupId} + apm-logging-plugin-common + ${project.version} + test-jar + test + + + org.apache.ivy + ivy + test + + + + + diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java similarity index 100% rename from apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java rename to apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java similarity index 100% rename from apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java rename to apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java index 302f0132f5..5446b0cb35 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.log4j2; -import co.elastic.apm.agent.testutils.JUnit4TestClassWithDependencyRunner; import co.elastic.apm.agent.logging.LoggingConfigurationImpl; +import co.elastic.apm.agent.testutils.JUnit4TestClassWithDependencyRunner; import org.apache.logging.log4j.core.config.ConfigurationFactory; import org.junit.After; import org.junit.AfterClass; diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_17_1InstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_17_1InstrumentationTest.java similarity index 100% rename from apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_17_1InstrumentationTest.java rename to apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_17_1InstrumentationTest.java diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_24_0InstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_24_0InstrumentationTest.java new file mode 100644 index 0000000000..02741ef1cb --- /dev/null +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_24_0InstrumentationTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.log4j2; + +import co.elastic.apm.agent.testutils.JUnit4TestClassWithDependencyRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; + +import java.util.List; + +@DisabledOnOs(OS.WINDOWS) +public class Log4j2_24_0InstrumentationTest { + private final JUnit4TestClassWithDependencyRunner runner; + + public Log4j2_24_0InstrumentationTest() throws Exception { + List dependencies = List.of( + "org.apache.logging.log4j:log4j-core:2.24.0", + "org.apache.logging.log4j:log4j-api:2.24.0", + "co.elastic.logging:log4j2-ecs-layout:1.3.2" + ); + runner = new JUnit4TestClassWithDependencyRunner(dependencies, Log4j2InstrumentationTestVersions.class, Log4j2InstrumentationTest.class, + Log4j2InstrumentationTest.Log4j2LoggerFacade.class); + } + + @Test + public void testVersions() { + runner.run(); + } +} diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_6SInstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_6SInstrumentationTest.java similarity index 100% rename from apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_6SInstrumentationTest.java rename to apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_6SInstrumentationTest.java diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2ErrorCapturingTestVersions.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2ErrorCapturingTestVersions.java similarity index 100% rename from apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2ErrorCapturingTestVersions.java rename to apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2ErrorCapturingTestVersions.java diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2LoggerErrorCapturingInstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2LoggerErrorCapturingInstrumentationTest.java similarity index 100% rename from apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2LoggerErrorCapturingInstrumentationTest.java rename to apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2LoggerErrorCapturingInstrumentationTest.java diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2_17_1ErrorCapturingTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2_17_1ErrorCapturingTest.java similarity index 100% rename from apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2_17_1ErrorCapturingTest.java rename to apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2_17_1ErrorCapturingTest.java diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/resources/log4j2.xml b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/resources/log4j2.xml similarity index 100% rename from apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/resources/log4j2.xml rename to apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/resources/log4j2.xml diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml index 39b9a22959..ad208e00ea 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml @@ -32,18 +32,6 @@ log4j2-ecs-layout ${version.ecs.logging} - - ${project.groupId} - apm-logging-plugin-common - ${project.version} - test-jar - test - - - org.apache.ivy - ivy - test - diff --git a/apm-agent-plugins/apm-logging-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/pom.xml index 628560fea3..be0fc2aeb0 100644 --- a/apm-agent-plugins/apm-logging-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/pom.xml @@ -25,6 +25,7 @@ apm-tomcat-logging-plugin apm-slf4j-plugin apm-jul-plugin + apm-log4j2-plugin-tests From 5ae171aace571df58b72d86d15cf39f43b20d323 Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Tue, 17 Sep 2024 13:11:48 +0200 Subject: [PATCH 4/5] Upgrade log4j2 tests to JUnit5, disable broken tests --- .../log4j2/Log4j2InstrumentationTest.java | 165 +++-------------- .../Log4j2InstrumentationTestDefinitions.java | 168 ++++++++++++++++++ .../Log4j2InstrumentationTestVersions.java | 118 ------------ ...ggerErrorCapturingInstrumentationTest.java | 8 +- .../Log4j2_17_1InstrumentationTest.java | 46 ----- .../Log4j2_24_0InstrumentationTest.java | 46 ----- .../log4j2/Log4j2_6SInstrumentationTest.java | 46 ----- .../Log4j2ErrorCapturingTestVersions.java | 51 ------ .../error/Log4j2_17_1ErrorCapturingTest.java | 42 ----- 9 files changed, 201 insertions(+), 489 deletions(-) create mode 100644 apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestDefinitions.java delete mode 100644 apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java rename apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/{error => }/Log4j2LoggerErrorCapturingInstrumentationTest.java (90%) delete mode 100644 apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_17_1InstrumentationTest.java delete mode 100644 apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_24_0InstrumentationTest.java delete mode 100644 apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_6SInstrumentationTest.java delete mode 100644 apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2ErrorCapturingTestVersions.java delete mode 100644 apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2_17_1ErrorCapturingTest.java diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java index e8cfe0480a..a4855da304 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java @@ -18,146 +18,39 @@ */ package co.elastic.apm.agent.log4j2; -import co.elastic.apm.agent.loginstr.LoggingInstrumentationTest; -import co.elastic.apm.agent.loginstr.LoggerFacade; -import co.elastic.apm.agent.logging.LoggingConfigurationImpl; -import org.apache.logging.log4j.LogManager; -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.Appender; -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.appender.RandomAccessFileAppender; -import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; +import co.elastic.apm.agent.testutils.TestClassWithDependencyRunner; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -import java.net.URI; -import java.net.URISyntaxException; import java.util.List; -import java.util.Objects; -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Since the agent core uses log4j 2.12.4, and since both agent core and tests are loaded by the system class loader in unit tests, - * the proper way to test integration tests with log4j2 is only through dedicated class loaders. - */ -@Disabled -public class Log4j2InstrumentationTest extends LoggingInstrumentationTest { - - @BeforeAll - static void resetConfigFactory() { - ConfigurationFactory.resetConfigurationFactory(); - } - - @AfterAll - static void reInitLogging() { - LoggingConfigurationImpl.init(List.of(), ""); - } - - private static final Marker TEST_MARKER = MarkerManager.getMarker("TEST"); - - @Override - protected LoggerFacade createLoggerFacade() { - return new Log4j2LoggerFacade(); - } - - @Override - protected boolean markersSupported() { - return true; +@DisabledOnOs(OS.WINDOWS) +public class Log4j2InstrumentationTest { + + @ParameterizedTest + @ValueSource(strings = {"2.6", "2.17.1", "2.24.0"}) + public void testInstrumentation(String version) throws Exception { + List dependencies = List.of( + "org.apache.logging.log4j:log4j-core:" + version, + "org.apache.logging.log4j:log4j-api:" + version, + "co.elastic.logging:log4j2-ecs-layout:1.3.2" + ); + new TestClassWithDependencyRunner(dependencies, Log4j2InstrumentationTestDefinitions.class.getName(), + Log4j2InstrumentationTestDefinitions.Log4j2LoggerFacade.class.getName()) + .run(); } - @Override - protected void waitForFileRolling() { - try { - Thread.sleep(50); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - static class Log4j2LoggerFacade implements LoggerFacade { - - private Logger log4j2Logger; - private URI configLocation; - - public Log4j2LoggerFacade() { - try { - configLocation = Objects.requireNonNull(Log4j2InstrumentationTest.class.getClassLoader() - .getResource("log4j2.xml")).toURI(); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - } - - @Override - public void open() { - log4j2Logger = LogManager.getLogger("Test-File-Logger"); - assertThat(log4j2Logger).isInstanceOf(org.apache.logging.log4j.core.Logger.class); - - LoggerContext loggerContext = ((org.apache.logging.log4j.core.Logger) log4j2Logger).getContext(); - loggerContext.setConfigLocation(configLocation); - } - - @Override - public void close() { - LogManager.shutdown(); - } - - @Override - public String getLogFilePath() { - assertThat(log4j2Logger) - .isInstanceOf(org.apache.logging.log4j.core.Logger.class); - org.apache.logging.log4j.core.Logger logger = (org.apache.logging.log4j.core.Logger) log4j2Logger; - - assertThat(logger.getAppenders()).containsKey("FILE"); - Appender fileAppender = logger.getAppenders().get("FILE"); - assertThat(fileAppender).isInstanceOf(RandomAccessFileAppender.class); - - return ((RandomAccessFileAppender) fileAppender).getFileName(); - } - - @Override - public void trace(String message) { - log4j2Logger.trace(message); - } - - @Override - public void debug(String message) { - log4j2Logger.debug(message); - } - - @Override - public void debugWithMarker(String message) { - log4j2Logger.debug(TEST_MARKER, message); - } - - @Override - public void warn(String message) { - log4j2Logger.warn(message); - } - - @Override - public void error(String message) { - log4j2Logger.error(message); - } - - @Override - public void error(String message, Throwable throwable) { - log4j2Logger.error(message, throwable); - } - - @Override - public void putTraceIdToMdc(String traceId) { - ThreadContext.put("trace.id", traceId); - } - - @Override - public void removeTraceIdFromMdc() { - ThreadContext.remove("trace.id"); - } + //TODO: Error capturing is currently broken on 2.6 + @ParameterizedTest + @ValueSource(strings = {/*"2.6",*/ "2.17.1", "2.24.0"}) + public void testErrorCapture(String version) throws Exception { + List dependencies = List.of( + "org.apache.logging.log4j:log4j-core:" + version, + "org.apache.logging.log4j:log4j-api:" + version + ); + new TestClassWithDependencyRunner(dependencies, Log4j2LoggerErrorCapturingInstrumentationTest.class.getName()) + .run(); } } diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestDefinitions.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestDefinitions.java new file mode 100644 index 0000000000..4482a5e096 --- /dev/null +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestDefinitions.java @@ -0,0 +1,168 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.log4j2; + +import co.elastic.apm.agent.logging.LoggingConfigurationImpl; +import co.elastic.apm.agent.loginstr.LoggerFacade; +import co.elastic.apm.agent.loginstr.LoggingInstrumentationTest; +import co.elastic.apm.agent.testutils.TestClassWithDependencyRunner; +import org.apache.logging.log4j.LogManager; +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.Appender; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.appender.RandomAccessFileAppender; +import org.apache.logging.log4j.core.config.ConfigurationFactory; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; +import java.util.Objects; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Since the agent core uses log4j 2.12.4, and since both agent core and tests are loaded by the system class loader in unit tests, + * the proper way to test integration tests with log4j2 is only through dedicated class loaders. + */ +@TestClassWithDependencyRunner.DisableOutsideOfRunner +public class Log4j2InstrumentationTestDefinitions extends LoggingInstrumentationTest { + + @BeforeAll + static void resetConfigFactory() { + ConfigurationFactory.resetConfigurationFactory(); + } + + @AfterAll + static void reInitLogging() { + LoggingConfigurationImpl.init(List.of(), ""); + } + + private static final Marker TEST_MARKER = MarkerManager.getMarker("TEST"); + + @Override + public void testSendLogs() { + //TODO: fix me, log sending is currently broken for log4j2 + } + + @Override + protected LoggerFacade createLoggerFacade() { + return new Log4j2LoggerFacade(); + } + + @Override + protected boolean markersSupported() { + return true; + } + + @Override + protected void waitForFileRolling() { + try { + Thread.sleep(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + static class Log4j2LoggerFacade implements LoggerFacade { + + private Logger log4j2Logger; + private URI configLocation; + + public Log4j2LoggerFacade() { + try { + configLocation = Objects.requireNonNull(Log4j2InstrumentationTestDefinitions.class.getClassLoader() + .getResource("log4j2.xml")).toURI(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + } + + @Override + public void open() { + log4j2Logger = LogManager.getLogger("Test-File-Logger"); + assertThat(log4j2Logger).isInstanceOf(org.apache.logging.log4j.core.Logger.class); + + LoggerContext loggerContext = ((org.apache.logging.log4j.core.Logger) log4j2Logger).getContext(); + loggerContext.setConfigLocation(configLocation); + } + + @Override + public void close() { + LogManager.shutdown(); + } + + @Override + public String getLogFilePath() { + assertThat(log4j2Logger) + .isInstanceOf(org.apache.logging.log4j.core.Logger.class); + org.apache.logging.log4j.core.Logger logger = (org.apache.logging.log4j.core.Logger) log4j2Logger; + + assertThat(logger.getAppenders()).containsKey("FILE"); + Appender fileAppender = logger.getAppenders().get("FILE"); + assertThat(fileAppender).isInstanceOf(RandomAccessFileAppender.class); + + return ((RandomAccessFileAppender) fileAppender).getFileName(); + } + + @Override + public void trace(String message) { + log4j2Logger.trace(message); + } + + @Override + public void debug(String message) { + log4j2Logger.debug(message); + } + + @Override + public void debugWithMarker(String message) { + log4j2Logger.debug(TEST_MARKER, message); + } + + @Override + public void warn(String message) { + log4j2Logger.warn(message); + } + + @Override + public void error(String message) { + log4j2Logger.error(message); + } + + @Override + public void error(String message, Throwable throwable) { + log4j2Logger.error(message, throwable); + } + + @Override + public void putTraceIdToMdc(String traceId) { + ThreadContext.put("trace.id", traceId); + } + + @Override + public void removeTraceIdFromMdc() { + ThreadContext.remove("trace.id"); + } + } +} diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java deleted file mode 100644 index 5446b0cb35..0000000000 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package co.elastic.apm.agent.log4j2; - -import co.elastic.apm.agent.logging.LoggingConfigurationImpl; -import co.elastic.apm.agent.testutils.JUnit4TestClassWithDependencyRunner; -import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -import java.io.IOException; -import java.util.List; - -/** - * This class only delegates tests to the current-version log4j2 tests through JUnit 4, so that it can be ran using - * {@link JUnit4TestClassWithDependencyRunner} in a dedicated CL where an older log4j2 version is loaded. - * This is required because the agent is using log4j2 and in tests they retain their original packages (relocation only - * takes place during packaging). - */ -@Ignore -public class Log4j2InstrumentationTestVersions extends Log4j2InstrumentationTest { - - @BeforeClass - public static void resetConfigFactory() { - ConfigurationFactory.resetConfigurationFactory(); - } - - @AfterClass - public static void reInitLogging() { - LoggingConfigurationImpl.init(List.of(), ""); - } - - @Before - @Override - public void setup() throws Exception { - super.setup(); - } - - @After - @Override - public void closeLogger() { - super.closeLogger(); - } - - @Test - @Override - public void testSimpleLogReformatting() throws Exception { - super.testSimpleLogReformatting(); - } - - @Test - @Override - public void testMarkers() throws Exception { - super.testMarkers(); - } - - @Test - @Override - public void testShadingIntoOriginalLogsDir() throws Exception { - super.testShadingIntoOriginalLogsDir(); - } - - @Test - @Override - public void testLazyEcsFileCreation() throws Exception { - super.testLazyEcsFileCreation(); - } - - @Test - @Override - public void testLogReformattingReplaceOriginal() throws IOException { - super.testLogReformattingReplaceOriginal(); - } - - @Test - @Override - public void testDynamicConfiguration() throws Exception { - super.testDynamicConfiguration(); - } - - @Test - @Override - public void testLogOverride() throws IOException { - super.testLogOverride(); - } - - @Test - @Override - public void testEmptyFormatterAllowList() throws Exception { - super.testEmptyFormatterAllowList(); - } - - @Test - @Override - public void testReformattedLogRolling() throws IOException { - super.testReformattedLogRolling(); - } -} diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2LoggerErrorCapturingInstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2LoggerErrorCapturingInstrumentationTest.java similarity index 90% rename from apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2LoggerErrorCapturingInstrumentationTest.java rename to apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2LoggerErrorCapturingInstrumentationTest.java index 08fd54465a..d89d908fb9 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2LoggerErrorCapturingInstrumentationTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2LoggerErrorCapturingInstrumentationTest.java @@ -16,20 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.log4j2.error; +package co.elastic.apm.agent.log4j2; import co.elastic.apm.agent.loginstr.error.AbstractErrorLoggingInstrumentationTest; +import co.elastic.apm.agent.testutils.TestClassWithDependencyRunner; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessageFactory; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; /** * Only tested through dedicated class loaders for latest and oldest-supported versions. - * See {@link Log4j2ErrorCapturingTestVersions} + * See {@link co.elastic.apm.agent.log4j2.Log4j2InstrumentationTest} */ -@Disabled +@TestClassWithDependencyRunner.DisableOutsideOfRunner public class Log4j2LoggerErrorCapturingInstrumentationTest extends AbstractErrorLoggingInstrumentationTest { private static final Logger logger = LogManager.getLogger(Log4j2LoggerErrorCapturingInstrumentationTest.class); diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_17_1InstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_17_1InstrumentationTest.java deleted file mode 100644 index 4f6e009153..0000000000 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_17_1InstrumentationTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package co.elastic.apm.agent.log4j2; - -import co.elastic.apm.agent.testutils.JUnit4TestClassWithDependencyRunner; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnOs; -import org.junit.jupiter.api.condition.OS; - -import java.util.List; - -@DisabledOnOs(OS.WINDOWS) -public class Log4j2_17_1InstrumentationTest { - private final JUnit4TestClassWithDependencyRunner runner; - - public Log4j2_17_1InstrumentationTest() throws Exception { - List dependencies = List.of( - "org.apache.logging.log4j:log4j-core:2.17.1", - "org.apache.logging.log4j:log4j-api:2.17.1", - "co.elastic.logging:log4j2-ecs-layout:1.3.2" - ); - runner = new JUnit4TestClassWithDependencyRunner(dependencies, Log4j2InstrumentationTestVersions.class, Log4j2InstrumentationTest.class, - Log4j2InstrumentationTest.Log4j2LoggerFacade.class); - } - - @Test - public void testVersions() { - runner.run(); - } -} diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_24_0InstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_24_0InstrumentationTest.java deleted file mode 100644 index 02741ef1cb..0000000000 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_24_0InstrumentationTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package co.elastic.apm.agent.log4j2; - -import co.elastic.apm.agent.testutils.JUnit4TestClassWithDependencyRunner; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnOs; -import org.junit.jupiter.api.condition.OS; - -import java.util.List; - -@DisabledOnOs(OS.WINDOWS) -public class Log4j2_24_0InstrumentationTest { - private final JUnit4TestClassWithDependencyRunner runner; - - public Log4j2_24_0InstrumentationTest() throws Exception { - List dependencies = List.of( - "org.apache.logging.log4j:log4j-core:2.24.0", - "org.apache.logging.log4j:log4j-api:2.24.0", - "co.elastic.logging:log4j2-ecs-layout:1.3.2" - ); - runner = new JUnit4TestClassWithDependencyRunner(dependencies, Log4j2InstrumentationTestVersions.class, Log4j2InstrumentationTest.class, - Log4j2InstrumentationTest.Log4j2LoggerFacade.class); - } - - @Test - public void testVersions() { - runner.run(); - } -} diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_6SInstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_6SInstrumentationTest.java deleted file mode 100644 index cfb8bf7df6..0000000000 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2_6SInstrumentationTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package co.elastic.apm.agent.log4j2; - -import co.elastic.apm.agent.testutils.JUnit4TestClassWithDependencyRunner; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnOs; -import org.junit.jupiter.api.condition.OS; - -import java.util.List; - -@DisabledOnOs(OS.WINDOWS) -public class Log4j2_6SInstrumentationTest { - private final JUnit4TestClassWithDependencyRunner runner; - - public Log4j2_6SInstrumentationTest() throws Exception { - List dependencies = List.of( - "org.apache.logging.log4j:log4j-core:2.6", - "org.apache.logging.log4j:log4j-api:2.6", - "co.elastic.logging:log4j2-ecs-layout:1.3.2" - ); - runner = new JUnit4TestClassWithDependencyRunner(dependencies, Log4j2InstrumentationTestVersions.class, Log4j2InstrumentationTest.class, - Log4j2InstrumentationTest.Log4j2LoggerFacade.class); - } - - @Test - public void testVersions() { - runner.run(); - } -} diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2ErrorCapturingTestVersions.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2ErrorCapturingTestVersions.java deleted file mode 100644 index 3c1aa79b0a..0000000000 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2ErrorCapturingTestVersions.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package co.elastic.apm.agent.log4j2.error; - -import co.elastic.apm.agent.testutils.JUnit4TestClassWithDependencyRunner; -import org.junit.Ignore; -import org.junit.Test; - -/** - * This class only delegates tests to the current-version log4j2 tests through JUnit 4, so that it can be ran using - * {@link JUnit4TestClassWithDependencyRunner} in a dedicated CL where an older log4j2 version is loaded. - * This is required because the agent is using log4j2 and in tests they retain their original packages (relocation only - * takes place during packaging). - */ -@Ignore -public class Log4j2ErrorCapturingTestVersions extends Log4j2LoggerErrorCapturingInstrumentationTest { - - @Test - @Override - public void captureErrorExceptionWithStringMessage() { - super.captureErrorExceptionWithStringMessage(); - } - - @Test - @Override - public void captureErrorExceptionWithMessageMessage() { - super.captureErrorExceptionWithMessageMessage(); - } - - @Test - @Override - public void captureFatalException() { - super.captureFatalException(); - } -} diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2_17_1ErrorCapturingTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2_17_1ErrorCapturingTest.java deleted file mode 100644 index 06415b3b49..0000000000 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/error/Log4j2_17_1ErrorCapturingTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package co.elastic.apm.agent.log4j2.error; - -import co.elastic.apm.agent.testutils.JUnit4TestClassWithDependencyRunner; -import org.junit.jupiter.api.Test; - -import java.util.List; - -public class Log4j2_17_1ErrorCapturingTest { - private final JUnit4TestClassWithDependencyRunner runner; - - public Log4j2_17_1ErrorCapturingTest() throws Exception { - List dependencies = List.of( - "org.apache.logging.log4j:log4j-core:2.17.1", - "org.apache.logging.log4j:log4j-api:2.17.1" - ); - runner = new JUnit4TestClassWithDependencyRunner(dependencies, Log4j2ErrorCapturingTestVersions.class, - Log4j2LoggerErrorCapturingInstrumentationTest.class); - } - - @Test - public void testVersions() { - runner.run(); - } -} From df3a503e06c005e2c42570d3b2ddde3367a0c4d0 Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Tue, 17 Sep 2024 13:14:42 +0200 Subject: [PATCH 5/5] Fix error capturing test for 2.6 --- .../co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java | 3 +-- .../log4j2/Log4j2LoggerErrorCapturingInstrumentationTest.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java index a4855da304..3a4c05ce6b 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java @@ -42,9 +42,8 @@ public void testInstrumentation(String version) throws Exception { .run(); } - //TODO: Error capturing is currently broken on 2.6 @ParameterizedTest - @ValueSource(strings = {/*"2.6",*/ "2.17.1", "2.24.0"}) + @ValueSource(strings = {"2.6", "2.17.1", "2.24.0"}) public void testErrorCapture(String version) throws Exception { List dependencies = List.of( "org.apache.logging.log4j:log4j-core:" + version, diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2LoggerErrorCapturingInstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2LoggerErrorCapturingInstrumentationTest.java index d89d908fb9..19e05d94ad 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2LoggerErrorCapturingInstrumentationTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin-tests/src/test/java/co/elastic/apm/agent/log4j2/Log4j2LoggerErrorCapturingInstrumentationTest.java @@ -42,7 +42,7 @@ void captureErrorExceptionWithStringMessage() { @Test void captureErrorExceptionWithMessageMessage() { - logger.error(ParameterizedMessageFactory.INSTANCE.newMessage("exception captured with parameter {}", "foo"), new RuntimeException("some business exception")); + logger.error(ParameterizedMessageFactory.INSTANCE.newMessage("exception captured with parameter {}", new Object[]{"foo"}), new RuntimeException("some business exception")); verifyExceptionCaptured("some business exception", RuntimeException.class); }