I'm making a move from Spring Boot 1.5.21 to 2.2.5, and in the process also moving from spring-boot-cloud version Edgware.SR6 to Hoxton.SR3. This move forced me to ditch the sleuth's own implementation of tracer/span model and embrace the new model from brave. However, I have an issue with my controller integration tests.
I have a microservice called Edge
with a main class called EdgeApplication
and I'm using Spock as a testing framework.
My code includes the following test class:
@ContextConfiguration(classes = EdgeApplication.class)
@SpringBootTest(classes = EdgeApplication.class)
@ActiveProfiles(profiles = ["test"])
@AutoConfigureMockMvc
class VerificationCodeControllerSpecIT extends Specification {
@Autowired
MockMvc mockMvc
def setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build()
}
def "Generate change password verification code"() {
// Some code calling a PrincipalController via mockMvc.perform()
}
}
Previously, in Spring Boot 1.5.21, when The call got to the PrincipalController
, a default trace context with span was initialized. Now, in Spring Boot 2, this is not the case. I must emphasise that this lack of context in the PrincipalController
only happens in test code, and not in a real run of the microservice.
Why this behavior changed and how can I restore the old behavior, i.e. have a default trace context with span when the controller is called?
I added a demo project:
Demo
You will be able to run the integration test and in debug see that in the controller tracer.currentSpan()
is null (while containing a value on normal project run)