java.lang.Object
dk.cloudcreate.essentials.shared.measurement.MeasurementTaker

public class MeasurementTaker extends Object
A facade to record the execution time of a given code block using one or more MeasurementRecorder instances.

Example of fluent usage:


 return measurementTaker.context("essentials.eventstore.append_to_stream")
                         .description("Time taken to append events to the event store")
                         .tag("aggregateType", operation.getAggregateType())
                         .record(chain::proceed);
 
 
or

 measurementTaker.recordTime(MeasurementContext.builder("essentials.invocation")
                                               .description("Time it takes to invoke a method")
                                               .tag("class", FunctionalInterfaceLoggingNameResolver.resolveLoggingName(invokeMethodsOn))
                                               .tag("method", methodLoggingName)
                                               .build(),
                             duration);
 
 
  • Method Details

    • builder

      public static MeasurementTaker.Builder builder()
      Creates a new Builder for constructing a MeasurementTaker.
      Returns:
      a new Builder instance
    • record

      public <T> T record(MeasurementContext context, Supplier<T> block)
      Executes the supplied block of code, measures its execution time, and notifies all configured recorders.
      Type Parameters:
      T - the type of result returned by the code block
      Parameters:
      context - the measurement context containing metric information
      block - the code block whose execution time is to be measured
      Returns:
      the result of executing the code block
    • recordTime

      public void recordTime(MeasurementContext context, Duration elapsed)
      Records an already measured duration.
      Parameters:
      context - the measurement context containing metric name, description and tags
      elapsed - the elapsed time to record
    • context

      Starts a fluent measurement configuration for the specified metric.
      Parameters:
      metricName - the name of the metric
      Returns:
      a fluent context builder for further configuration