You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add opt-in text log pattern injection for Logback and Log4j - #21261
Add opt-in correlation fields to existing Logback and Log4j text patterns so console and file logs can be correlated without editing each application's logging configuration.
Disabled by default. Supports Logback classic 1.0+, Log4j 1.2, and Log4j2 2.7+. Reuses existing MDC converters and configured trace/span key names, preserves timestamp options and repeated layout initialization, and exposes the resource's service.name outside a span. Application-provided correlation values take precedence. JSON layouts and Log4j2 PatternSelector branches are excluded.
Validated the parser and baseline/latest-dependency check tasks for all five logging modules on JDK 25, including focused parser and Logback checks for native default-key semantics. On Java 8, 102 installed-agent tests pass; six cases requiring newer Logback color converters are skipped. Regression coverage includes whole-line wrappers, literal braces in Logback composites, version-specific MDC defaults, native escaped keys, special correlation keys, key lists and wrapper aliases, repeated initialization, and original-MDC export with pattern injection enabled.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Log-pattern handling can place Log4j2 correlation fields on the wrong line, omit Logback trace IDs for comma-containing keys, and duplicate correlation fields inside Log4j2 color wrappers.
Adds opt-in text log correlation to the Java agent’s existing Logback and Log4j instrumentation, addressing #21260 without requiring application logging-pattern changes.
Changes:
Adds a shared pattern rewriter and framework-specific layout instrumentation, disabled by default.
Exposes service.name outside spans and preserves application-provided correlation values.
Adds parser and installed-agent tests, configuration metadata, and usage documentation.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Logback MDC keys containing commas and both quote characters are quoted without escaping embedded delimiters, preventing correlation-value lookup and duplicating fields on repeated initialization.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Configured trace/span keys are inserted verbatim into Log4j labels and MDC options, allowing percent signs to split log records and commas to cause trace IDs to disappear.
[Javaagent] Passing the configured key verbatim is unsafe for Log4j2 MDC options. A trace key such as custom,trace becomes %X{custom,trace}, which selects two MDC entries rather than the single custom,trace entry populated by the instrumentation; the trace ID therefore disappears from the injected output. Add a safe option/key-resolution mechanism for Log4j2, analogous to the Logback alias handling, and exercise a comma-containing key in the installed-agent rendering tests.
Escape percent signs in Log4j labels for custom trace keys
[Javaagent] A configured trace/span key containing %, such as trace%n, is copied verbatim into the Log4j label, where %n becomes an extra newline and splits the log record. Escape literal percent signs as %% in Log4j labels while retaining the original key inside the MDC option. Add a rendering regression test for these custom keys.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because framework-specific parsing, escaping, and wrapper handling can omit correlation fields or break log-record boundaries.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Pattern parsing can place correlation fields after newlines and misidentify Logback MDC keys, producing malformed log output and missing or duplicate trace IDs.
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
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.
Add opt-in correlation fields to existing Logback and Log4j text patterns so console and file logs can be correlated without editing each application's logging configuration.
otel.instrumentation.logging.pattern-injection.enabled=trueDisabled by default. Supports Logback classic 1.0+, Log4j 1.2, and Log4j2 2.7+. Reuses existing MDC converters and configured trace/span key names, preserves timestamp options and repeated layout initialization, and exposes the resource's
service.nameoutside a span. Application-provided correlation values take precedence. JSON layouts and Log4j2 PatternSelector branches are excluded.Closes #21260.
Validated the parser and baseline/latest-dependency
checktasks for all five logging modules on JDK 25, including focused parser and Logback checks for native default-key semantics. On Java 8, 102 installed-agent tests pass; six cases requiring newer Logback color converters are skipped. Regression coverage includes whole-line wrappers, literal braces in Logback composites, version-specific MDC defaults, native escaped keys, special correlation keys, key lists and wrapper aliases, repeated initialization, and original-MDC export with pattern injection enabled.