Class MetricsContextTimer

  • All Implemented Interfaces:
    ContextTimer

    public class MetricsContextTimer
    extends Object
    implements ContextTimer
    A ContextTimer implementation that locates an appropriate shared metric registry. Then it registers a new Timer for context switches and updates it.

    Shared metric registry resolution

    What an appropriate shared metric registry is, is rather complex and determined by the following rules:

    1. First, if a contextpropagation.metrics.registry system property is defined, the shared metric registry by that name will be used for all context related timers.
    2. Alternatively, the environment property CONTEXTPROPAGATION_METRICS_REGISTRY serves the same purpose if the system property is not defined.
    3. Next, if there is a default shared metric registry, that one is used.
    4. Otherwise:
      • If there is exactly one shared registry, that one is used instead of the default.
      • If there are no shared registries yet, a new one is created by the name "ContextPropagationMetrics".
      • Otherwise we cannot sensibly choose and try to register new timers to all shared registries.

    Timers, once created, will not be retroactively registered to other shared registries.

    Author:
    Sjoerd Talsma
    • Constructor Detail

      • MetricsContextTimer

        public MetricsContextTimer()
    • Method Detail

      • update

        public void update​(Class<?> type,
                           String method,
                           long duration,
                           TimeUnit unit)
        Description copied from interface: ContextTimer
        Provides a new update for the context timer.
        Specified by:
        update in interface ContextTimer
        Parameters:
        type - The class being called
        method - The method being called
        duration - The duration of the method
        unit - The unit of the duration