Recently I had the need of doing some integration tests that include components declared as Beans which generate traces and I had some drawbacks. I have coded a naive approach to solve them but I think that it would be nice to have it out of the box either at Spring Boot or at micrometer-tracing-test.

The drawbacks I had were the following:

On one hand, I tried the approach of using the micrometer-tracing-test injecting the SimpleTracer as a bean, so the spring components make use of it. But I realized that some components are not executed. For example:

  • Compoments used by the vendor implementation like io.micrometer.tracing.otel.bridge.Slf4JBaggageEventListener (otel is the implementation which I am using at the project) or io.opentelemetry.sdk.trace.SpanProcessor. But also
  • Components from the micrometer api like io.micrometer.tracing.exporter.SpanFilter that although they are generic, they are called by the implementation bridge. (For example from io.micrometer.tracing.otel.bridge.CompositeSpanExporter).

I think it would be interesting to have a tracing testing tool that executes the vendor's infraestructure. (Although not sending the races for real).

On the other hand, I tried to use the micrometer-tracing-integration-test but I could not publish the Tracer created there as a bean.

I have opened a similar issue at https://github.com/micrometer-metrics/tracing/issues/463

You can take a look to my approach at the repo https://github.com/JordiMartinezVicent/spring-boot-tracing-test

Here we have the following components:

  • @TracingTest annotation, which ease the configuration of the tests, inserting all the needed components
  • The TracingExtension which manages the tests lifecycle (and clean up resources between tests)
  • The OtelTracingTestAutoConfiguration which auto-configures the mocked infraestructure for open telementry vendor. (Currently I only have this implementation)
  • The TracingAssertions are the micrometer's

You can see an example of use at https://github.com/JordiMartinezVicent/spring-boot-tracing-test/blob/main/src/test/java/org/jordi/test/tracing/TracingTestWithSBTests.java

Note that the user code is independent of the vendor

I would have open a PR directly against SpringBoot or micrometer tracing, but would not know where to place each component. But if you like the approach, I am happy to contribute with a bit of guidance from you.

Comment From: mhalbritter

If Micrometer supplies something which stores the spans in memory for later assertions, Boot could autowire that in tests. Let's see what the discussion in https://github.com/micrometer-metrics/tracing/issues/463 brings up.

Comment From: wilkinsona

Superseded by https://github.com/spring-projects/spring-boot/issues/39451.