Class MetadataSpanAttributesProvider

java.lang.Object
org.axonframework.messaging.tracing.attributes.MetadataSpanAttributesProvider
All Implemented Interfaces:
SpanAttributesProvider

public final class MetadataSpanAttributesProvider extends Object implements SpanAttributesProvider
Adds message metadata entries to the span, each under the key <prefix><metadataKey>.

By default the prefix is METADATA_PREFIX (axoniq.metadata.) and every metadata entry is added. The prefix can be overridden through the constructor. An optional allowlist restricts which metadata keys are added; an empty allowlist means all keys. Entries with a null value are skipped.

Besides the metadata already attached to the message, this provider also includes correlation data staged on the ProcessingContext under CorrelationDataInterceptor.CORRELATION_DATA. Dispatch-side spans are created by the outermost tracing decorators before the CorrelationDataInterceptor dispatch interceptor merges that staged data onto the outgoing message, so reading the staged resource lets the span report the metadata the message will effectively carry. Staged entries take precedence over message entries with the same key, mirroring the interceptor's merge. The allowlist applies to staged entries as well, so disabling or restricting this provider governs all metadata attributes in one place.

Since:
4.6.0
Author:
Mateusz Nowak, Mitchell Herrijgers
  • Field Details

    • METADATA_PREFIX

      public static final String METADATA_PREFIX
      Default prefix prepended to each metadata key to form the span attribute key.
      See Also:
  • Constructor Details

    • MetadataSpanAttributesProvider

      public MetadataSpanAttributesProvider()
      Creates a provider that adds all metadata entries under the default METADATA_PREFIX prefix.
    • MetadataSpanAttributesProvider

      public MetadataSpanAttributesProvider(Set<String> allowedKeys)
      Creates a provider that adds the given metadata keys (when present) under the default METADATA_PREFIX prefix. An empty set means all keys.
      Parameters:
      allowedKeys - the metadata keys to add, or an empty set for all keys
    • MetadataSpanAttributesProvider

      public MetadataSpanAttributesProvider(String prefix, Set<String> allowedKeys)
      Creates a provider that adds the given metadata keys (when present) under the given prefix. An empty allowlist means all keys.
      Parameters:
      prefix - the prefix prepended to each metadata key to form the span attribute key
      allowedKeys - the metadata keys to add, or an empty set for all keys
  • Method Details

    • provideForMessage

      public Map<String,String> provideForMessage(Message message, @Nullable ProcessingContext context)
      Description copied from interface: SpanAttributesProvider
      Provides the attributes this provider contributes for the given message and optional context.
      Specified by:
      provideForMessage in interface SpanAttributesProvider
      Parameters:
      message - the message the span is created for
      context - the active processing context, or null when none is available
      Returns:
      the attributes to add to the span; an empty map when this provider contributes nothing