Skip to content

Capture Logback KeyValuePairs #8059

@jack-berg

Description

@jack-berg

If I use the SLF4J 2.0.0 fluent API to do structured logging as follows:

            slf4jLogger
                .atInfo()
                .setMessage("A slf4j structured message")
                .addKeyValue("key", "value")
                .log()

I expect the key value pairs I add via addKeyValue(...) to be included in OpenTelemetry LogRecords when I use the logback appender.

Key value pairs are currently dropped. This appears to happen because the logback appender supports logback v1+, and a new API ILoggingEvent#getKeyValuePairs was added in logback v1.3.

We should add support to the logback appender to capture keyvalue pairs.

Note, this isn't a problem if using log4j2 as an implementation of slf4j2 via log4j-slf4j2-impl. Slf4j2 key value pairs are captured in log4j2 context data, which is accessed via LogEvent#getContextData(). There's already a property in the log4j2 appender config to capture context data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions