Documentation forSolarWinds Observability

Java trace context in logs

When you add trace context to application logs, you can correlate the log messages from a single transaction, and if sampled, the log messages to the transaction trace detail.

The SolarWinds Observability Java Library uses the standard OpenTelemetry Java Library to inject trace context into logs managed by several popular Java logging frameworks.

Application logs for your service entity are not included in the data sent by APM libraries. Configure your server or application to send application logs to SolarWinds Observability. See Add logs from services.

If trace context is added to logs and those logs are sent to SolarWinds Observability, use the Traces Explorer to see the logs associated with a traced transaction.

Enable trace context

To enable trace context in logs, configure the logging framework. For example, in Logback, the following configuration prepends the trace context before the log message:

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> 
    <layout class="ch.qos.logback.classic.PatternLayout"> 
            trace_id=%X{trace_id} span_id=%X{span_id} trace_flags=%X{trace_flags}${} %5p - %msg%n

An example of the logs after the trace context being enabled is:

trace_id=87f03e188270c5b6d8bfffee45f78fcb span_id=b9c4101c7ec7dbdb trace_flags=01 INFO -  hi this is an info log.

See Logger MDC auto-instrumentation in the OpenTelemetry Java Instrumentation documentation. The MDC context for service name can be configured as follows:

  • Log4j2:${}

  • Logback:${}

Supported frameworks

Log4j 1 1.2+
Log4j 2 2.7+
Logback 1.0+

The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.