All Products
Search
Document Center

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

Last Updated:Nov 21, 2023

You can associate trace IDs with the business logs of an application. This way, if an error occurs in the application, you can access the business logs associated with trace IDs to find out and troubleshoot the error.

Prerequisites

Note

Only Application Monitoring Pro Edition supports this feature.

Background information

In ARMS, trace IDs can be associated with the business logs of an application based on the Mapped Diagnostic Context (MDC) mechanism. Mainstream log frameworks such as Log4j, Log4j 2, and Logback are supported.

Procedure

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

  2. On the Applications page, select a region in the top navigation bar and click the name of the application that you want to manage.

    Note

    If the Java icon icon is displayed in the Language column, the application is connected to Application Monitoring. If a hyphen (-) is displayed, the application is connected to Managed Service for OpenTelemetry .

  3. In the left-side navigation pane, click Application Settings. On the page that appears, click the Custom Configuration tab.

  4. In the Log Collect Configuration section of the Custom Configuration tab, set the log source to Associated Log, turn on Link Business Logs with TraceId, select the region where Simple Log Service resources are deployed, and then select the project and Logstore that you created.

    Link Business Logs with TraceId

    Note
  5. Add %X{EagleEye-TraceID} to the pattern property of the business log layout.

    Note

    For more information about how to obtain the {EagleEye-TraceID} in your business code, see ARMS SDK instructions.

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

    • Modify 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} - %m%n
    • Modify the Log4j2 configuration file log4j2.xml:

      <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} - %m%n"/>
      </console>
    • Modify the Logback configuration file logback.xml:

      <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} - %msg%n</pattern>
      </encoder>
  6. Restart the application.

    If trace IDs are displayed in the business logs of the application, the business logs are associated with the trace IDs, as shown in the following figure.dg_am_log_traceid

  7. Optional. Configure log collection and upload application logs to the project and Logstore.

    By default, ARMS does not collect application logs.