TraceId and SpanId not available after migrating to Spring Boot 3
Asked Answered
P

2

14

After migrating spring boot from version 2.x to 3 we miss traceId and spanId in our logs.

We removed all sleuth dependencies and added

implementation 'io.micrometer:micrometer-core'
implementation 'io.micrometer:micrometer-tracing'
implementation 'io.micrometer:micrometer-tracing-bridge-brave'
implementation platform('io.micrometer:micrometer-tracing-bom:latest.release')

as well as

logging.pattern.level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]"

but no traceIds and spanIds are being logged.

Is there something we missed?

Polite answered 19/1, 2023 at 9:58 Comment(1)
You can remove the micrometer-tracing dependency as it "is added transitively". Not sure if you need the micrometer-core, logs work in my case just with the tracing bridge and actuator as mentioned in the comment below.Napoli
D
9

You need actuator and a bridge, the rest you included is not needed:

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-tracing-bridge-brave'

If you also want to report your spans, you should add the zipkin reporter too:

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-tracing-bridge-brave'
implementation 'io.zipkin.reporter2:zipkin-reporter-brave'

Here's an example on start.spring.io and there are a lot of samples in the micrometer-samples repo.

Discriminatory answered 21/2, 2023 at 22:49 Comment(5)
Hi! I'm using your demo project without zipkin report and it doesn't work. Here is the result: 2023-05-26T22:02:11.632+07:00 " INFO [,,]" 341317 --- [ Test worker] com.example.demo.DemoApplicationTests What is may be wrong?Pained
Found my mistake, missed the need to use the @Observed annotation.Pained
@VictorBorovlev .. Where to use that Annotation in our Springboot Application ?Linkwork
I tried adding the annotation on the Controller Class and I am getting different TraceIds at my Receiver end . Trace Id are not same in Sender and Receiver Controllers - Any Hint for this issue ?Linkwork
@SusheelRao I used annonation io.micrometer.observation.annotation.Observed on Controller class and RestTemplate or WebClient for request another application and it is work fine. Also i use CurrentTraceContext for get trace id in ControllerAdvice class and put in error dto.Pained
L
0

If it is a Spring Webflux project you won't be able to see the traceId and spanId as the micrometer does not support that in sprint boot 3. If its Spring MVC then you should be able to see the traceId and SpanId.

https://github.com/spring-projects/spring-boot/issues/33372

https://github.com/spring-projects/spring-framework/issues/29466

Lelahleland answered 18/6 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.