Class TracingEventHandlingComponent
- All Implemented Interfaces:
DescribableComponent,MessageHandler,EventHandler,EventHandlingComponent,ReplayStatusChangedHandler,ResetHandler
EventHandlingComponent decorator that opens a per-event handler span around each event handled,
and -- for streaming-processor batches -- a single enclosing batch span.
On each handle(EventMessage, ProcessingContext) a handler span (kind consumer) is opened
branch-scoped via Span.branchStream(ProcessingContext, java.util.function.Function): its
SpanScope is carried on a context branch passed to the delegate, the handling window executes within
that scope, and the scope closes when this event's own result stream terminates -- not at batch end.
Carrying the scope on a branch, rather than writing it to the shared batch context, is what lets downstream children
(dispatch spans, asynchronous continuations, and provider-instrumented work) parent under their own event even when
a later event in the same batch has since started on the shared context.
The streaming flag selects the trace topology; it does not make assumptions about how or where event
handling runs. When streaming is false, each handler span continues the publisher's trace and no
batch span is created. When streaming is true, a handler span continues the publisher's trace only
in distributed-in-same-trace mode for sufficiently fresh events. Otherwise, it is a child of the enclosing batch
span and links back to the publisher, or starts a new trace with the same publisher link when batch tracing is
disabled.
The batch span, by contrast, is context-lifetime: it is opened lazily on the first event of a batch, only for
streaming processors, and only outside distributed-in-same-trace mode (in that mode per-event spans continue their
publishers' traces, so a batch root would dangle without meaningful children). It is bound to the shared batch
context's root via Span.coverLifecycle(ProcessingContext), so it legitimately stays the active span there
for every lifecycle action (commit, etc.) that runs against that root. A non-streaming processor gets no separate
batch span.
Every span this component creates -- the batch span and the per-event handler span -- carries the owning event
processor's name under the PROCESSOR_NAME_ATTRIBUTE attribute (when the name is known), so spans of
different processors handling the same event type stay distinguishable in APM UIs.
This decorator is registered by MessagingTracingConfigurationEnhancer; it is never instantiated directly by
applications.
- Since:
- 5.3.0
- Author:
- Mateusz Nowak
-
Constructor Summary
ConstructorsConstructorDescriptionTracingEventHandlingComponent(EventHandlingComponent delegate, SpanFactory spanFactory) Initializes a tracingEventHandlingComponentwith the non-streaming trace topology (streaming=false), the default sub-toggles (batchTraceEnabled=true,distributedInSameTrace=false,distributedInSameTraceTimeLimit=PT2M), and no processor name.TracingEventHandlingComponent(EventHandlingComponent delegate, SpanFactory spanFactory, @Nullable String processorName, boolean streaming, boolean batchTraceEnabled, boolean distributedInSameTrace, Duration distributedInSameTraceTimeLimit) Initializes a tracingEventHandlingComponentwrapping the givendelegate, obtaining spans from the givenspanFactory. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.handle(EventMessage event, ProcessingContext context) Handles the giveneventwithin the givencontext.handle(ReplayStatusChanged statusChange, ProcessingContext context) Handles the givenReplayStatusChangedmessage, allowing for tasks to be performed when thereplay startsandends.handle(ResetContext resetContext, ProcessingContext context) Handles the givenResetContextmessage, performing any necessary reset operations.sequenceIdentifierFor(EventMessage event, ProcessingContext context) Returns the sequence identifier for the givenevent.All supportedevents, referenced through aQualifiedName.booleanIndicates whether this component supports reset operations.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.eventhandling.EventHandlingComponent
supports, unwrap
-
Constructor Details
-
TracingEventHandlingComponent
Initializes a tracingEventHandlingComponentwith the non-streaming trace topology (streaming=false), the default sub-toggles (batchTraceEnabled=true,distributedInSameTrace=false,distributedInSameTraceTimeLimit=PT2M), and no processor name.- Parameters:
delegate- the event-handling component to delegate tospanFactory- the factory producing the tracing spans
-
TracingEventHandlingComponent
public TracingEventHandlingComponent(EventHandlingComponent delegate, SpanFactory spanFactory, @Nullable String processorName, boolean streaming, boolean batchTraceEnabled, boolean distributedInSameTrace, Duration distributedInSameTraceTimeLimit) Initializes a tracingEventHandlingComponentwrapping the givendelegate, obtaining spans from the givenspanFactory.- Parameters:
delegate- the event-handling component to delegate tospanFactory- the factory producing the tracing spansprocessorName- the name of the event processor owning thedelegate, attached to every created span under the processor-name attribute; ornullwhen unknown, in which case no attribute is attachedstreaming- whether to use the streaming trace topology; whenfalse, handler spans continue the publisher's trace and no batch span is opened; whentrue, the other tracing settings determine the handler spans' parent and whether a batch span is openedbatchTraceEnabled- whether an enclosing batch span is opened for streaming batchesdistributedInSameTrace- whentrue, a streaming handler span continues the publisher's trace and no batch span is opened; whenfalse, the handler is parented to an enabled batch span and linked to its publisher, or starts a linked trace when batch tracing is disableddistributedInSameTraceTimeLimit- how recent an event must be to continue the publisher's trace whendistributedInSameTraceistrue; older events (e.g. replays) start their own trace linked back to the publisher instead of stretching the publisher's long-finished trace
-
-
Method Details
-
handle
Description copied from interface:EventHandler- Specified by:
handlein interfaceEventHandler- Parameters:
event- The event to handle.context- The context to the giveneventis handled in.- Returns:
- An
empty streamcontaining nothing.
-
supportedEvents
Description copied from interface:EventHandlingComponentAll supportedevents, referenced through aQualifiedName.- Specified by:
supportedEventsin interfaceEventHandlingComponent- Returns:
- All supported
events, referenced through aQualifiedName.
-
sequenceIdentifierFor
Description copied from interface:EventHandlingComponentReturns the sequence identifier for the givenevent. When two events have the same sequence identifier (as defined by their equals method), they will be executed sequentially. Important: AllEventHandlersfor the sameQualifiedNamewithin a singleEventHandlingComponentmust return the same sequence identifier for a given event. Mixing different sequence identifiers within the scope of a singleEventHandlingComponentis not supported and may lead to undefined behavior.- Specified by:
sequenceIdentifierForin interfaceEventHandlingComponent- Parameters:
event- The event for which to get the sequencing identifier.context- The processing context in which the event is being handled.- Returns:
- A sequence identifier for the given event.
-
supportsReset
public boolean supportsReset()Description copied from interface:EventHandlingComponentIndicates whether this component supports reset operations.When
true, this component can participate in replay operations and itsEventHandlingComponent.handle(ResetContext, ProcessingContext)method will be called before replay begins.By default, reset is supported.
- Specified by:
supportsResetin interfaceEventHandlingComponent- Returns:
trueif this component supports reset operations,falseotherwise.
-
handle
Description copied from interface:ResetHandlerHandles the givenResetContextmessage, performing any necessary reset operations.This method is invoked before the processor begins replaying events. Handlers typically use this opportunity to clean up state that will be rebuilt during replay.
If this method completes exceptionally, the reset operation will be aborted and no replay will occur.
- Specified by:
handlein interfaceEventHandlingComponent- Specified by:
handlein interfaceResetHandler- Parameters:
resetContext- The reset context message containing reset information and optional payload.context- The processing context for this operation.- Returns:
- An empty message stream after handling completes successfully.
-
handle
public MessageStream.Empty<Message> handle(ReplayStatusChanged statusChange, ProcessingContext context) Description copied from interface:ReplayStatusChangedHandlerHandles the givenReplayStatusChangedmessage, allowing for tasks to be performed when thereplay startsandends.This method is invoked on the moment the
ReplayStatusis about to change as part of the event handlingProcessingContext. In doing so, this handler has two concrete moments when it is invoked:- When the
ReplayStatuschanges fromReplayStatus.REGULARtoReplayStatus.REPLAY, exactly before the first replayed event is processed - When the
ReplayStatuschanges fromReplayStatus.REPLAYtoReplayStatus.REGULAR, exactly after processing the final event of the replay
If this operation returns a
failed MessageStream, event handling that occurs within the givencontextis impacted. The failure will be passed to theErrorHandler, typically resulting in a rollback of the invoked event handling tasks.- Specified by:
handlein interfaceEventHandlingComponent- Specified by:
handlein interfaceReplayStatusChangedHandler- Parameters:
statusChange- the replay status context message containing replay status informationcontext- the processing context for this operation- Returns:
- an empty message stream after handling completes successfully
- When the
-
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.
-