Analyze code-level slow requests with SkyWalking and Managed Service for OpenTelemetry

Updated at:

Java's bytecode injection technology allows many frameworks to support automatic instrumentation. This helps you identify the approximate source of a slow request. However, to pinpoint the exact code method causing the performance issue, you can combine the slow request analysis feature of SkyWalking with tracing.

Prerequisites

You have connected your Java application to Managed Service for OpenTelemetry using the SkyWalking Agent. For more information, see Report Java application data by using SkyWalking.

Background information

The following diagram illustrates how SkyWalking collects data for slow requests.

image
Note

The slow request analysis feature is available only in SkyWalking 7.0 and later versions.

Create a slow request collection task

  1. Log on to the Managed Service for OpenTelemetry console. In the left-side navigation pane, click Applications.

  2. On the Applications page, select a region in the top navigation bar and click the name of the application.

  3. In the left-side navigation pane, click slow request analysis, and then click Create a task.

  4. In the Create a task dialog box, configure the parameters and click OK.

    Parameter

    Description

    Required

    Example

    Span name

    The span to monitor.

    Yes

    /api

    Monitoring duration

    The duration of the monitoring task.

    No

    5 min

    Span duration threshold

    Only spans with a duration exceeding this threshold (in ms) are analyzed.

    No

    30 ms

    Monitoring interval

    The data collection interval.

    No

    20 ms

    Maximum number of samples

    The maximum number of spans to sample, from 1 to 9.

    No

    5

    The new task appears in the task list.

Pinpoint slow methods

After the monitoring period, spans exceeding the duration threshold appear in the Sampled Traces section. Use the thread stack details to pinpoint the methods that cause slow requests.

  1. On the slow request analysis page, click a task in the task list section.

    When you click a task, a span tree and the Thread Stack details appear on the right. The span tree displays the request's call chain as a tree table (for example, the root span /api has child spans /api1 and /api2), showing the Start time, IP, and Duration for each span. The Thread Stack table below shows the complete method call stack, including the Duration, Self duration, and Sample count columns. High-latency methods, such as java.lang.Thread.sleep, are highlighted in red to help you identify performance bottlenecks.

    The Sampled Traces section lists spans whose duration exceeded the threshold.

  2. In the Sampled Traces section, click a span and observe the Thread Stack section on the right.

    Methods displayed in red have exceeded the duration threshold. You can optimize them accordingly.

Why are thread stacks missing?

If no thread stacks are sampled after the monitoring duration ends, follow these steps to troubleshoot the issue.

  1. On the slow request analysis page, in the task list section, click View task details for the relevant task.

  2. Review the information in the task details dialog box.

    The details include parameters such as span name (for example, /api), timestamp, monitoring duration (for example, 5 min), span duration threshold (for example, 30 ms), monitoring interval (for example, 20 ms), and maximum number of samples (for example, 5), as well as fields like instance (which includes the agent's IP address) and operation type.