GH-332 - Avoid proxying configuration classes for observability purposes.

We now skip configuration classes for observability-related proxying as it's hard to detect those during the ProxyFactory setup to configure target class proxying. Also, configuration classes are usually no targets of inter-module communication and thus don't need to be observed at all.
This commit is contained in:
Oliver Drotbohm
2023-10-16 21:11:30 +02:00
parent 1482ba01f5
commit 752b5d7cf3
4 changed files with 46 additions and 7 deletions

View File

@@ -140,7 +140,7 @@ class DefaultObservedModule implements ObservedModule {
.map(SpringBean::toArchitecturallyEvidentType)
.findFirst()
.map(it -> new ObservedModuleType(modules, this, it))
.filter(ObservedModuleType::shouldBeTraced)
.filter(ObservedModuleType::shouldBeObserved)
.orElse(null);
}

View File

@@ -23,6 +23,7 @@ import java.util.stream.Stream;
import org.springframework.aop.TargetClassAware;
import org.springframework.aop.framework.Advised;
import org.springframework.context.annotation.Configuration;
import org.springframework.modulith.core.ApplicationModules;
import org.springframework.modulith.core.ArchitecturallyEvidentType;
import org.springframework.modulith.core.ArchitecturallyEvidentType.ReferenceMethod;
@@ -34,7 +35,7 @@ import org.springframework.util.ReflectionUtils;
*
* @author Oliver Drotbohm
*/
public class ObservedModuleType {
class ObservedModuleType {
private static Collection<Class<?>> IGNORED_TYPES = List.of(Advised.class, TargetClassAware.class);
@@ -62,16 +63,20 @@ public class ObservedModuleType {
}
/**
* Returns whether the type should be traced at all. Can be skipped for types not exposed by the module unless they
* Returns whether the type should be observed at all. Can be skipped for types not exposed by the module unless they
* listen to events of other modules.
*
* @return
*/
public boolean shouldBeTraced() {
public boolean shouldBeObserved() {
boolean isApiType = module.exposes(type.getType());
if (type.getType().isMetaAnnotatedWith(Configuration.class)) {
return false;
}
return type.isController() || listensToOtherModulesEvents() || isApiType;
return type.isController()
|| listensToOtherModulesEvents()
|| module.exposes(type.getType());
}
/**