Class TracingEntityLifecycleHandler<I,E>

java.lang.Object
org.axonframework.eventsourcing.handler.tracing.TracingEntityLifecycleHandler<I,E>
Type Parameters:
I - the entity identifier type
E - the entity type
All Implemented Interfaces:
DescribableComponent, EntityLifecycleHandler<I,E>, SourcingHandler<I,E>

@Internal public final class TracingEntityLifecycleHandler<I,E> extends Object implements EntityLifecycleHandler<I,E>
Type-preserving tracing decorator for EntityLifecycleHandler. Opens an internal sourcing span around source(Object, ProcessingContext) - the parent for the SnapshotStore.load / SnapshotStore.store spans produced by TracingSnapshotStore, plus the eventual event-replay spans the framework emits underneath.

initialize and subscribe are pure pass-throughs (no span); they are not on the hot replay path and adding spans there would only add noise to the trace.

Since:
5.3.0
Author:
Mateusz Nowak
  • Constructor Details

    • TracingEntityLifecycleHandler

      public TracingEntityLifecycleHandler(EntityLifecycleHandler<I,E> delegate, SpanFactory spanFactory, String entityTypeName)
      Initializes a tracing EntityLifecycleHandler wrapping the given delegate, obtaining spans from the given spanFactory.
      Parameters:
      delegate - the lifecycle handler to delegate to
      spanFactory - the factory producing the tracing spans
      entityTypeName - the entity-type name used as the span suffix and axoniq.entity.type attribute. When unknown a generic value such as "entity" is acceptable; null is not.
  • Method Details

    • source

      public CompletableFuture<E> source(I identifier, ProcessingContext processingContext)
      Description copied from interface: SourcingHandler
      Sources the entity identified by the given identifier.

      This method returns a CompletableFuture that completes when the entity has been fully reconstructed or evolved to its latest state.

      Specified by:
      source in interface SourcingHandler<I,E>
      Parameters:
      identifier - the identifier of the entity to source, cannot be null
      processingContext - the ProcessingContext associated with this sourcing operation, cannot be null
      Returns:
      a CompletableFuture that completes with the sourced entity, never null
    • initialize

      public E initialize(I identifier, ProcessingContext context)
      Description copied from interface: EntityLifecycleHandler
      Creates a new instance of the entity for the given identifier.

      This operation is used when no prior state exists for the entity. The resulting instance represents the initial state before any events have been applied.

      Specified by:
      initialize in interface EntityLifecycleHandler<I,E>
      Parameters:
      identifier - the entity identifier, cannot be null
      context - the processing context, cannot be null
      Returns:
      a newly initialized entity instance
    • subscribe

      public void subscribe(ManagedEntity<I,E> entity, ProcessingContext context)
      Description copied from interface: EntityLifecycleHandler
      Subscribes the given managed entity to the event stream so it receives future state changes.

      After subscription, any newly appended events relevant to the entity are applied to its current state, keeping it synchronized with the event store for the remainder of its lifecycle.

      Specified by:
      subscribe in interface EntityLifecycleHandler<I,E>
      Parameters:
      entity - the managed entity to subscribe
      context - the processing context
    • 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.