Class MetricsInterceptor

java.lang.Object
com.shri.restinpeace.interceptor.MetricsInterceptor
All Implemented Interfaces:
RequestInterceptor

public class MetricsInterceptor extends Object implements RequestInterceptor
Pre-built interceptor that times every request and reports it, once its response comes back, to a MetricsSink - the metrics counterpart of LoggingInterceptor, following the exact same "bring your own sink" shape so RIP doesn't have to depend on Micrometer or any other metrics library to support one.

Register this first, before any other interceptor, if it should measure the total time a call takes including every other interceptor's own work; register it last if it should measure only the network call itself - the same registration-order tradeoff RequestInterceptor's own javadoc describes.

Only a call that actually receives a response is reported - a transport failure (no response at all) never reaches afterResponse, so it produces no sample through this interceptor. A @Retry'd call reports one sample per attempt, since every attempt gets its own afterResponse notification.

  • Constructor Details

    • MetricsInterceptor

      public MetricsInterceptor(MetricsSink sink)
      Reports each call's metrics to the given sink.
      Parameters:
      sink - receives one call's metrics per completed response
  • Method Details