Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This file contains all changes which are not released yet.

# Fixes
<!--FIXES-START-->
* Fix `NoSuchMethodError` in Log4j 2.7 log correlation, which called `ThreadContext.removeAll` that is only available since Log4j 2.8 - [#4593](https://github.com/elastic/apm-agent-java/issues/4593)

<!--FIXES-END-->
# Features and enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class Log4j2InstrumentationTest {

@ParameterizedTest
@ValueSource(strings = {"2.6", "2.17.1", "2.24.0"})
@ValueSource(strings = {"2.6", "2.7", "2.17.1", "2.24.0"})
public void testInstrumentation(String version) throws Exception {
List<String> dependencies = List.of(
"org.apache.logging.log4j:log4j-core:" + version,
Expand All @@ -43,7 +43,7 @@ public void testInstrumentation(String version) throws Exception {
}

@ParameterizedTest
@ValueSource(strings = {"2.6", "2.17.1", "2.24.0"})
@ValueSource(strings = {"2.6", "2.7", "2.17.1", "2.24.0"})
public void testErrorCapture(String version) throws Exception {
List<String> dependencies = List.of(
"org.apache.logging.log4j:log4j-core:" + version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import java.util.Map;

/**
* Using {@link ThreadContext#putAll(Map)} that is available since 2.7 for improved efficiency
* Using {@link ThreadContext#putAll(Map)} that is available since 2.7 for improved efficiency.
* Keys are removed one by one, as {@link ThreadContext#removeAll(Iterable)} is only available since 2.8.
*/
public class Log4j2_7PlusLogCorrelationHelper extends AbstractLogCorrelationHelper {

Expand All @@ -44,6 +45,8 @@ protected boolean addToMdc() {

@Override
protected void removeFromMdc() {
ThreadContext.removeAll(CorrelationIdMapAdapter.allKeys());
for (String key : CorrelationIdMapAdapter.allKeys()) {
ThreadContext.remove(key);
}
}
}
Loading