Analyze request call chains

Updated at:

This topic describes how to use the end-to-end connection feature to analyze service call chains and parameters for efficient troubleshooting.

Prerequisites

Cloud Toolkit 2021.4.1 or later is installed in IntelliJ IDEA. For more information, see Install and configure Cloud Toolkit in IntelliJ IDEA.

Background

When a service call exception or resource access failure occurs during application runtime, developers often use breakpoint-based debugging to troubleshoot these issues. However, breakpoint-based debugging is not suitable for all scenarios and may have the following drawbacks:

  • Lack of a holistic call overview: When a high-level service receives a request, it often splits the request into multiple sub-requests and aggregates their results. For example, a service might first attempt to access a cache. If the cache access times out, it then accesses a database before consolidating the data to return a response. Breakpoint-based debugging makes it difficult to determine which sub-requests the service initiated and the duration of each request.
  • Inefficient debugging due to deep class nesting: Service frameworks abstract many internal processing details, simplifying operations like microservice calls, cache access, and database access. However, the underlying processes are often complex. The path from the top-level entry point to a low-level exception typically involves multiple nested class calls and various synchronous and asynchronous processing steps, which makes breakpoint-based debugging extremely difficult.
  • Performance impact of debugging itself: Breakpoint-based debugging is time-consuming. Meanwhile, service frameworks often have timeout checks. The delays that debugging introduces can cause the service to time out.

Enable end-to-end connection and print trace information

  1. Start IntelliJ IDEA.
  2. In the top menu bar, choose Tools > Alibaba Cloud > Preferences....
  3. In the Settings dialog box, choose Alibaba Cloud Toolkit > Microservice > Microservice.
  4. On the Microservice page, select the Remote Debugging checkbox, and then click Advanced Configuration.
  5. In the Advanced Configuration dialog box, select the Print trace information checkbox, and then click OK.
    Note This feature relies on trace collection by the Application Real-Time Monitoring Service (ARMS) Agent. The plugin automatically attaches the agent when you start the application, so no additional action is required.

View request call chain

After you start the application, the following call chain is displayed in the output when the application initiates a service call or accesses an external resource.

DNS name: xxx.redis.rds.aliyuncs.com, IP: xxx, use: 34(ms)
Get redis: foo -> bar
TraceId: c0a801bxxx, Service: /consumer-echo/xxx, Api: None, Line: None, Cost: 916(ms), Ext: status:[200]
  -org.apache.catalina.core.StandardHostValve.invoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response), Line: 109, Cost:
  -org.springframework.web.servlet.FrameworkServlet.doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response), Line: 866
  -com.alibaba.edas.boot.DemoConsumerController.feign1(java.lang.String str), Line: 94, Cost: 759(ms), Ext: None
    -org.apache.dubbo.rpc.protocol.AbstractInvoker.invoke(org.apache.dubbo.rpc.Invocation inv), Line: 131, Cost: 38(ms), Ext: params:[nahai], url:[com.alibaba.edas]
    -com.alibaba.edas.boot.DemoConsumerController.redisGetAndSet(), Line: 150, Cost: 411(ms), Ext: None
      -redis.clients.jedis.BinaryJedis.auth(java.lang.String password), Line: 2284, Cost: 54(ms), Ext: sql:[BinaryJedis.auth], destination:[xxx.redis.rds.aliyuncs.com:xxx]
      -redis.clients.jedis.BinaryJedis.getDB(), Line: 3357, Cost: 1(ms), Ext: sql:[BinaryJedis.getDB], destination:[xxx.redis.rds.aliyuncs.com:63]
      -redis.clients.jedis.BinaryJedis.set(byte[] key, byte[] value), Line: 196, Cost: 33(ms), Ext: sql:[BinaryJedis.set], destination:[xxx.redis]
      -redis.clients.jedis.BinaryJedis.resetState(), Line: 1915, Cost: 0(ms), Ext: sql:[BinaryJedis.resetState], destination:[xxx.redis.rds.aliyu]
      -redis.clients.jedis.BinaryJedis.get(byte[] key), Line: 246, Cost: 33(ms), Ext: sql:[BinaryJedis.get], destination:[xxx.redis.rds.aliyuncs.]
    -com.alibaba.edas.boot.DemoConsumerController.testdb(), Line: 141, Cost: 120(ms), Ext: None
      -com.mysql.cj.jdbc.StatementImpl.executeQuery(java.lang.String sql), Line: 1123, Cost: 47(ms), Ext: sql:[select * from books], destination:[book_store]
Console Link: https://arms.console.aliyun.com/apm?regionId=cn-hangzhou#/callChain/xxx/1618798551/1618798571

The call chain output contains the following information:

  • TraceId: Identifies the entire processing flow of a request. In a distributed microservices scenario, the TraceId propagates from the front-end application node to all downstream nodes in the call chain. You can use this TraceId to query the entire call chain on the EDAS console or the ARMS console.
  • Service: The request processing entry point for the current application, such as a Spring Cloud, Dubbo, or HSF service.
  • API: The method signature used in the call chain processing.
  • Line: The specific line number where the method is processed.
  • Cost: The time taken by this method and its downstream processes, in milliseconds.
  • Ext: Extended information, including the request processing status code, database access SQL, and resource target address.
  • Console link: A link to the trace information collected on the ARMS console. ARMS call chain collection is near real-time. If the call chain is not displayed when you open the link, wait a moment and refresh the page.

