I am trying to get open telemetry tracing setup in my spring boot 2.7 project. It is just a simple REST api project.
The tutorial I am following is the following one. I checked several other articles as well, but all of them discuss the same thing.
https://www.baeldung.com/spring-boot-opentelemetry-setup
I have added following dependencies in my pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Sleuth with Brave tracer implementation -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<exclusions>
<!-- Exclude Brave (the default) -->
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-brave</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Add OpenTelemetry tracer -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-otel-autoconfigure</artifactId>
</dependency>
</dependencies>
I have following dependencyManagement
tag as well in the pom file.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-otel-dependencies</artifactId>
<version>1.1.1</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
My application just exposes a simple endpoint that returns a simple string.
private final Logger logger = LoggerFactory.getLogger(GreetingsController.class);
@GetMapping("/hello-two")
public String helloFromService2() {
logger.info("Hello from service 2");
return "Hello from service 2";
}
Now the issue is, when I start the application and invoke the endpoint, I see a series of zeros as the trace id and the span id
2023-05-23 22:50:05.770 INFO [service-2,00000000000000000000000000000000,0000000000000000] 63434 --- [nio-9092-exec-5] c.e.s.controller.GreetingsController : Hello from service 2
If I use brave without excluding it, the trace id and the span id start appearing. This gives me the impression that there is something that is unknown to me in spring-cloud-sleuth-otel-autoconfigure
. Do I need to provide any configuration for that to inject the trace id and the span id ? Or what's happening here? How can I get this working.
Any help on this will be highly appreciated.
Thanks in advance.
EDIT: I am using opentelemetry java agent to collect the metrics of the application.
java -javaagent:./opentelemetry-javaagent-1.22.0.jar \
-jar target/spring-tracing-0.0.1-SNAPSHOT.jar \
--spring.config.location=./src/main/resources/application.properties