Class MeasurementTaker.FluentMeasurementContext

java.lang.Object
dk.cloudcreate.essentials.shared.measurement.MeasurementTaker.FluentMeasurementContext
Enclosing class:
MeasurementTaker

public static class MeasurementTaker.FluentMeasurementContext extends Object
A fluent builder for constructing a measurement context and recording its execution.

Example 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);
 

  • Method Details

    • description

      public MeasurementTaker.FluentMeasurementContext description(String description)
      Sets the description for the measurement.
      Parameters:
      description - the description text
      Returns:
      this FluentMeasurementContext instance for fluent chaining
    • tag

      Adds a tag to the measurement.
      Parameters:
      key - the tag key
      value - the tag value
      Returns:
      this FluentMeasurementContext instance for fluent chaining
    • tag

      Adds a tag to the measurement.
      Parameters:
      key - the tag key
      value - the tag value
      Returns:
      this FluentMeasurementContext instance for fluent chaining
    • tag

      public MeasurementTaker.FluentMeasurementContext tag(String key, int value)
      Adds a tag to the measurement.
      Parameters:
      key - the tag key
      value - the tag value
      Returns:
      this FluentMeasurementContext instance for fluent chaining
    • record

      public <T> T record(Supplier<T> block)
      Executes the supplied code block, measuring its execution time using the built measurement context.
      Type Parameters:
      T - the type of result returned by the code block
      Parameters:
      block - the code block to execute and measure
      Returns:
      the result of executing the code block
    • optionalTag

      public MeasurementTaker.FluentMeasurementContext optionalTag(String key, String value)
      Adds an optional tag to the measurement. If the value is null then the tag isn't added
      Parameters:
      key - the tag key
      value - the tag value
      Returns:
      this FluentMeasurementContext instance for fluent chaining