Log4j 2.7 log correlation calls ThreadContext.removeAll, which was introduced in 2.8
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- java
調査の方向性
Start with Log4j2_7PlusLogCorrelationHelper.removeFromMdc in the apm-log4j2-plugin, which calls ThreadContext.removeAll, and with the version check in Log4j2LogCorrelationInstrumentation that selects log4j-core 2.7 and above. Decide whether to replace the call with per-key ThreadContext.remove for 2.7 or gate the instrumentation, then check that the reproduction no longer throws NoSuchMethodError. Done means a regression test passes for both 2.7 and 2.8+, including cleanup after logging and thread reuse.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
Elastic APM Java agent 1.57.0 emits repeated NoSuchMethodError messages when log correlation is used with Log4j 2.7:
ERROR co.elastic.apm.agent.bci.IndyBootstrap - Advice threw an exception, this should never happen!
java.lang.NoSuchMethodError: org.apache.logging.log4j.ThreadContext.removeAll(Ljava/lang/Iterable;)V
at co.elastic.apm.agent.log4j2.correlation.Log4j2_7PlusLogCorrelationHelper.removeFromMdc(Log4j2_7PlusLogCorrelationHelper.java:47)
at co.elastic.apm.agent.loginstr.correlation.AbstractLogCorrelationHelper.afterLoggingEvent(AbstractLogCorrelationHelper.java:54)
The application continues running, but ordinary logging during traced requests repeatedly triggers the error. This is not limited to startup.
Relevant versions: Java 8; log4j-api and log4j-core both 2.7; Elastic APM Java agent 1.57.0.
Steps to reproduce
Suggested minimal reproduction, derived from the observed error and source analysis (not yet independently executed as a standalone test):
- Use matching
org.apache.logging.log4j:log4j-api:2.7andorg.apache.logging.log4j:log4j-core:2.7dependencies. - Start with agent 1.57.0, leaving
log-correlationinstrumentation enabled. - Emit an enabled log event while an APM transaction is active, for example:
Transaction transaction = ElasticApm.startTransaction();
try (Scope scope = transaction.activate()) {
LogManager.getLogger("example").info("correlation test");
} finally {
transaction.end();
}
Here ElasticApm, Transaction, and Scope are from co.elastic.apm.api, and LogManager is from org.apache.logging.log4j.
Expected behavior
Log correlation should avoid invoking an API absent from the selected Log4j version. If Log4j 2.7 is supported, correlation IDs should be added and cleaned up without an exception. Otherwise the incompatible instrumentation should not be selected for 2.7.
Source analysis
The same version/API mismatch is present in main at commit 5cabf9ceeaea99f7a811b896064bf7aa8b131e5d (source inspected; that commit was not runtime-tested):
Log4J2_7PlusLogCorrelationInstrumentationselectslog4j-coreversions greater than or equal to 2.7.Log4j2_7PlusLogCorrelationHelper.removeFromMdcunconditionally callsThreadContext.removeAll(...).- The Log4j API documentation marks
removeAll(Iterable<String>)as introduced in 2.8, whereasputAll(Map)was introduced in 2.7.
A possible fix is a compatible per-key ThreadContext.remove(String) cleanup for 2.7, or a separate version/capability-gated implementation. A regression test should cover 2.7 specifically, as well as 2.8+, including cleanup after logging and thread reuse.
This differs from #3745 / #3764: those address version detection in shaded JARs; here the application actually uses Log4j 2.7 and lacks the invoked API.
Workaround
Upgrade the application's matching Log4j dependencies to a compatible maintained version, or disable log-correlation temporarily, accepting the loss of automatic logging correlation.
- 主要言語
- Java
- スター
- 593
- フォーク
- 338
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 13
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
elastic/apm-agent-java のほかの issue
-
agent-java community triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
elastic/apm-agent-java#4594 ·
メンテナーはふだん 1 日以内に返信
-
agent-java
難易度 2/5 1〜2日 初心者へのやさしさ 62/100
elastic/apm-agent-java#2844 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Improve docs and add error log related to illegal activation of transaction対応中かも @AzazelSensei が 37 日前に担当しました。 オープンdocs good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
elastic/apm-agent-java#850 · コメント 4 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
agent-java community triage
elastic/apm-agent-java#4573 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
agent-java
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
elastic/apm-agent-java#4549 ·
メンテナーはふだん 1 日以内に返信
elastic/apm-agent-java の issue をすべて見る
似ている issue
-
approved bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
checkstyle/checkstyle#21981 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
beehive-lab/TornadoVM#1248 ·
メンテナーはふだん 1 日以内に返信
-
bug jdbc-v2
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ClickHouse/clickhouse-java#3214 ·
メンテナーはふだん 1 日以内に返信
-
Java and Kotlin (JVM): parse gradle/wrapper/gradle-wrapper.properties with exact line locationsオープンarea: detector eco: java help wanted lane: free-agent roadmap size: S type: parser
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
arminazimi/evergreen#355 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
micronaut-projects/micronaut-data#4134 ·
メンテナーはふだん 1 日以内に返信