Class TracingStateManager

java.lang.Object
org.axonframework.modelling.tracing.TracingStateManager
All Implemented Interfaces:
DescribableComponent, StateManager

@Internal public final class TracingStateManager extends Object implements StateManager
Delegating 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
; it is never instantiated directly by applications.
Since:
5.3.0
Author:
Mateusz Nowak
  • Constructor Details

    • TracingStateManager

      public TracingStateManager(StateManager delegate, SpanFactory spanFactory)
      Initializes a tracing StateManager wrapping the given delegate, obtaining spans from the given spanFactory.
      Parameters:
      delegate - the state manager to delegate to
      spanFactory - the factory producing the tracing spans
  • Method Details

    • register

      public <ID, T> StateManager register(Repository<ID,T> repository)
      Registers an Repository for use with this StateManager. The combination of Repository.entityType() and Repository.idType() must be unique for all registered repositories.

      Contract: the given repository is assumed to be untraced and is wrapped in a TracingRepository before 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-maximal TRACING_DECORATOR_ORDER and are therefore always the outermost layer. If you register a hand-built decorator pipeline around an already-traced repository, keep the TracingRepository as the outermost wrapper - burying it under another decorator makes it undetectable here and results in duplicate Repository.* spans.

      Specified by:
      register in interface StateManager
      Type Parameters:
      ID - The type of id.
      T - The type of the entity.
      Parameters:
      repository - The Repository to use for loading state.
      Returns:
      This StateManager for fluent interfacing.
    • loadManagedEntity

      public <ID, T> CompletableFuture<ManagedEntity<ID,T>> loadManagedEntity(Class<T> type, ID id, ProcessingContext context)
      Description copied from interface: StateManager
      Retrieves a ManagedEntity of the given type and id. The CompletableFuture will resolve to a ManagedEntity, or complete exceptionally if it could not be resolved.
      Specified by:
      loadManagedEntity in interface StateManager
      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 - The context to load the entity in.
      Returns:
      a CompletableFuture which resolves to the entity instance.
    • registeredEntities

      public Set<Class<?>> registeredEntities()
      Description copied from interface: StateManager
      The types of entities that are registered with this StateManager.
      Specified by:
      registeredEntities in interface StateManager
      Returns:
      the types of entities that are registered with this StateManager.
    • registeredIdsFor

      public Set<Class<?>> registeredIdsFor(Class<?> entityType)
      Description copied from interface: StateManager
      The types of identifiers that are registered with this StateManager for the given entityType.
      Specified by:
      registeredIdsFor in interface StateManager
      Parameters:
      entityType - The type of the entity.
      Returns:
      the types of identifiers that are registered with this StateManager for the given entityType.
    • repository

      public <ID, T> Repository<ID,T> repository(Class<T> entityType, Class<ID> idType)
      Description copied from interface: StateManager
      Returns the Repository for the given type. Returns null if no repository is registered for the given type and id.
      Specified by:
      repository in interface StateManager
      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 Repository for the given idType and entityType.
    • describeTo

      public void describeTo(ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods 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 DescribableComponent implementation 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 the describeTo method, 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:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.