Class TracingStateManager
- All Implemented Interfaces:
DescribableComponent,StateManager
StateManager decorator that opens internal tracing spans around state-manager load operations.
The loadManagedEntity call produces a single span named StateManager.loadManagedEntity <EntityType>
carrying the entity type name and the entity identifier (under
EntityIdSpanAttributesProvider.DEFAULT_ATTRIBUTE_KEY). The default loadEntity method
ultimately calls loadManagedEntity, so it is naturally traced too.
Repositories registered on this state manager are wrapped in a
TracingRepository (when not traced already), so their load / loadOrCreate /
persist / attach operations produce spans as well. This matters for entity modules (e.g.
event-sourced entities), which build their Repository inside the module's own component registry - out of
reach of the root registry's Repository decorator - and then register it on the root StateManager:
this wrap is what puts the Repository.load <EntityType> span inside the entity-loading trace.
This decorator is registered by
invalid reference
ModellingTracingConfigurationEnhancer
- Since:
- 5.3.0
- Author:
- Mateusz Nowak
-
Constructor Summary
ConstructorsConstructorDescriptionTracingStateManager(StateManager delegate, SpanFactory spanFactory) Initializes a tracingStateManagerwrapping the givendelegate, obtaining spans from the givenspanFactory. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.<ID,T> CompletableFuture <ManagedEntity<ID, T>> loadManagedEntity(Class<T> type, ID id, ProcessingContext context) <ID,T> StateManager register(Repository<ID, T> repository) Registers anRepositoryfor use with thisStateManager.The types of entities that are registered with thisStateManager.registeredIdsFor(Class<?> entityType) The types of identifiers that are registered with thisStateManagerfor the givenentityType.<ID,T> Repository <ID, T> repository(Class<T> entityType, Class<ID> idType) Returns theRepositoryfor the giventype.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.modelling.StateManager
loadEntity, register
-
Constructor Details
-
TracingStateManager
Initializes a tracingStateManagerwrapping the givendelegate, obtaining spans from the givenspanFactory.- Parameters:
delegate- the state manager to delegate tospanFactory- the factory producing the tracing spans
-
-
Method Details
-
register
Registers anRepositoryfor use with thisStateManager. The combination ofRepository.entityType()andRepository.idType()must be unique for all registered repositories.Contract: the given
repositoryis assumed to be untraced and is wrapped in aTracingRepositorybefore registration, unless it already is one (e.g. on re-registration of the same instance, or when registering a component the root registry's decorator already traced). The already-traced check looks at the outermost wrapper only - sound for everything the component registry builds, because the tracing decorators register at near-maximalTRACING_DECORATOR_ORDERand are therefore always the outermost layer. If you register a hand-built decorator pipeline around an already-traced repository, keep theTracingRepositoryas the outermost wrapper - burying it under another decorator makes it undetectable here and results in duplicateRepository.*spans.- Specified by:
registerin interfaceStateManager- Type Parameters:
ID- The type of id.T- The type of the entity.- Parameters:
repository- TheRepositoryto use for loading state.- Returns:
- This
StateManagerfor fluent interfacing.
-
loadManagedEntity
public <ID,T> CompletableFuture<ManagedEntity<ID,T>> loadManagedEntity(Class<T> type, ID id, ProcessingContext context) Description copied from interface:StateManagerRetrieves aManagedEntityof the giventypeandid. TheCompletableFuturewill resolve to aManagedEntity, or complete exceptionally if it could not be resolved.- Specified by:
loadManagedEntityin interfaceStateManager- Type Parameters:
ID- The type of the identifier of the entity.T- The type of the entity.- Parameters:
type- The type of state to retrieve.id- The id of the state to retrieve.context- Thecontextto load the entity in.- Returns:
- a
CompletableFuturewhich resolves to the entity instance.
-
registeredEntities
Description copied from interface:StateManagerThe types of entities that are registered with thisStateManager.- Specified by:
registeredEntitiesin interfaceStateManager- Returns:
- the types of entities that are registered with this
StateManager.
-
registeredIdsFor
Description copied from interface:StateManagerThe types of identifiers that are registered with thisStateManagerfor the givenentityType.- Specified by:
registeredIdsForin interfaceStateManager- Parameters:
entityType- The type of the entity.- Returns:
- the types of identifiers that are registered with this
StateManagerfor the givenentityType.
-
repository
Description copied from interface:StateManagerReturns theRepositoryfor the giventype. Returnsnullif no repository is registered for the given type and id.- Specified by:
repositoryin interfaceStateManager- Type Parameters:
ID- The type of the identifier of the entity.T- The type of the entity.- Parameters:
entityType- The type of the entity.idType- The type of the identifier of the entity.- Returns:
- The
Repositoryfor the givenidTypeandentityType.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-