Make auto-configured OtelTracer back off when user defines a Tracer

Closes gh-33097
This commit is contained in:
Andy Wilkinson
2022-11-10 10:12:36 +00:00
parent d91e16a6c5
commit 6e4bece912
2 changed files with 5 additions and 5 deletions

View File

@@ -135,7 +135,7 @@ public class OpenTelemetryAutoConfiguration {
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnMissingBean(io.micrometer.tracing.Tracer.class)
OtelTracer micrometerOtelTracer(Tracer tracer, EventPublisher eventPublisher,
OtelCurrentTraceContext otelCurrentTraceContext) {
return new OtelTracer(tracer, otelCurrentTraceContext, eventPublisher,

View File

@@ -106,8 +106,8 @@ class OpenTelemetryAutoConfigurationTests {
@Test
void shouldBackOffOnCustomBeans() {
this.contextRunner.withUserConfiguration(CustomConfiguration.class).run((context) -> {
assertThat(context).hasBean("customOtelTracer");
assertThat(context).hasSingleBean(OtelTracer.class);
assertThat(context).hasBean("customMicrometerTracer");
assertThat(context).hasSingleBean(io.micrometer.tracing.Tracer.class);
assertThat(context).hasBean("customEventPublisher");
assertThat(context).hasSingleBean(EventPublisher.class);
assertThat(context).hasBean("customOtelCurrentTraceContext");
@@ -201,8 +201,8 @@ class OpenTelemetryAutoConfigurationTests {
private static class CustomConfiguration {
@Bean
OtelTracer customOtelTracer() {
return mock(OtelTracer.class);
io.micrometer.tracing.Tracer customMicrometerTracer() {
return mock(io.micrometer.tracing.Tracer.class);
}
@Bean