Observability in Spring AI often relies on standardized instrumentation for tracing execution paths across components. Although the underlying implementation can appear verbose, its principal role is to enable trace collection for performance analysis and debugging.
Micrometer Integration
Micrometer acts as the abstraction layer for observability backends. It provides binidngs to various monitoring systems and standardizes metric and trace exposition. For detailed concepts and API usage, refer to the official documentation: https://docs.micrometer.io/micrometer/reference/observation.html
JMX-Based Monitoring
A lightweight way to inspect runtime metrics is via JMX. Using the JDK's jconsole tool—found in the bin directory of a JDK installation—you can connect to a running JVM and browse exposed MBeans.
Include the necessary dependencies in your project build file:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-jmx</artifactId>
</dependency>
Launch jconsole, atttach it to the local process, and navigate to the MBeans tab. While this approach shows basic configuration and runtime data, it may omit custom keys injected by instrumentation code, limiting depth of insight.
Distributed Tracing with Zipkin
For end-to-end request tracing, deploy a Zipkin instance using Docker:
docker run --name zipkin -d -p 9411:9411 openzipkin/zipkin
Add tracing-specific dependencies:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
Configure tracing endpoints and sampling in application.properties:
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.zipkin.tracing.endpoint=http://localhost:9411/api/v2/spans
management.tracing.sampling.probability=1.0
After starting the application, invoke an endpoint to generate activity, then open Zipkin’s UI at http://localhost:9411. The traced call will display spans containing all relevant keys and values, revealing timing, tags, and invocation hierarchy.
While JMX offers quick introspection, Zipkin provides comprehensive distributed tracing suitable for multi-service environments. Alternative setups may combine Prometheus for metrics colllection with Grafana for visualization, or employ SkyWalking for extended application performance management.