If I use the new slf4j2 fluent API to created structured logs with key value pairs:
logger.atInfo().setMessage("A slf4j structured message").addKeyValue("key", "value").log()
And configure the logback mdc appender to wrap the console logger and include trace context:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %kvp{DOUBLE} - trace_id=%X{trace_id} span_id=%X{span_id} trace_flags=%X{trace_flags}%n
</pattern>
</encoder>
</appender>
<appender name="OpenTelemetryConsole" class="io.opentelemetry.instrumentation.logback.mdc.v1_0.OpenTelemetryAppender">
<appender-ref ref="console"/>
</appender>
<root level="INFO">
<appender-ref ref="OpenTelemetryConsole"/>
</root>
</configuration>
I get the following error:
Exception in thread "main" java.lang.AbstractMethodError: Receiver class io.opentelemetry.instrumentation.logback.mdc.v1_0.LoggingEventWrapper does not define or inherit an implementation of the resolved method 'abstract java.util.List getKeyValuePairs()' of interface ch.qos.logback.classic.spi.ILoggingEvent.
at ch.qos.logback.classic.pattern.KeyValuePairConverter.convert(KeyValuePairConverter.java:67)
at ch.qos.logback.classic.pattern.KeyValuePairConverter.convert(KeyValuePairConverter.java:21)
at ch.qos.logback.core.pattern.FormattingConverter.write(FormattingConverter.java:36)
at ch.qos.logback.core.pattern.PatternLayoutBase.writeLoopOnConverters(PatternLayoutBase.java:116)
at ch.qos.logback.classic.PatternLayout.doLayout(PatternLayout.java:176)
at ch.qos.logback.classic.PatternLayout.doLayout(PatternLayout.java:39)
Haven't had time to study the problem, but I think we need to update the MDC appender to implement some additional API surface area.
If I use the new slf4j2 fluent API to created structured logs with key value pairs:
And configure the logback mdc appender to wrap the console logger and include trace context:
I get the following error:
Haven't had time to study the problem, but I think we need to update the MDC appender to implement some additional API surface area.