Skip to content

Auto-configure testing support for tracing #39451

Open
@marcingrzejszczak

Description

@marcingrzejszczak

Currently there's no out of the box way to set up a test with tracing turned on that would collect spans in a queue for further analysis. What is required now from the user is to either use a TestSpanHandler from Brave or ArrayListSpanReporter from OTel.

With the changes in this PR we're introducing an abstract concept of aggregating spans for Micrometer Tracing API.

In Spring Boot we would need the @TracingTest test slice that would turn on the @AutoConfigureObservability with tracing on and would register the TestSpanHandler as a bean.

related issue

Activity

wilkinsona

wilkinsona commented on Feb 8, 2024

@wilkinsona
Member

A tracing slice would limit the context to only the beans that are related to tracing. It doesn't sound like that's what we want here. Don't we just want a way to opt in to the registration of the TestSpanHandler bean, leaving all of the context's other beans pretty much as they are?

marcingrzejszczak

marcingrzejszczak commented on Feb 8, 2024

@marcingrzejszczak
ContributorAuthor

Yeah, you're right. That would be the way to go.

JordiMartinezVicent

JordiMartinezVicent commented on Feb 8, 2024

@JordiMartinezVicent

Just a couple of points:

Otel considerations:
Currently a BatchSpanProcessor at OpenTelemetryAutoConfiguration being used. It reports the span asynchronously. I think that it should not be desirable in tests as it could cause race conditions. A way of solve the issue would be to override the SdkTracerProvider with a SimpleSpanProcessor instead:

@Bean
	SdkTracerProvider testSdkTracerProvider(ObjectProvider<SpanExporter> spanExporters,
			ObjectProvider<SpanExportingPredicate> spanExportingPredicates, ObjectProvider<SpanReporter> spanReporters,
			ObjectProvider<SpanFilter> spanFilters,
			final ObjectProvider<SdkTracerProviderBuilderCustomizer> customizers) {

		final SdkTracerProviderBuilder builder = SdkTracerProvider.builder();

		builder.addSpanProcessor(SimpleSpanProcessor.create(new CompositeSpanExporter(
				spanExporters.orderedStream().toList(), spanExportingPredicates.orderedStream().toList(),
				spanReporters.orderedStream().toList(), spanFilters.orderedStream().toList())));

		customizers.orderedStream().forEach((customizer) -> customizer.customize(builder));

		return builder.build();
	}

Brave considerations
It would be nice to auto-configure a Sampler.ALWAYS_SAMPLE for testing purposes for the user not to worry about it.

Also we would need some mechanism to clear the spans reported between tests (JUnit extension??)

marcingrzejszczak

marcingrzejszczak commented on Feb 9, 2024

@marcingrzejszczak
ContributorAuthor

As for the test extension I guess we should summon @sbrannen

changed the title [-]Add a @TracingTest test slice[/-] [+]Auto-configure testing support for tracing[/+] on Feb 9, 2024
added this to the 3.x milestone on Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @wilkinsona@marcingrzejszczak@spring-projects-issues@JordiMartinezVicent

        Issue actions

          Auto-configure testing support for tracing · Issue #39451 · spring-projects/spring-boot