How to Master Microservice Performance Monitoring with SkyWalking APM
This tutorial walks you through installing SkyWalking, configuring Java agents, tracing microservice calls, profiling performance bottlenecks, creating custom trace annotations, logging with ActiveSpan, and using OpenTracing to achieve fine‑grained observability of Java‑based microservices.
SkyWalking Overview
SkyWalking is an APM tool for tracing request chains in microservices. It helps identify latency or errors across multiple services by visualizing the call graph.
Download and Installation
Download the SkyWalking APM distribution, which contains skywalking-oap (collector) and skywalking-ui (UI) from the official site. Install JDK 17 and set JAVA_HOME. Unzip the package and run startup.bat in the bin directory to start both OAP and UI, then access the UI at http://localhost:8080/.
Viewing Monitoring Information
Start the Nacos registry, then launch the two services with the following JVM arguments:
-javaagent:D:\developer\env\skywalking-agent\skywalking-agent.jar
-Dskywalking.agent.service_name=sky-user-service
-Dskywalking.collector.backend_service=127.0.0.1:11800Repeat the same for sky-feign-service (changing the service name). After both services start, you can see them in the SkyWalking UI, view trace data at http://localhost:8701/userFeign/1, and view the topology graph.
Performance Profiling
To simulate a slow request, add a 5‑second sleep in sky-user-service ’s getByUsername method. After invoking the endpoint, create a profiling task in SkyWalking, run the test several times, and click “Analyze”. The Thread Stack view reveals the slow operation and points to the exact line in UserFeignController.
Custom Trace
Use the @Trace annotation for method‑level tracing. Add the apm-toolkit-trace dependency to sky-feign-service and create a CustomTraceController with a test endpoint. Implement a service method annotated with @Trace and additional @Tag annotations to capture parameters and results.
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-trace</artifactId>
<version>9.1.0</version>
</dependency>Invoke the custom endpoint (e.g., http://localhost:8701/trace/annotation?userId=1) to see method‑level trace data and tagged results.
ActiveSpan Logging
Log messages directly to SkyWalking using ActiveSpan methods ( debug, info, error) inside a service method. Errors appear in red in the UI, and detailed logs are viewable in the trace details.
@Service
public class CustomTraceServiceImpl implements CustomTraceService {
@Override
public CommonResult<User> activeSpan(Long userId) {
ActiveSpan.debug("activeSpan debug message...");
ActiveSpan.info("activeSpan info message...");
ActiveSpan.error("activeSpan error message...");
return userService.getUser(userId);
}
}OpenTracing Usage
Add the apm-toolkit-opentracing dependency to sky-feign-service. In a service method, create a manual span to monitor a specific code segment:
Tracer tracer = new SkywalkingTracer();
Tracer.SpanBuilder spanBuilder = tracer.buildSpan("/trace-span/openTracing");
Span span = spanBuilder.withTag("tag", "openTracing").startManual();
// business logic
span.finish();Calling the endpoint (e.g., http://localhost:8701/trace/openTracing?userId=1) shows the total request time (~1000 ms) and the traced segment time (~6 ms).
Conclusion
The guide demonstrates how to use SkyWalking for request‑level, method‑level, and code‑segment tracing in microservices, highlighting its low intrusion for basic tracing and richer capabilities for deeper analysis.
References
Official documentation: https://skywalking.apache.org/docs/
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
