Support excluding MDC attributes from capture-all#18912
Conversation
When capturing all MDC/context-data attributes with the `*` wildcard in the jboss-logmanager, log4j (1.2 and 2.17), and logback log appenders, attributes can now be excluded by prefixing them with `!`. For example, `*,!foo` captures all MDC attributes except `foo`.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for excluding specific MDC/context-data keys when wildcard capture (*) is enabled across multiple logging appenders/instrumentations.
Changes:
- Implement exclusion syntax (
!key) when wildcard capture is enabled in Logback / Log4j / JBoss Log Manager mappers. - Add unit tests for exclusion behavior in Logback and Log4j 2.17.
- Update metadata and READMEs to document
*,!fooconfiguration.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation/logback/logback-appender-1.0/metadata.yaml | Documents !key exclusions alongside * wildcard capture. |
| instrumentation/logback/logback-appender-1.0/library/src/test/java/io/opentelemetry/instrumentation/logback/appender/v1_0/internal/LoggingEventMapperTest.java | Adds test coverage for wildcard capture with exclusions. |
| instrumentation/logback/logback-appender-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/appender/v1_0/internal/LoggingEventMapper.java | Implements exclusion set for MDC capture when using *. |
| instrumentation/logback/logback-appender-1.0/javaagent/README.md | Documents *,!foo exclusion syntax for MDC capture. |
| instrumentation/log4j/log4j-appender-2.17/metadata.yaml | Documents !key exclusions alongside * wildcard capture. |
| instrumentation/log4j/log4j-appender-2.17/library/src/test/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/internal/LogEventMapperTest.java | Adds test coverage for wildcard capture with exclusions. |
| instrumentation/log4j/log4j-appender-2.17/library/src/main/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/internal/LogEventMapper.java | Implements exclusion set for context data capture when using *. |
| instrumentation/log4j/log4j-appender-2.17/library/README.md | Documents *,!foo exclusion syntax for context data capture. |
| instrumentation/log4j/log4j-appender-2.17/javaagent/README.md | Documents *,!foo exclusion syntax for context data capture. |
| instrumentation/log4j/log4j-appender-1.2/metadata.yaml | Documents !key exclusions alongside * wildcard capture. |
| instrumentation/log4j/log4j-appender-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/appender/v1_2/LogEventMapper.java | Implements exclusion set for MDC capture when using *. |
| instrumentation/log4j/log4j-appender-1.2/javaagent/README.md | Documents *,!foo exclusion syntax for MDC capture. |
| instrumentation/jboss-logmanager/jboss-logmanager-appender-1.1/metadata.yaml | Documents !key exclusions alongside * wildcard capture. |
| instrumentation/jboss-logmanager/jboss-logmanager-appender-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jbosslogmanager/appender/v1_1/LoggingEventMapper.java | Implements exclusion set for MDC capture when using *. |
| instrumentation/jboss-logmanager/README.md | Documents *,!foo exclusion syntax for MDC capture. |
| docs/instrumentation-list.yaml | Propagates exclusion syntax into generated instrumentation docs. |
Comments suppressed due to low confidence (1)
instrumentation/logback/logback-appender-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/appender/v1_0/internal/LoggingEventMapper.java:1
- When
*is not present, entries like"!key2"are currently treated as a literal attribute key (because only"*"is filtered out). Since docs define!keyas meaningful only with*, it would be better to ignore!…entries (or fail fast / warn) in the non-wildcard branch to avoid silently doing something unexpected.
/*
|
Is there prior art for this in otel ecosystem? There is a moratorium in otel spec for introducing new environment variables with complex encoding. The moratorium was originally in place to incentivize development of declarative config, which is done now. While we are not strictly bound by this moratorium the question is still whether there could be a better solution for this that does not involve complex encodings. Perhaps some sort of include/exclude pair would work better? |
|
I'm happy to refactor if needed. Let me know your concrete suggestions. (e.g. new option names, and what to do with the existing option names) |
…for MDC capture Replace the !-prefix exclusion syntax with a dedicated exclude-mdc-attributes property and reuse the OpenTelemetry SDK's IncludeExcludePredicate (glob matching) across the jboss-logmanager, log4j (1.2 and 2.17), and logback appenders. - capture-mdc-attributes is the include list; exclude-mdc-attributes is the new exclude list; both support glob wildcards (* and ?) - empty includes captures nothing (preserving the default); excludes only take effect alongside a non-empty include list - wire the new property through the javaagent config, the standalone library appenders, and the Spring Boot starter (non-agent path)
|
I've updated the code to have both include and exclude properties as suggested. The existing The instrumentations now use |
Problem
I need the ability to exclude specific attributes when capturing MDC/context-data. Previously, the logging instrumentations supported including all attributes (e.g.
*) or specific attributes (e.g.foo,bar). But there was no way to say "include everything except x). This PR adds that capability.Closes #14925
Change Summary
Added the ability to exclude specific attributes when capturing all MDC/context-data attributes with the
*wildcard, across the jboss-logmanager, log4j 1.2, log4j 2.17, and logback log appenders. Prefix an attribute name with!to exclude it.Behavior
*check changed from "list is exactly[*]" to "list contains*", so*can be combined with!-prefixed exclusions.otel.event.nameremains special-cased (mapped to the log event name, never emitted as an attribute).Changes by area
Mappers (core logic. identical small change in each)
LogEventMapper.javaLogEventMapper.java(context data)LoggingEventMapper.javaLoggingEventMapper.javaEach parses
!-prefixed entries into an exclusionSet<String>and skips those keys when iterating the MDC map.Tests
testAllWithExclusionadded to the two library modules with directly testable mappers (log4j 2.17 and logback).Documentation
metadata.yamldescriptions + a*,!fooexample.README.mdsettings tables (realigned to the repo's table style).