All Products
Search
Document Center

Application Real-Time Monitoring Service:Associate trace IDs with Java business logs

Last Updated:Aug 24, 2026

Associate trace IDs with your Java application's business logs so that you can quickly find relevant logs by trace ID when an issue occurs and resolve the problem faster.

Prerequisites

Note

This feature is not supported in the Basic edition of Application Real-Time Monitoring Service (ARMS).

Background information

ARMS associates trace IDs with business logs by using the Mapped Diagnostic Context (MDC) mechanism and supports Log4j, Log4j2, and Logback.

Enable the association

  1. Log on to the ARMS console. In the left-side navigation pane, choose Application Monitoring > Application List.

  2. Select a region in the top navigation bar and click the application.

    Note

    Icons in the Language column indicate the application's programming language:

    • Java icon: Java

    • image: Go

    • image: Python

    • - (Hyphen): an application monitored in Managed Service for OpenTelemetry

  3. In the top navigation bar, choose Application Configuration > Custom Configurations.

  4. On the Custom Configurations tab, in the Application Log Association Configuration section, set Log Source to SLS. Turn on the Associate Business Logs with trace ID switch, select the region of your SLS project, and then bind the project and Logstore.

    You can also turn on the Logs are automatically populated with trace ID and Logs are automatically populated with span ID switches as needed.

    The Logs are automatically populated with trace ID and Logs are automatically populated with span ID features require agent version 4.1.6 or later. When you bind SLS, you must also select an Associated Index. You can specify either a field index or a full-text index.

    Note
  5. (Optional) Manually associate the trace ID.

    In the Pattern attribute of your business log layout, add %X{EagleEye-TraceID}. If you use the SkyWalking protocol, add %X{Skywalking-TraceID} instead. If you onboard your application by using ACK OnePilot (the ARMS in-house agent), the trace ID format is %X{EagleEye-TraceID}.

    To also associate a span ID, add %X{span_id}.

    Important

    The following examples show how to modify the configuration files for Log4j, Log4j2, and Logback:

    • Example modification to the Log4j configuration file log4j.properties:

      log4j.appender.warn.layout=org.apache.log4j.PatternLayout
      log4j.appender.warn.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss}-[%p]-(%C:%L) - traceId:%X{EagleEye-TraceID} - spanId:%X{span_id} - %m%n
    • Example modification to the Log4j2 configuration file log4j2.xml:

      PatternLayout

      <console name="Console" target="SYSTEM_OUT">
          <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
          <PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - traceId:%X{EagleEye-TraceID} - spanId:%X{span_id} - %m%n"/>
      </console>

      JsonLayout

      <JsonLayout   complete="false" compact="true" eventEol="true"
                    properties="false" locationInfo="true"
                    includeStacktrace="true" stacktraceAsString="true"
                    objectMessageAsJsonObject="true" >
          <KeyValuePair key="EagleEye-TraceID" value="${ctx:EagleEye-TraceID}" />
          <KeyValuePair key="span_id" value="${ctx:span_id}" />
      </JsonLayout>
    • Example modification to the Logback configuration file logback.xml:

      PatternLayout

      <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
          <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - traceId:%X{EagleEye-TraceID} - spanId:%X{span_id} - %msg%n</pattern>
      </encoder>

      JsonLayout

      <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
      	<providers>
      		<timestamp/>
      		<threadName/>
      		<logLevel/>
      		<loggerName/>
      		<message/>
      		<callerData/>
      		<stackTrace/>
      		<pattern>
      			<pattern>
      				{
      				"EagleEye-TraceID": "%X{EagleEye-TraceID}",
                                      "span_id": "%X{span_id}"
      				}
      			</pattern>
      		</pattern>
      	</providers>
      </encoder>
  6. Restart your application.

    If the trace ID appears in your business logs, the association is successful. Example output:

    2023-02-15 15:03:43-[INFO]-(com.example....HelloController:17) - traceId:ea1e0fe79b16764446      this is an info message
    2023-02-15 15:03:43-[ERROR]-(com.example....HelloController:19) - traceId:ea1e0fe79b16764446    - this is an error message
    2023-02-15 15:03:43-[WARN]-(com.example....HelloController:21) - traceId:ea1e0fe79b16764446      this is a warn message
  7. (Optional) Configure SLS log collection to upload application logs to the project and Logstore that you bound in the previous steps.

    By default, ARMS does not collect application logs.