8

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?

htmoia
  • 429
  • 4
  • 9

1 Answers1

4

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.

Jonatan Ivanov
  • 4,895
  • 2
  • 15
  • 30
  • 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? – Victor Borovlev May 26 '23 at 15:08
  • Found my mistake, missed the need to use the @Observed annotation. – Victor Borovlev May 27 '23 at 10:19
  • @VictorBorovlev .. Where to use that Annotation in our Springboot Application ? – Susheel Rao Jun 15 '23 at 02:46
  • 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 ? – Susheel Rao Jun 15 '23 at 02:56
  • @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. – Victor Borovlev Jun 16 '23 at 11:01