Log4j
OpenTelemetry Java agent instrumentation
This instrumentation bridges Log4j log events to OpenTelemetry logs.
- Name:
log4j-appender-2.17 - Scope:
io.opentelemetry.log4j-appender-2.17 - Target versions:
org.apache.logging.log4j:log4j-core:[2.0,) - Library: https://logging.apache.org/log4j/2.x/
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
otel.instrumentation.common.logging.span-id | string | span_id | Deprecated: use otel.instrumentation.common.logging.span-id-key instead. It is ignored under v3 preview and will be removed in 3.0. |
otel.instrumentation.common.logging.span-id-key | string | span_id | Specifies the key name used to store the span ID in the logging context. |
otel.instrumentation.common.logging.trace-flags | string | trace_flags | Deprecated: use otel.instrumentation.common.logging.trace-flags-key instead. It is ignored under v3 preview and will be removed in 3.0. |
otel.instrumentation.common.logging.trace-flags-key | string | trace_flags | Specifies the key name used to store the trace flags in the logging context. |
otel.instrumentation.common.logging.trace-id | string | trace_id | Deprecated: use otel.instrumentation.common.logging.trace-id-key instead. It is ignored under v3 preview and will be removed in 3.0. |
otel.instrumentation.common.logging.trace-id-key | string | trace_id | Specifies the key name used to store the trace ID in the logging context. |
otel.instrumentation.common.logging.structured-attributes.excluded | list | Comma-separated list of case-sensitive glob patterns for event-local structured log attribute keys not to capture. Applies to Log4j MapMessage entries, SLF4J key-value pairs, Logback Logstash markers, and Logstash structured arguments. Excluded patterns take precedence over included patterns. An exclude-only selector captures every key not excluded; "*" captures no structured attributes. This does not affect otel.event.name, MDC, or logger context. | |
otel.instrumentation.common.logging.structured-attributes.included | list | Comma-separated list of case-sensitive glob patterns for event-local structured log attribute keys to capture. Applies to Log4j MapMessage entries, SLF4J key-value pairs, Logback Logstash markers, and Logstash structured arguments. "*" matches any number of characters and "?" matches one character. Excluded patterns take precedence. An exclude-only selector captures every key not excluded. Under v3-preview, an absent or empty selector captures all structured attributes by default. MDC and logger-context attributes remain separate and opt-in. | |
otel.instrumentation.log4j-appender.experimental-log-attributes | boolean | false | Enables the capture of experimental log attributes, including thread name and thread ID. |
otel.instrumentation.log4j-appender.experimental.capture-arguments | boolean | false | Enables the capture of the log message arguments. |
otel.instrumentation.log4j-appender.experimental.capture-code-attributes | boolean | false | Enables the capture of code location attributes, including file path, class name, method name, and line number. |
otel.instrumentation.log4j-appender.experimental.capture-map-message-attributes | boolean | false | Deprecated; use otel.instrumentation.common.logging.structured-attributes.included instead. This setting is ignored under v3-preview and will be removed in 3.0. Outside v3-preview, true captures all MapMessage attributes and false captures none. It is ignored when a source-specific included or excluded pattern is configured. |
otel.instrumentation.log4j-appender.experimental.capture-marker-attribute | boolean | false | Enables the capture of the Log4j marker attribute. |
otel.instrumentation.log4j-appender.experimental.capture-mdc-attributes | list | Deprecated include-only alias for otel.instrumentation.log4j-appender.experimental.mdc-attributes.included. It does not support glob patterns: a list containing only "*" captures all context data attributes, and otherwise every entry, including one containing "*" or "?", is matched as a literal context data key. It is ignored when an included or excluded pattern is configured, and it may be removed in the next minor release. | |
otel.instrumentation.log4j-appender.experimental.capture-template | boolean | false | Enables the capture of the log message template (if arguments are provided). |
otel.instrumentation.log4j-appender.experimental.map-message-attributes.excluded | list | Deprecated; use otel.instrumentation.common.logging.structured-attributes.excluded instead. This setting is ignored under v3-preview and will be removed in 3.0. Comma-separated list of case-sensitive glob patterns for MapMessage keys not to capture as log attributes. "*" matches any number of characters and "?" matches one character. Excluded patterns take precedence over included patterns. No MapMessage attributes are captured unless an included pattern, an excluded pattern, or the deprecated otel.instrumentation.log4j-appender.experimental.capture-map-message-attributes setting is configured; configuring only excluded patterns captures all MapMessage attributes that do not match them. Captured MapMessage attributes may contain sensitive information. | |
otel.instrumentation.log4j-appender.experimental.map-message-attributes.included | list | Deprecated; use otel.instrumentation.common.logging.structured-attributes.included instead. This setting is ignored under v3-preview and will be removed in 3.0. Comma-separated list of case-sensitive glob patterns for MapMessage keys to capture as log attributes. "*" matches any number of characters and "?" matches one character. Excluded patterns take precedence over included patterns. No MapMessage attributes are captured unless an included pattern, an excluded pattern, or the deprecated otel.instrumentation.log4j-appender.experimental.capture-map-message-attributes setting is configured; configuring only excluded patterns captures all MapMessage attributes that do not match them. Captured MapMessage attributes may contain sensitive information. | |
otel.instrumentation.log4j-appender.experimental.mdc-attributes.excluded | list | Comma-separated list of case-sensitive glob patterns for context data keys not to capture as log attributes. "*" matches any number of characters and "?" matches one character. Excluded patterns take precedence over included patterns. No context data attributes are captured unless an included pattern, an excluded pattern, or the deprecated otel.instrumentation.log4j-appender.experimental.capture-mdc-attributes setting is configured; configuring only excluded patterns captures all context data attributes that do not match them. Captured context data attributes may contain sensitive information. | |
otel.instrumentation.log4j-appender.experimental.mdc-attributes.included | list | Comma-separated list of case-sensitive glob patterns for context data keys to capture as log attributes. "*" matches any number of characters and "?" matches one character. Excluded patterns take precedence over included patterns. No context data attributes are captured unless an included pattern, an excluded pattern, or the deprecated otel.instrumentation.log4j-appender.experimental.capture-mdc-attributes setting is configured; configuring only excluded patterns captures all context data attributes that do not match them. Captured context data attributes may contain sensitive information. |