Metrics and Management

This section describes how to capture metrics for Spring Integration. In recent versions, we have relied more on Micrometer (see micrometer.io), and we plan to use Micrometer even more in future releases.spring-doc.cn

Disabling Logging in High Volume Environments

You can control debug logging in the main message flow. In very high volume applications, calls to isDebugEnabled() can be quite expensive with some logging subsystems. You can disable all such logging to avoid this overhead. Exception logging (debug or otherwise) is not affected by this setting.spring-doc.cn

The following listing shows the available options for controlling logging:spring-doc.cn

@Configuration
@EnableIntegration
@EnableIntegrationManagement(
    defaultLoggingEnabled = "true" <1>)

public static class ContextConfiguration {
...
}
<int:management default-logging-enabled="true"/> (1)
1 Set to false to disable all logging in the main message flow, regardless of the log system category settings. Set to 'true' to enable debug logging (if also enabled by the logging subsystem). Only applied if you have not explicitly configured the setting in a bean definition. The default is true.
defaultLoggingEnabled is applied only if you have not explicitly configured the corresponding setting in a bean definition.

Micrometer Integration

Overview

Starting with version 5.0.3, the presence of a Micrometer MeterRegistry in the application context triggers support for Micrometer metrics.spring-doc.cn

To use Micrometer, add one of the MeterRegistry beans to the application context.spring-doc.cn

For each MessageHandler and MessageChannel, timers are registered. For each MessageSource, a counter is registered.spring-doc.cn

This only applies to objects that extend AbstractMessageHandler, AbstractMessageChannel, and AbstractMessageSource (which is the case for most framework components).spring-doc.cn

The Timer Meters for send operations on message channels have the following names or tags:spring-doc.cn

(A failure result with a none exception means the channel’s send() operation returned false.)spring-doc.cn

The Counter Meters for receive operations on pollable message channels have the following names or tags:spring-doc.cn

The Timer Meters for operations on message handlers have the following names or tags:spring-doc.cn

The Counter meters for message sources have the following names/tags:spring-doc.cn

In addition, there are three Gauge Meters:spring-doc.cn

  • spring.integration.channels: The number of MessageChannels in the application.spring-doc.cn

  • spring.integration.handlers: The number of MessageHandlers in the application.spring-doc.cn

  • spring.integration.sources: The number of MessageSources in the application.spring-doc.cn

It is possible to customize the names and tags of Meters created by integration components by providing a subclass of MicrometerMetricsCaptor. The MicrometerCustomMetricsTests test case shows a simple example of how to do that. You can also further customize the meters by overloading the build() methods on builder subclasses.spring-doc.cn

Starting with version 5.1.13, the QueueChannel exposes Micrometer gauges for queue size and remaining capacity:spring-doc.cn

Disabling Meters

By default, all meters are registered when first used. Now, with Micrometer, you can add MeterFilter s to the MeterRegistry to prevent some or all from being registered. You can filter out (deny) meters by any of the properties provided, name, tag, etc. See Meter Filters in the Micrometer documentation for more information.spring-doc.cn

For example, given:spring-doc.cn

@Bean
public QueueChannel noMeters() {
    return new QueueChannel(10);
}

You can suppress registration of meters for just this channel with:spring-doc.cn

registry.config().meterFilter(MeterFilter.deny(id ->
        "channel".equals(id.getTag("type")) &&
        "noMeters".equals(id.getTag("name"))));

Micrometer Observation

Starting with version 6.0, Spring Integration utilizes a Micrometer Observation abstraction which can handle metrics as well as tracing via appropriate ObservationHandler configuration.spring-doc.cn

The observation handling is enabled on the IntegrationManagement components whenever an ObservationRegistry bean is present in the application context and an @EnableIntegrationManagement is configured. To customize what set of components should be instrumented, an observationPatterns() attribute is exposed on the @EnableIntegrationManagement annotation. See its javadocs for a pattern matching algorithm.spring-doc.cn

By default, none of the IntegrationManagement components are instrumented with an ObservationRegistry bean. Can be configured as * to match all components.

The meters are not gathered in this case independently, but delegated to an appropriate ObservationHandler configured on the provided ObservationRegistry.spring-doc.cn

