{"id":3651,"date":"2025-12-24T10:01:03","date_gmt":"2025-12-24T15:01:03","guid":{"rendered":"https:\/\/www.mymiller.name\/wordpress\/?p=3651"},"modified":"2025-12-24T10:01:03","modified_gmt":"2025-12-24T15:01:03","slug":"spring-micrometer-tracing-and-observability-made-easy","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/spring_tracing\/spring-micrometer-tracing-and-observability-made-easy\/","title":{"rendered":"Spring Micrometer: Tracing and Observability Made Easy"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><p>Observability is crucial for modern applications, allowing you to understand their behavior and performance. Spring Boot 3 introduces powerful observability features through Micrometer.<\/p>\n<p><strong>Understanding Observability<\/strong><\/p>\n<p>Observability involves collecting metrics, logs, and traces to provide insights into your running application. Micrometer is the core of this in Spring Boot, offering:<\/p>\n<ul>\n<li><strong>Metrics:<\/strong> Numerical measurements about your application\u2019s performance and resource usage.<\/li>\n<li><strong>Tracing:<\/strong> Records the path of requests through your system, helping pinpoint bottlenecks and latency issues.<\/li>\n<li><strong>Logging:<\/strong> Traditional text-based records for debugging and understanding application behavior.<\/li>\n<\/ul>\n<p><strong>Micrometer\u2019s Role<\/strong><\/p>\n<p>Micrometer acts as a facade for various monitoring systems like Prometheus, Grafana, and Zipkin. It offers:<\/p>\n<ul>\n<li><strong>Vendor-Neutral API:<\/strong> Instrument your code once, and Micrometer handles the integration with the backend system.<\/li>\n<li><strong>Automatic Configuration:<\/strong> Spring Boot auto-configures Micrometer, making it easy to get started.<\/li>\n<li><strong>Flexible Customization:<\/strong> Fine-tune metrics and traces collection to match your needs.<\/li>\n<\/ul>\n<p><strong>Tracing with Micrometer<\/strong><\/p>\n<p>Micrometer Tracing builds upon Micrometer\u2019s metrics capabilities, providing distributed tracing support:<\/p>\n<ul>\n<li><strong>Span Creation:<\/strong> Annotate your code to create spans representing units of work within a trace.<\/li>\n<li><strong>Context Propagation:<\/strong> Spans are linked across service boundaries, enabling end-to-end tracing.<\/li>\n<li><strong>Integration with Logging:<\/strong> Correlate logs with traces for enhanced troubleshooting.<\/li>\n<\/ul>\n<p><strong>Benefits of Micrometer Tracing<\/strong><\/p>\n<ul>\n<li><strong>Identify Performance Bottlenecks:<\/strong> Trace requests through your system to identify slowdowns.<\/li>\n<li><strong>Understand Complex Interactions:<\/strong> Visualize how services interact to pinpoint issues.<\/li>\n<li><strong>Improve Troubleshooting:<\/strong> Combine logs and traces for faster issue resolution.<\/li>\n<\/ul>\n<p><strong>Configuration and Setup in a Spring Project<\/strong><\/p>\n<ol>\n<li>\n<p><strong>Add Dependencies:<\/strong><\/p>\n<ul>\n<li>Include <code>micrometer-core<\/code> and <code>micrometer-tracing<\/code> dependencies in your <code>pom.xml<\/code> or <code>build.gradle<\/code>.<\/li>\n<li>Choose a tracing implementation (e.g., Zipkin) and add its corresponding dependency.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Enable Tracing:<\/strong><\/p>\n<ul>\n<li>In your <code>application.properties<\/code> or <code>application.yml<\/code>, set <code>management.tracing.enabled=true<\/code>.<\/li>\n<li>If using Zipkin, configure its endpoint: <code>management.zipkin.tracing.endpoint=http:\/\/localhost:9411\/api\/v2\/spans<\/code><\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Annotate Code:<\/strong><\/p>\n<ul>\n<li>Use <code>@NewSpan<\/code> to create new spans for methods or blocks of code you want to trace.<\/li>\n<li>Use <code>@ContinueSpan<\/code> to continue an existing span in a new method.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Visualize Traces:<\/strong><\/p>\n<ul>\n<li>Access your tracing system\u2019s UI (e.g., Zipkin) to view and analyze traces.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>Tracing over Kafka<\/strong><\/p>\n<p>Spring Kafka 3.0 integrates seamlessly with Micrometer Tracing:<\/p>\n<ol>\n<li>\n<p><strong>Enable Observation:<\/strong><\/p>\n<ul>\n<li>Set <code>spring.kafka.listener.observation-enabled=true<\/code> and <code>spring.kafka.template.observation-enabled=true<\/code> in your configuration.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Kafka Producer Example:<\/strong><\/p>\n<pre><code class=\"language-java\">@Service\npublic class KafkaProducerService {\n\n    private final KafkaTemplate&lt;String, String&gt; kafkaTemplate;\n\n    public KafkaProducerService(KafkaTemplate&lt;String, String&gt; kafkaTemplate) {\n        this.kafkaTemplate = kafkaTemplate;\n    }\n\n    @NewSpan(&quot;send-message&quot;)\n    public void sendMessage(String topic, String message) {\n        kafkaTemplate.send(topic, message);\n    }\n}\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>Kafka Consumer Example:<\/strong><\/p>\n<pre><code class=\"language-java\">@Service\npublic class KafkaConsumerService {\n\n    @KafkaListener(topics = &quot;my-topic&quot;)\n    @ContinueSpan\n    public void consumeMessage(String message) {\n        \/\/ Process the message\n    }\n}\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p><strong>Tracing MongoDB Operations<\/strong><\/p>\n<p>Spring Data MongoDB also integrates with Micrometer Tracing:<\/p>\n<ol>\n<li>\n<p><strong>Enable Observation:<\/strong><\/p>\n<ul>\n<li>Configure your <code>MongoClientSettings<\/code> to include tracing.<\/li>\n<li>Set necessary properties in your <code>application.properties<\/code> or <code>application.yml<\/code>:\n<ul>\n<li><code>management.tracing.mongo.enabled=true<\/code><\/li>\n<li><code>spring.data.mongodb.tracing.enabled=true<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>MongoDB Repository Example:<\/strong><\/p>\n<pre><code class=\"language-java\">@Repository\npublic interface UserRepository extends MongoRepository&lt;User, String&gt; {\n\n    @NewSpan\n    List&lt;User&gt; findByUsername(String username);\n}\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p><strong>Tracing SQL Databases (PostgreSQL, MariaDB, MySQL)<\/strong><\/p>\n<p>Spring Data JDBC and Spring Data JPA provide integration with Micrometer Tracing:<\/p>\n<ol>\n<li><strong>Enable Observation:<\/strong><\/li>\n<\/ol>\n<ul>\n<li>\n<p><strong>Include <code>DataSourceDecoratorAutoConfiguration<\/code><\/strong>: Add the following dependency to your project:<\/p>\n<pre><code class=\"language-xml\">&lt;dependency&gt;\n    &lt;groupId&gt;com.github.gavlyukovskiy&lt;\/groupId&gt;\n    &lt;artifactId&gt;datasource-decorator-spring-boot-autoconfigure&lt;\/artifactId&gt;\n    &lt;version&gt;1.8.3&lt;\/version&gt; &lt;\/dependency&gt;\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>Configure Datasource Proxy<\/strong>: In your <code>application.properties<\/code> or <code>application.yml<\/code>, enable datasource proxy:<\/p>\n<pre><code class=\"language-yaml\">spring.datasource.decorator.enabled=true\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<ol start=\"2\">\n<li>\n<p><strong>JPA Repository Example:<\/strong><\/p>\n<pre><code class=\"language-java\">@Repository\npublic interface ProductRepository extends JpaRepository&lt;Product, Long&gt; {\n\n    @NewSpan\n    List&lt;Product&gt; findByName(String name);\n}\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p><strong>Explanation:<\/strong><\/p>\n<ul>\n<li><code>DataSourceDecoratorAutoConfiguration<\/code> is a third-party library that enhances Spring Boot\u2019s auto-configuration for datasources.<\/li>\n<li>It allows seamless integration with various datasource proxies like p6spy, datasource-proxy, and flexy-pool, enabling features like SQL logging, connection pooling enhancements, and most importantly, tracing support.<\/li>\n<li>By enabling <code>spring.datasource.decorator.enabled<\/code>, you instruct Spring Boot to use a proxy datasource that wraps your actual datasource, allowing the interception of SQL queries and their inclusion in traces.<\/li>\n<\/ul>\n<p><strong>Important Considerations:<\/strong><\/p>\n<ul>\n<li><strong>Choose a Compatible Tracing Implementation:<\/strong> Ensure your tracing implementation (e.g., Zipkin) is compatible with the <code>DataSourceDecoratorAutoConfiguration<\/code> library.<\/li>\n<li><strong>Configure Tracing System<\/strong>: Set up your chosen tracing system to receive and visualize traces.<\/li>\n<li><strong>Additional Configuration:<\/strong> Depending on your specific requirements and the chosen datasource proxy, you might need additional configuration. Refer to the <code>DataSourceDecoratorAutoConfiguration<\/code> documentation for details.<\/li>\n<\/ul>\n<p>Spring Micrometer offers a robust framework for observability, with tracing playing a critical role. The integration with various data stores and messaging systems allows for seamless end-to-end tracing, enabling you to gain complete visibility into your applications. By leveraging Micrometer Tracing, you can identify performance bottlenecks, understand complex interactions, and improve troubleshooting across your entire system.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":3652,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[446],"tags":[69,319],"series":[],"class_list":["post-3651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring_tracing","tag-java-2","tag-spring"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/08\/art-6749527_1280-jpg.avif","jetpack-related-posts":[{"id":3438,"url":"https:\/\/www.mymiller.name\/wordpress\/spring\/architecting-with-spring-and-spring-cloud\/","url_meta":{"origin":3651,"position":0},"title":"Architecting with Spring and Spring Cloud","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Building a Multi-Service Architecture with Spring 3.1.x and Spring Cloud: Unlocking the Power of Microservices In the ever-evolving landscape of software development, microservices have emerged as a powerful architectural paradigm, enabling organizations to build scalable, resilient, and agile applications. Spring, a widely adopted Java framework, provides a comprehensive suite of\u2026","rel":"","context":"In &quot;Spring&quot;","block_context":{"text":"Spring","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/field-5236879_640.jpg?fit=640%2C360&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/field-5236879_640.jpg?fit=640%2C360&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/field-5236879_640.jpg?fit=640%2C360&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3660,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_tracing\/crafting-custom-metrics-for-micrometer-tracing-a-comprehensive-guide\/","url_meta":{"origin":3651,"position":1},"title":"Crafting Custom Metrics for Micrometer Tracing: A Comprehensive Guide","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Micrometer, a versatile application metrics facade, seamlessly integrates with Spring Boot Actuator to capture and expose vital insights into your application\u2019s performance. While Micrometer offers a plethora of pre-defined metrics, you often need to track application-specific metrics that aren\u2019t covered out of the box. This blog post will explore creating\u2026","rel":"","context":"In &quot;Spring Tracing &amp; Observability&quot;","block_context":{"text":"Spring Tracing &amp; Observability","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_tracing\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/08\/car-dashboard-2667434_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/08\/car-dashboard-2667434_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/08\/car-dashboard-2667434_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/08\/car-dashboard-2667434_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/08\/car-dashboard-2667434_1280-jpg.avif 3x"},"classes":[]},{"id":3912,"url":"https:\/\/www.mymiller.name\/wordpress\/uncategorized\/spring-boot-4-0-whats-next-for-the-modern-java-architect\/","url_meta":{"origin":3651,"position":2},"title":"Spring Boot 4.0: What&#8217;s Next for the Modern Java Architect?","author":"Jeffery Miller","date":"September 24, 2025","format":false,"excerpt":"A Forward-Looking Comparison of Spring Boot 3.x and 4.0 Staying on top of the rapidly evolving Java ecosystem is paramount for any software architect. The shift from Spring Boot 2.x to 3.x brought significant changes, notably the move to Jakarta EE. Now, with the horizon of Spring Boot 4.0 and\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/09\/per-2056740_1280.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/09\/per-2056740_1280.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/09\/per-2056740_1280.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/09\/per-2056740_1280.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/09\/per-2056740_1280.avif 3x"},"classes":[]},{"id":3961,"url":"https:\/\/www.mymiller.name\/wordpress\/spring\/spring4\/architecting-spring-boot-4-with-official-spring-grpc-support\/","url_meta":{"origin":3651,"position":3},"title":"Architecting Spring Boot 4 with Official Spring gRPC Support","author":"Jeffery Miller","date":"January 15, 2026","format":false,"excerpt":"For years, the Spring community relied on excellent third-party starters (like net.devh) to bridge the gap between Spring Boot and gRPC. With the evolution of Spring Boot 4 and the official Spring gRPC project, we now have native support that aligns perfectly with Spring's dependency injection, observability, and configuration models.\u2026","rel":"","context":"In &quot;Spring4&quot;","block_context":{"text":"Spring4","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring\/spring4\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2026\/01\/Gemini_Generated_Image_3yqio33yqio33yqi.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2026\/01\/Gemini_Generated_Image_3yqio33yqio33yqi.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2026\/01\/Gemini_Generated_Image_3yqio33yqio33yqi.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2026\/01\/Gemini_Generated_Image_3yqio33yqio33yqi.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2026\/01\/Gemini_Generated_Image_3yqio33yqio33yqi.avif 3x"},"classes":[]},{"id":3771,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_circuit_breaker\/mastering-circuitbreaker-in-spring-cloud-a-comprehensive-guide\/","url_meta":{"origin":3651,"position":4},"title":"Mastering CircuitBreaker in Spring Cloud: A Comprehensive Guide","author":"Jeffery Miller","date":"December 23, 2025","format":false,"excerpt":"Spring Cloud Circuit Breaker provides an elegant way to handle failures in distributed systems by implementing the circuit breaker pattern. This pattern prevents cascading failures and improves application resilience by isolating failing services and providing fallback mechanisms. This article offers a deep dive into using CircuitBreaker in Spring Cloud, covering\u2026","rel":"","context":"In &quot;Spring Circuit Breaker&quot;","block_context":{"text":"Spring Circuit Breaker","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_circuit_breaker\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/network-5987786_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/network-5987786_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/network-5987786_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/network-5987786_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/network-5987786_1280-jpg.avif 3x"},"classes":[]},{"id":3830,"url":"https:\/\/www.mymiller.name\/wordpress\/spring-gateway\/scaling-the-gatekeeper-load-balancing-multiple-instances-of-spring-cloud-gateway\/","url_meta":{"origin":3651,"position":5},"title":"Scaling the Gatekeeper: Load Balancing Multiple Instances of Spring Cloud Gateway","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"As your microservices ecosystem grows and traffic increases, a single instance of Spring Cloud Gateway might become a bottleneck or a single point of failure. To ensure high availability, fault tolerance, and improved performance, you\u2019ll likely need to run multiple instances of your Spring Cloud Gateway and load balance traffic\u2026","rel":"","context":"In &quot;Spring Gateway&quot;","block_context":{"text":"Spring Gateway","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring-gateway\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/network-3152677_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/network-3152677_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/network-3152677_640.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/comments?post=3651"}],"version-history":[{"count":1,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3651\/revisions"}],"predecessor-version":[{"id":3653,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3651\/revisions\/3653"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/3652"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=3651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=3651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=3651"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=3651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}