Analyze request call chain

Viewing the request chain provides an overview of the key nodes in the request processing flow. If you need to further analyze the parameters, return values, or exceptions at these key nodes, you can use Arthas, which is integrated into the plugin.

  1. In the top menu bar, choose Tools > Alibaba Cloud > ... > Diagnostic Tools.
    The plugin automatically downloads and starts the Arthas package, which opens in the Terminal tab of IntelliJ IDEA.
    $ java -jar /Users/dengshenyuan/.arthas/lib/3.5.0/arthas/arthas-boot.jar
    [INFO] arthas-boot version: 3.5.0
    [INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
    * [1]: 92113 com.intellij.idea.Main
      [2]: 95313 org.jetbrains.jps.cmdline.Launcher
      [3]: 95458 org.jetbrains.jps.cmdline.Launcher
      [4]: 86071
      [5]: 95481 com.alibaba.edas.boot.DubboConsumer
      [6]: 92107 org.gradle.launcher.daemon.bootstrap.GradleDaemon
      [7]: 86207 org.jetbrains.jps.cmdline.Launcher
      [8]: 95326 com.alibaba.edas.boot.DubboProvider
    Note In IntelliJ IDEA, the application runs in the Run or Debug tab, while Arthas runs in the Terminal tab. Switch between these tabs as needed.
  2. Select the target process to attach Arthas, enter its serial number, and press Enter.
    The Arthas interface appears.
    [INFO] Try to attach process 95481
    [INFO] Attach process 95481 success.
    [INFO] arthas-client connect 127.0.0.1 3658
      ,---.  ,------. ,--------.,--.  ,--. ,---. ,---.  
     /  O  \ |  .--. ''--.  .--'|  '--'  |/  O  \  `--. 
    |  .-.  ||  '--'.'   |  |   |  .--.  |  .-.  | .-'  
    |  | |  ||  |\  \    |  |   |  |  |  |  | |  |.-'    |
    `--' `--'`--' '--'   `--'   `--'  `--`--' `--'`-----'
    wiki      https://arthas.aliyun.com/doc
    tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
    version   3.5.0
    main_class
    pid       95481
    time      2021-04-19 11:14:24
    [arthas@95481]$
    Note If your application is running in container mode locally, you must manually enter the container to attach and monitor with Arthas, as the process is not visible from outside the container.
  3. Use the Arthas Trace command and Watch command for analysis, and use the Exit command to exit Arthas.

    From the request call chain analysis, you can obtain the class path and method signature of key nodes. For example, for com.alibaba.edas.boot.DemoConsumerController.redisGetAndSet(), the class path is com.alibaba.edas.boot.DemoConsumerController, and the method name is redisGetAndSet. You can use this information for analysis.

    • Trace command

      The Trace command shows the internal call path of a method and the time spent at each node. Functionally, the Arthas Trace command is similar to viewing the request chain. Because they use different trace collection mechanisms, you can use them together for a comprehensive analysis.

      The Trace command format is as follows:

      trace <class_path> <method_name>
      main_class
      pid          95481
      time         2021-04-19 11:23:41
      [arthas@95481]$ trace redis.clients.jedis.BinaryJedis resetState
      Press Q or Ctrl+C to abort.
      Affect(class count: 2 , method count: 1) cost in 548 ms, listenerId: 1
      `---ts=2021-04-19 11:23:41;thread_name=http-nio-8088-exec-5;id=8e;is_daemon=true;priority=5;TCCL=org.springframework.b
      r@19a12e1
          `---[1.093155ms] redis.clients.jedis.BinaryJedis:resetState()
              +---[0.061789ms] com.navercorp.pinpoint.bootstrap.interceptor.registry.InterceptorRegistry:getInterceptor() #2
              +---[0.070186ms] com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor:before() #95
              +---[0.036731ms] redis.clients.jedis.Client:isConnected() #1915
              +---[0.030611ms] redis.clients.jedis.Client:resetState() #1924
              `---[0.261572ms] com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor:after() #1929

      Press Q or Ctrl+C to exit this command.

    • Watch command

      The Watch command lets you observe the processing results of methods at key nodes. You can inspect input parameters, return values, and thrown exceptions.

      The Watch command format is as follows:

      watch <class_path> <method_name> <watch expression> <condition>

      For details about the command, see the Arthas official documentation. The following example demonstrates common parameters. This command observes the redisGetAndSet method of the com.alibaba.edas.boot.DemoConsumerController class, outputs its input parameters and return value, and specifies a property traversal depth of 2.

      watch com.alibaba.edas.boot.DemoConsumerController redisGetAndSet '{params,returnObj}' -x 2
      [arthas@96413]$ watch com.alibaba.edas.boot.DemoConsumerController redisGetAndSet '{params,returnObj}' -x 2
      Press Q or Ctrl+C to abort.
      Affect(class count: 1 , method count: 1) cost in 159 ms, listenerId: 1
      method=com.alibaba.edas.boot.DemoConsumerController.redisGetAndSet location=AtExit
      ts=2021-04-19 11:42:46; [cost=453.193619ms] result=@ArrayList[
          @Object[][
              @String[foo],
          ],
          @String[bar],
      ]

      Note The property traversal depth in the example is 2. By adjusting this parameter, you can view the property values of complex, nested objects during a method call.

      Press Q or Ctrl+C to exit this command.

    • Exit command

      To stop using Arthas, enter exit and press Enter.