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?
You can try following ways (Any one of the following):
Try to remove micrometer core and micrometer tracing dependencies and add actuator dependency it has micrometer core and micrometer observation available with it.
Add micrometer observations dependency.
Related
I use spring sleuth in my project and after I updated spring-boot to version 3 I receive the following error:
Consider defining a bean of type 'org.springframework.cloud.sleuth.Tracer' in your configuration.
I inject Tracer in my logging service to get current traceId and spanId. This is the dependency for spring sleuth:
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.1.5'
Is Tracer Bean no longer built in in terms of spring boot v3?
Spring Cloud Sleuth’s last minor version is 3.1. You can check the 3.1.x branch for the latest commits. The core of this project got moved to Micrometer Tracing project and the instrumentations will be moved to Micrometer and all respective projects (no longer all instrumentations will be done in a single repository).
see: https://spring.io/projects/spring-cloud-sleuth
This means that for Boot 3.x you need to use Micrometer Tracing instead of Sleuth.
I'm using Spring Boot 2.6 and Spring Cloud Sleuth 3.1.4
Whenever I run the app I'm getting this:
Your project setup is incompatible with our requirements due to following reasons:
- Spring Boot [2.6.0] is not compatible with this Spring Cloud release train
Action:
Consider applying the following actions:
- Change Spring Boot version to one of the following versions [2.4.x, 2.5.x] .
You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn].
If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [https://spring.io/projects/spring-cloud#overview] and check the [Release Trains] section.
If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]
According to release train 2021.0.x should be compatible with Spring boot 2.6 and sleuth 3.1.4 is a part of it.
Am I missing something here?
In the compatibility matrix, as listed here: https://spring.io/projects/spring-cloud, under 'Release Train' section, this should work.
But, I would recommend you to lower the spring cloud version to 3.1.3 to begin with. If you still get the same error, try with version 3.1.0. as in my project I had no problems using spring-cloud-starter-sleuth 3.1.0 with Spring Boot 2.6.x.
Best regards,
Filip
EDIT: With spring sleuth 3.1.4 you should use spring-cloud-dependencies of version 2021.0.4. Maybe here you got the problem.
My colleague offers me a openFeign interface which is based in spring Cloud 2.x, i can't inject it in my service as usuall. (my spring cloud version is Edgware.RELEASE, and may be it may be the initiator of this problem),so what can i do to solve this problem?
As #spencergibb has mentioned in his comment, Edgeware is not compatible with Spring Boot 2.x. You will need to use the Finchley release train:
Please read the Release Train section of the Spring Cloud Documentation.
I am using Spring boot.
I want to check which logging implementation is printing the message - I know with Spring boot default is Logback, and I have excluded it as mentioned in this post so mostly Logback will not be printing the messages, but I want to show it as a proof that Logback implementation is not printing and probably Log4j is printing.
Basically I need an API which I can call and I can get the details of which is the logging implementation, the way we can know Java version etc.
You can enforce Spring Boot to use a certain implementation by setting this property:
org.springframework.boot.logging.LoggingSystem
with any of:
org.springframework.boot.logging.logback.LogbackLoggingSystem
org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
org.springframework.boot.logging.java.JavaLoggingSystem
none (to swith off completely)
This explicit configuration would be your proof.
To check configuration you can install spring actuator framework. Through web endpoints all config params can be queried.
I am to use Dependency Injection of Spring framework version 4. I have seen that the Jersey has its DI with plugin
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>2.12</version>
</dependency>
Is Jersey's DI of Spring recommended or is there special reason to use it? What if Spring 4 DI is used independently ?
Also please let me know any step by step learning source to integration Spring DI with Jersey ?
The jersey-spring3 extension is not a stand-alone Dependency Injection feature, it's just an extension which makes Jersey aware of Spring's managed beans.
From Jersey - Spring DI:
Jersey provides an extension to support Spring DI. This enables Jersey to use Spring beans as JAX-RS components (e.g. resources and providers) and also allows Spring to inject into Jersey managed components.
...
The above module does not add any transitive dependency to Spring modules, so you will need to add Spring 3 dependencies explicitly into your dependency list.
So if you want to use Jersey with Spring you need jersey-spring3 and all the Spring dependencies you normally use.
By the way, the jersey-spring3 extension is compiled against Spring 3, but should work with Spring 4. See Using Jersey-spring with Spring 4.0 for reference.
You should add jersey-spring3.jar first like the document in jersey website.
For this step by step learning source to integration Spring DI with Jersey, you can do like this when you start up you application debug the application.
Find ServletContainer.class and set a breakpoint in init() function, as this you can find this step by step.