Skip to content

Micrometer Tracer not available in integration tests #32907

@mhalbritter

Description

@mhalbritter

This application

@SpringBootApplication
public class TracertestApplication {

    public static void main(String[] args) {
        SpringApplication.run(TracertestApplication.class, args);
    }

    @Bean
    CommandLineRunner clr(Tracer tracer) {
        return (args) -> System.out.println(tracer);
    }
}

with this test

@SpringBootTest
class TracertestApplicationTests {

	@Test
	void contextLoads() {
	}

}

fails:

Parameter 0 of method clr in com.example.tracertest.TracertestApplication required a bean of type 'io.micrometer.tracing.Tracer' that could not be found.

We disable tracing in tests, which means there is no Tracer bean available. We disable metrics too, but we provide a SimpleMeterRegistry for the MeterRegistry.

Marcin has added a NOOP tracer which we should use as a Tracer in tests when tracing is not enabled. With this change, the test works again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions