Class MicrometerThreadLocalContextPropagationConfigurationEnhancer

java.lang.Object
io.axoniq.framework.tracing.micrometer.threadlocal.MicrometerThreadLocalContextPropagationConfigurationEnhancer
All Implemented Interfaces:
ConfigurationEnhancer

@Internal @RegistrationScope("Register the UnitOfWorkFactory decorator once at the root; do not re-invoke in child module registries (the DecoratorDefinition is copied down and reaches module-built factories on its own).") public final class MicrometerThreadLocalContextPropagationConfigurationEnhancer extends Object implements 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:
  1. decorates the UnitOfWorkFactory with a ThreadLocalContextPropagatingUnitOfWorkFactory, which restores the dispatching thread's captured thread-locals (and makes the per-action Axon span current) on the framework's worker threads; and
  2. registers the ObservationAwareSpanThreadLocalAccessor on the ContextRegistry component (the thread-local counterpart that turns a captured span back into the current span on ContextSnapshot.setThreadLocals()).
Together these let instrumented JDBC/gRPC/WebClient calls and MDC logging nest under the active Axon span. Resolution is lazy -- deferred to framework-configuration time -- so it observes the finally-registered 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 Details

    • DECORATOR_ORDER

      public static final int DECORATOR_ORDER
      Decorator order for the thread-local context-propagation decorator. A low value keeps it near the delegate; its position relative to other UnitOfWorkFactory decorators 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

      public void enhance(ComponentRegistry registry)
      Description copied from interface: ConfigurationEnhancer
      Enhances the given registry with, for example, additional components and decorators.
      Specified by:
      enhance in interface ConfigurationEnhancer
      Parameters:
      registry - The registry instance to enhance.
    • order

      public int order()
      Description copied from interface: ConfigurationEnhancer
      Returns 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 0 when not set.

      Specified by:
      order in interface ConfigurationEnhancer
      Returns:
      The order in which this enhancer should be invoked.