Repository navigation
Fix NoSuchMethodError in Log4j 2.7 log correlation - #4600
Open
Anshuman-Prakash wants to merge 1 commit into
Open
Anshuman-Prakash wants to merge 1 commit into
Anshuman-Prakash wants to merge 1 commit into
Conversation
ThreadContext.removeAll(Iterable) is only available since Log4j 2.8, but Log4j2_7PlusLogCorrelationHelper is selected for log4j-core >= 2.7. Remove the correlation keys one by one with ThreadContext.remove(String) instead, and run the log4j2 instrumentation tests against 2.7 as well. Fixes elastic#4593 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🤖 GitHub commentsJust comment with:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #4593
Log4J2_7PlusLogCorrelationInstrumentationis selected forlog4j-core>= 2.7, but its helper cleaned up the correlation IDs withThreadContext.removeAll(Iterable), which Log4j only added in 2.8. On 2.7 every logging event during a transaction therefore threwNoSuchMethodErrorfrom the advice. Because the advice suppresses it, the correlation keys were never removed, so a staleerror.idleaked onto later log lines.Log4j2_7PlusLogCorrelationHelper.removeFromMdc()now removes the keys one by one withThreadContext.remove(String), as the 2.6 helper already does.putAll(Map)(available since 2.7) is still used to add them.Log4j2InstrumentationTestnow also runs the instrumentation and error-capture definitions against Log4j2.7, next to2.6,2.17.1and2.24.0.Tests
Run in
maven:3.9-eclipse-temurin-17(Linux):Tests run: 8, Failures: 1.testInstrumentation[2](2.7) fails inverifyErrorCaptureAndCorrelationwithexpected: null but was: "16e9e1523a…"(a leakederror.id), and the log shows theNoSuchMethodError: ThreadContext.removeAll(java.lang.Iterable)from the issue.Tests run: 8, Failures: 0, Errors: 0, and there is noNoSuchMethodErrorin the output.Checklist
This is an enhancement of existing features, or a new feature in existing pluginsThis is a new pluginThis is something else🤖 Generated with Claude Code