Integrating SkyWalking for Application Performance Monitoring in Spring Boot

Integrating SkyWalking for Application Performence Monitoring in Spring Boot

In a microservices environment, monitoring and tracing system performance is critical. Apache SkyWalking, an application performance management (APM) tool, enables real-time observation and analysis of microservice performance. This integration process involves configuring dependencies, setting up agents, and applying custom annotations for detailed monitoring.

Prerequisites

Ensure SkyWalking is installed and configured in your environment. Refer to the official SkyWalking documentation for installation guidance.

Setting Up a Spring Boot Project

Create a new Spring Boot project or modify an existing one. Add SkyWalking dependencies to the pom.xml file:

<dependency>
    <groupId>org.apache.skywalking</groupId>
    <artifactId>apm-toolkit-logback-1.x</artifactId>
    <version>8.9.0</version>
</dependency>
<dependency>
    <groupId>org.apache.skywalking</groupId>
    <artifactId>apm-toolkit-trace</artifactId>
    <version>8.9.0</version>
</dependency>

Configuring the SkyWalking Agent

Download and extract the SkyWalking Agent. Edit the skywalking-agent/config/agent.config file to specify the OAP Server address:

agent.service_name=spring-boot-monitoring-app
collector.backend_service=localhost:11800

Add the following JVM argument to the Spring Boot application startup command to activate the agent:

-javaagent:/path/to/skywalking-agent/skywalking-agent.jar

Develloping a Sample Application

Build a basic Spring Boot application with a REST endpoint and a simulated database operation to demonstrate SkyWalking's capabilities:

package com.example.monitoring;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@SpringBootApplication
public class MonitoringApplication {
    public static void main(String[] args) {
        SpringApplication.run(MonitoringApplication.class, args);
    }
}

@RestController
class GreetingController {
    @Autowired
    private DataAccessService dataAccessService;

    @GetMapping("/greet")
    public String sendGreeting() {
        dataAccessService.fetchData();
        return "Greetings from SkyWalking!";
    }
}

@Service
class DataAccessService {
    public void fetchData() {
        // Simulating a database query
        try {
            Thread.sleep(150);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}

Applying Custom Tracing with Annotations

SkyWalking offers annotations to define custom tracing logic. Use the @Trace annotation to mark methods for monitoring:

package com.example.monitoring;

import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.springframework.stereotype.Service;

@Service
public class TracingService {
    @Trace(operationName = "specializedTask")
    public void executeTask() {
        // Simulating a custom operation
        System.out.println("Current Trace ID: " + TraceContext.traceId());
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}

The @Trace annotation designates executeTask as a traceable operation. TraceContext.traceId() retrieves the currant trace identifier for logging or other purposes.

Configuring Log Integration

Integrate SkyWalking trace data into logs by configuring the logback-spring.xml file:

<configuration>
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="TRACE" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.trace.TraceIdConverter">
        <layout>
            <Pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg [TraceId: %traceId] %n</Pattern>
        </layout>
    </appender>

    <root level="info">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="TRACE"/>
    </root>
</configuration>

Verifying Integration

Launch the Spring Boot application and access the /greet endpoint. The SkyWalking UI displays trace data and performance metrics. Logs include trace identifiers, aiding in issue diagnosis and analysis.

Enhancements and Optimizations

  • Custom Plugins: Develop SkyWalking plugins to monitor specific middleware or libraries based on business requirements.
  • Performance Tuning: Adjust agent configurations to optimize performance and minimize application impact.
  • Distributed Tracing: Implement distributed tracing across microservices with SkyWalking to analyze call chains and identify performance bottlenecks.

Tags: Spring Boot skywalking apm monitoring microservices

Posted on Sun, 19 Jul 2026 15:59:43 +0000 by sgalatas