javaspringlogbackgrayloggelf

Cannot get GELF Appender to add Sleuth Span Id


I am trying to get the Sleuth Span-Id and Trace-Id included as additonalFields in my logback-sping.xml GELF appeneder but am having no luck. They show up fine in the actual log file output in the Console, but in Graylog they don't show up. NOTE : the profile works just fine.

<property name="CONSOLE_LOG_PATTERN" value="%date{ISO8601} [${springProfile}] [${springAppName:-},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}] [%level] [${PID}] [%X{bindName}] [%thread] [%logger{10}] : %msg%n %ex{20}"/>


<springProfile name="integration,qa,prod">
    <appender name="GELF" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
        <graylogHost>${graylogProtocol}:${graylogHost}</graylogHost>
        <graylogPort>${graylogPort}</graylogPort>
        <facility>${springAppName}</facility>
        <additionalFields>profile=${springProfile},traceid=%X{X-B3-TraceId:-},spanid=%X{X-B3-SpanId:-}</additionalFields>
        <extractStackTrace>true</extractStackTrace>
        <filterStackTrace>true</filterStackTrace>
        <maximumMessageSize>8192</maximumMessageSize>
        <timestampPattern>yyyy-MM-dd HH:mm:ss,SSSS</timestampPattern>
    </appender>
</springProfile>

Also tried this:

        <additionalFields>profile=${springProfile},traceid=${X-B3-TraceId},spanid=${X-B3-SpanId}</additionalFields>

No luck.


Solution

  • Additional fields are static. They might get pre-processed by applying system properties but don't extract values from the MDC (%X).

    Use mdcFields for this purpose:

    <mdcFields>X-B3-TraceId,X-B3-SpanId</mdcFields>
    

    mdcFields does not support field naming of included MDC fields (e.g. traceid=X-B3-TraceId does not work).

    Documentation: http://logging.paluch.biz/examples/logback.html