Class MicrometerThreadLocalContextPropagationConfigurationEnhancer
- All Implemented Interfaces:
ConfigurationEnhancer
ConfigurationEnhancer that installs the Micrometer thread-local trace-context-propagation bridge. Discovered
automatically via ServiceLoader, so having the axoniq-tracing-micrometer module on the classpath is enough.
It does two things:
- decorates the
UnitOfWorkFactorywith aThreadLocalContextPropagatingUnitOfWorkFactory, which restores the dispatching thread's captured thread-locals (and makes the per-action Axon span current) on the framework's worker threads; and - registers the
ObservationAwareSpanThreadLocalAccessoron theContextRegistrycomponent (the thread-local counterpart that turns a captured span back into the current span onContextSnapshot.setThreadLocals()).
SpanFactory. The
enhancer backs off entirely (with an INFO log) when no Tracer component is registered, and the
decorators back off when no SpanFactory component exists at all -- the jar being on the classpath never breaks
a configuration that does not wire tracing. If a SpanFactory is configured but is a different
implementation than MicrometerSpanFactory, an IllegalStateException is raised rather than silently
skipping -- configure the Micrometer SpanFactory or disable this bridge.
This governs only the in-process, thread-local bridge. Cross-service trace-context propagation (via the
Propagator over message metadata) is part of core tracing and is unaffected by disabling this enhancer. To
turn this bridge off, call ComponentRegistry.disableEnhancer(Class) with this class.
The ContextSnapshotFactory that captures the dispatching thread's thread-locals is registered as a component
via ComponentRegistry.registerIfNotPresent(java.lang.Class<C>, org.axonframework.common.configuration.ComponentBuilder<? extends C>) (built from the ContextRegistry component), so a
user-registered factory takes precedence.
- Since:
- 5.3.0
- Author:
- Mateusz Nowak
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDecorator order for the thread-local context-propagation decorator. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidenhance(ComponentRegistry registry) intorder()Returns the relative order this enhancer should be invoked in, compared to other instances.
-
Field Details
-
DECORATOR_ORDER
public static final int DECORATOR_ORDERDecorator order for the thread-local context-propagation decorator. A low value keeps it near the delegate; its position relative to otherUnitOfWorkFactorydecorators is immaterial because it only composes an action interceptor onto the created unit of work's configuration.- See Also:
-
-
Constructor Details
-
MicrometerThreadLocalContextPropagationConfigurationEnhancer
public MicrometerThreadLocalContextPropagationConfigurationEnhancer()
-
-
Method Details
-
enhance
Description copied from interface:ConfigurationEnhancer- Specified by:
enhancein interfaceConfigurationEnhancer- Parameters:
registry- The registry instance to enhance.
-
order
public int order()Description copied from interface:ConfigurationEnhancerReturns the relative order this enhancer should be invoked in, compared to other instances.Use lower (negative) values for enhancers providing sensible defaults, and higher values for enhancers that should be able to override values potentially previously set. Defaults to
0when not set.- Specified by:
orderin interfaceConfigurationEnhancer- Returns:
- The order in which this enhancer should be invoked.
-