Skip to content

Use mdc-attributes.included instead of deprecated capture-mdc-attributes - #4893

Merged
xiang17 merged 2 commits into
mainfrom
fix/mdc-attributes-deprecation
Nov 12, 2026
Merged

xiang17 merged 2 commits into
mainfrom
fix/mdc-attributes-deprecation

Conversation

@rajkumar-rangaraj

Copy link
Copy Markdown
Member

Fix #4890 .

Since OpenTelemetry Java Instrumentation 2.31, the logback, log4j and jboss-logmanager appenders resolve MDC capture through SelectorConfig, which logs a deprecation warning when the old *.experimental.capture-mdc-attributes property is used. AiConfigCustomizer sets those properties itself, so every agent startup logged the warning and users couldn't suppress it.

Changes:

  • Replace otel.instrumentation.{logback-appender,log4j-appender,jboss-logmanager}.experimental.capture-mdc-attributes=* with the corresponding ...experimental.mdc-attributes.included=*. With the new glob semantics, * still captures all MDC/context data attributes, so captured telemetry is unchanged.
  • Remove otel.instrumentation.log4j-appender.experimental.capture-context-data-attributes, which is no longer read upstream (log4j context data is covered by log4j-appender.experimental.mdc-attributes).

Not changed here: the agent also sets otel.instrumentation.log4j-appender.experimental.capture-map-message-attributes=true, which logs a similar deprecation warning. Its replacement (otel.instrumentation.common.logging.structured-attributes.included) is a common setting that would also enable SLF4J key-value pair and Logstash marker capture for logback, which changes behavior, so it should be handled separately.

Validation:

  • ./gradlew :smoke-tests:apps:Log4j2:smokeTest --tests "*Log4j2Test$Tomcat8Java8Test": passed (2 tests; asserts MDC key is captured, and the container output no longer has the capture-mdc-attributes warning)
  • ./gradlew :smoke-tests:apps:Logback:smokeTest --tests "*LogbackTest$Tomcat8Java8Test": passed (2 tests; asserts MDC key is captured, and no SelectorConfig warning in the output)

For significant contributions please make sure you have completed the following items:

Avoids the SelectorConfig deprecation warning logged at every startup since
OpenTelemetry Java Instrumentation 2.31. Also removes the log4j
capture-context-data-attributes property which is no longer read upstream.

Fixes #4890

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the MDC capture configuration update.

No open issues 🎉

What changed in this PR

Updates the agent’s MDC capture configuration to remove startup deprecation warnings introduced by OpenTelemetry instrumentation 2.31, addressing #4890 while preserving capture of all MDC attributes.

Changes:

  • Uses mdc-attributes.included=* for Logback, Log4j, and JBoss LogManager.
  • Removes the obsolete Log4j context-data capture property.
  • Documents the fix in the changelog; leaves map-message capture unchanged.
File Description
CHANGELOG.md Records the startup deprecation warning fix.
agent/​agent-tooling/​src/​main/​java/​com/​microsoft/​applicationinsights/​agent/​internal/​init/​AiConfigCustomizer.java Replaces deprecated MDC settings and removes the obsolete Log4j property.

Review effort: Balanced

@xiang17
xiang17 merged commit d8efbc8 into main Nov 12, 2026
147 checks passed
@xiang17
xiang17 deleted the fix/mdc-attributes-deprecation branch November 12, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecation warning at startup: capture-mdc-attributes is set by the agent itself (OTel 2.31+)

3 participants