CodexBloom - Programming Q&A Platform

implementing OpenTelemetry instrumentation in a Spring Boot application for distributed tracing

👀 Views: 95 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-07
spring-boot opentelemetry distributed-tracing Java

I'm testing a new approach and I've hit a wall trying to I'm currently working on a Spring Boot application (version 2.4.5) and trying to implement distributed tracing using OpenTelemetry... I've set up the OpenTelemetry SDK (version 1.6.0) and included the necessary dependencies in my `pom.xml`: ```xml <dependency> <groupId>io.opentelemetry</groupId> <artifactId>opentelemetry-spring-boot-starter</artifactId> <version>1.6.0</version> </dependency> <dependency> <groupId>io.opentelemetry</groupId> <artifactId>opentelemetry-exporter-otlp</artifactId> <version>1.6.0</version> </dependency> ``` I followed the basic setup and started using the `@WithSpan` annotation on my service methods to create spans, but I notice that the traces are not being sent to my OpenTelemetry collector. I'm running the collector locally with the default configuration: ```yaml receivers: otlp: protocols: grpc: http: exporters: logging: service: pipelines: traces: receivers: [otlp] exporters: [logging] ``` When I run my application, I see no errors, but the logs from the collector do not show any traces coming in. I've confirmed that my application can reach the collector at `localhost:4317`, and I have set the endpoint in my application properties: ```properties spring.application.name=my-spring-app otel.exporter.otlp.endpoint=http://localhost:4317 ``` Despite this, when I add logging in my service methods, I don't see any traces being generated or exported. I've tried placing the `@WithSpan` annotation on both the controller methods and the service methods but to no avail. Is there something I'm missing in the configuration? Any insights on how to debug this scenario or best practices for setting up tracing in a Spring Boot application with OpenTelemetry will be greatly appreciated. I'd really appreciate any guidance on this. I'm developing on Windows 11 with Java. Thanks for any help you can provide! Thanks for taking the time to read this!