Add factory for NoopTracer instead of using instance supplier

Closes gh-33298
pull/33335/head
Moritz Halbritter 2 years ago
parent 5a3972fee7
commit fad610ef72

@ -26,6 +26,7 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@ -133,7 +134,7 @@ class ObservabilityContextCustomizerFactory implements ContextCustomizerFactory
* {@link ConfigurationClassPostProcessor} and adds a {@link Tracer} bean definition
* when a {@link Tracer} hasn't already been registered.
*/
private static class NoopTracerRegistrar implements BeanDefinitionRegistryPostProcessor, Ordered, BeanFactoryAware {
static class NoopTracerRegistrar implements BeanDefinitionRegistryPostProcessor, Ordered, BeanFactoryAware {
private BeanFactory beanFactory;
@ -154,7 +155,7 @@ class ObservabilityContextCustomizerFactory implements ContextCustomizerFactory
}
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) this.beanFactory,
Tracer.class, false, false).length == 0) {
registry.registerBeanDefinition("noopTracer", new RootBeanDefinition(Tracer.class, () -> Tracer.NOOP));
registry.registerBeanDefinition("noopTracer", new RootBeanDefinition(NoopTracerFactoryBean.class));
}
}
@ -164,4 +165,18 @@ class ObservabilityContextCustomizerFactory implements ContextCustomizerFactory
}
static class NoopTracerFactoryBean implements FactoryBean<Tracer> {
@Override
public Tracer getObject() {
return Tracer.NOOP;
}
@Override
public Class<?> getObjectType() {
return Tracer.class;
}
}
}

Loading…
Cancel
Save