-
Notifications
You must be signed in to change notification settings - Fork 54
Description
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 would like to share them with you and if you agree, I could contribute to the repo with the solution I found. (Not sure if this is the right repo, as micrometer-tracing does not include Spring Boot. If it is not, I would appreciate your opinion and the redirection to the right repo).
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 fromio.micrometer.tracing.otel.bridge.CompositeSpanExporter
).
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.
Having said that, I would suggest to have some tracing testing tool which integrates with Spring Boot and can make test like the following:
@SpringBootTest(classes = TracingTestWithSBTestConfig.class)
@TracingTest //JunitExtension + Spring Config
@EnableAutoConfiguration
class TracingTestWithSBTest {
@Autowired
private InstrumentedComponent instrumentedComponent;
@Spans
private SpanCollector spanCollector;
@Test
void smoke() {
this.instrumentedComponent.doSomethingWithTrace();
TracingAssertions.assertThat(this.spanCollector.getFinishedSpans())
.hasNumberOfSpansEqualTo(1)
.hasASpanWithName("instrumented-component-span");
}
@Test
void assertTags() {
this.instrumentedComponent.doSomethingWithTrace();
TracingAssertions.assertThat(this.spanCollector.getFinishedSpans())
.hasNumberOfSpansEqualTo(1)
.assertThatASpanWithNameEqualTo("instrumented-component-span")
.hasTag("tag", "tag-value");
}
}
Where the key points would be:
- The annotation
@TracingTest
would declare the tracing beans to be used by Spring Boot auto-configurations - The annotation
@TracingTest
would contain a junit extension to manage the tests lifecycle. - The user test would not be coupled to any vendor, just to micrometer-tracing api. The SpanColletor is a generic class to decouple the tests from the vendor classes.
- The TracingAsserts would be done using the micrometer-api
I have a naive approach with the opentelemetry vendor. If you feel that it could be useful, I could share it with you, and if you like it, contribute to the project.