The following Spring Integration components are instrumented with observation logic each with a respective convention:spring-doc.cn

  • MessageProducerSupport, being the inbound endpoint of the flow, is considered as a CONSUMER span type and uses the IntegrationObservation.HANDLER API;spring-doc.cn

  • MessagingGatewaySupport` is an inbound request-reply endpoint, and is considered as a SERVER span type. It uses the IntegrationObservation.GATEWAY API;spring-doc.cn

  • An AbstractMessageChannel.send() operation is the only Spring Integration API where it produces messages. So, it is treated as a PRODUCER span type and uses the IntegrationObservation.PRODCUER API. This makes more sense when a channel is a distributed implementation (e.g. PublishSubscribeKafkaChannel or ZeroMqChannel) and trace information has to be added to the message. So, the IntegrationObservation.PRODUCER observation is based on a MessageSenderContext where Spring Integration supplies a MutableMessage to allow a subsequent tracing Propagator to add headers, so they are available to the consumer;spring-doc.cn

  • An AbstractMessageHandler is a CONSUMER span type and uses the IntegrationObservation.HANDLER API.spring-doc.cn

An observation production on the IntegrationManagement components can be customized via ObservationConvention configuration. For example an AbstractMessageHandler expects a MessageReceiverObservationConvention via its setObservationConvention() API.spring-doc.cn

The following are supported metrics, spans and conventions for Observation API:spring-doc.cn

Observability - Metrics

Below you can find a list of all metrics declared by this project.spring-doc.cn

Gateway

Observation for inbound message gateways.spring-doc.cn

Metric name spring.integration.gateway (defined by convention class o.s.i.support.management.observation.DefaultMessageRequestReplyReceiverObservationConvention). Type timer.spring-doc.cn

Metric name spring.integration.gateway.active (defined by convention class o.s.i.support.management.observation.DefaultMessageRequestReplyReceiverObservationConvention). Type long task timer.spring-doc.cn

KeyValues that are added after starting the Observation might be missing from the *.active metrics.
Micrometer internally uses nanoseconds for the baseunit. However, each backend determines the actual baseunit. (i.e. Prometheus uses seconds)

Fully qualified name of the enclosing class o.s.i.support.management.observation.IntegrationObservation.spring-doc.cn

All tags must be prefixed with spring.integration. prefix!
Table 1. Low cardinality Keys

Descriptionspring-doc.cn

spring.integration.name (required)spring-doc.cn

Name of the message gateway component.spring-doc.cn

spring.integration.outcome (required)spring-doc.cn

Outcome of the request/reply execution.spring-doc.cn

spring.integration.type (required)spring-doc.cn

Type of the component - 'gateway'.spring-doc.cn

Handler

Observation for message handlers.spring-doc.cn

Metric name spring.integration.handler (defined by convention class o.s.i.support.management.observation.DefaultMessageReceiverObservationConvention). Type timer.spring-doc.cn

Metric name spring.integration.handler.active (defined by convention class o.s.i.support.management.observation.DefaultMessageReceiverObservationConvention). Type long task timer.spring-doc.cn

KeyValues that are added after starting the Observation might be missing from the *.active metrics.
Micrometer internally uses nanoseconds for the baseunit. However, each backend determines the actual baseunit. (i.e. Prometheus uses seconds)

Fully qualified name of the enclosing class o.s.i.support.management.observation.IntegrationObservation.spring-doc.cn

All tags must be prefixed with spring.integration. prefix!
Table 2. Low cardinality Keys

Descriptionspring-doc.cn

spring.integration.name (required)spring-doc.cn

Name of the message handler component.spring-doc.cn

spring.integration.type (required)spring-doc.cn

Type of the component - 'handler'.spring-doc.cn

Producer

Observation for message producers, e.g. channels.spring-doc.cn

Metric name spring.integration.producer (defined by convention class o.s.i.support.management.observation.DefaultMessageSenderObservationConvention). Type timer.spring-doc.cn

Metric name spring.integration.producer.active (defined by convention class o.s.i.support.management.observation.DefaultMessageSenderObservationConvention). Type long task timer.spring-doc.cn

KeyValues that are added after starting the Observation might be missing from the *.active metrics.
Micrometer internally uses nanoseconds for the baseunit. However, each backend determines the actual baseunit. (i.e. Prometheus uses seconds)

Fully qualified name of the enclosing class o.s.i.support.management.observation.IntegrationObservation.spring-doc.cn

All tags must be prefixed with spring.integration. prefix!
Table 3. Low cardinality Keys

Descriptionspring-doc.cn

spring.integration.name (required)spring-doc.cn

Name of the message handler component.spring-doc.cn

spring.integration.type (required)spring-doc.cn

Type of the component - 'producer'.spring-doc.cn

Observability - Spans

Below you can find a list of all spans declared by this project.spring-doc.cn

Gateway Span

Observation for inbound message gateways.spring-doc.cn

Span name spring.integration.gateway (defined by convention class o.s.i.support.management.observation.DefaultMessageRequestReplyReceiverObservationConvention).spring-doc.cn

Fully qualified name of the enclosing class o.s.i.support.management.observation.IntegrationObservation.spring-doc.cn

All tags must be prefixed with spring.integration. prefix!
Table 4. Tag Keys

Namespring-doc.cn

Descriptionspring-doc.cn

spring.integration.name (required)spring-doc.cn

Name of the message gateway component.spring-doc.cn

spring.integration.outcome (required)spring-doc.cn

Outcome of the request/reply execution.spring-doc.cn

spring.integration.type (required)spring-doc.cn

Type of the component - 'gateway'.spring-doc.cn

Handler Span

Observation for message handlers.spring-doc.cn

Span name spring.integration.handler (defined by convention class o.s.i.support.management.observation.DefaultMessageReceiverObservationConvention).spring-doc.cn

Fully qualified name of the enclosing class o.s.i.support.management.observation.IntegrationObservation.spring-doc.cn

All tags must be prefixed with spring.integration. prefix!
Table 5. Tag Keys

Namespring-doc.cn

Descriptionspring-doc.cn

spring.integration.name (required)spring-doc.cn

Name of the message handler component.spring-doc.cn

spring.integration.type (required)spring-doc.cn

Type of the component - 'handler'.spring-doc.cn

Producer Span

Observation for message producers, e.g. channels.spring-doc.cn

Span name spring.integration.producer (defined by convention class o.s.i.support.management.observation.DefaultMessageSenderObservationConvention).spring-doc.cn

Fully qualified name of the enclosing class o.s.i.support.management.observation.IntegrationObservation.spring-doc.cn

All tags must be prefixed with spring.integration. prefix!
Table 6. Tag Keys

Namespring-doc.cn

Descriptionspring-doc.cn

spring.integration.name (required)spring-doc.cn

Name of the message handler component.spring-doc.cn

spring.integration.type (required)spring-doc.cn

Type of the component - 'producer'.spring-doc.cn

Observability - Conventions

Below you can find a list of all GlobalObservationConvention and ObservationConvention declared by this project.spring-doc.cn

Table 7. ObservationConvention implementations

ObservationConvention Class Namespring-doc.cn

Applicable ObservationContext Class Namespring-doc.cn

o.s.i.support.management.observation.DefaultMessageReceiverObservationConventionspring-doc.cn

MessageReceiverContextspring-doc.cn

o.s.i.support.management.observation.MessageReceiverObservationConventionspring-doc.cn

MessageReceiverContextspring-doc.cn

o.s.i.support.management.observation.DefaultMessageRequestReplyReceiverObservationConventionspring-doc.cn

MessageRequestReplyReceiverContextspring-doc.cn

o.s.i.support.management.observation.MessageRequestReplyReceiverObservationConventionspring-doc.cn

MessageRequestReplyReceiverContextspring-doc.cn

o.s.i.support.management.observation.DefaultMessageSenderObservationConventionspring-doc.cn

MessageSenderContextspring-doc.cn

o.s.i.support.management.observation.MessageSenderObservationConventionspring-doc.cn

MessageSenderContextspring-doc.cn

Observation Propagation

To supply a connected chain of spans in one trace, independently of the nature of the messaging flow, even if a MessageChannel is persistent and distributed, the observation must be enabled on this channel and on consumers (subscribers) for this channel. This way, the tracing information is stored in the message headers before it is propagated to a consumer thread or persisted into the database. This is done via mentioned above MessageSenderContext. The consumer (a MessageHandler) side restores tracing information from those headers using a MessageReceiverContext and starts a new child Observation.spring-doc.cn

Spring Integration JMX Support