Module: Labkit::CoveredExperience

Defined in:
lib/labkit/covered_experience.rb,
lib/labkit/covered_experience/null.rb,
lib/labkit/covered_experience/error.rb,
lib/labkit/covered_experience/current.rb,
lib/labkit/covered_experience/registry.rb,
lib/labkit/covered_experience/experience.rb

Overview

Labkit::CoveredExperience namespace module.

This module is responsible for managing covered experiences, which are specific events or activities within the application that are measured and reported for performance monitoring and analysis.

Defined Under Namespace

Classes: Configuration, Current, Experience, Null, Registry

Constant Summary collapse

CoveredExperienceError =
Class.new(StandardError)
NotFoundError =
Class.new(CoveredExperienceError)
ReservedKeywordError =
Class.new(CoveredExperienceError)
Definition =
Data.define(:covered_experience, :description, :feature_category, :urgency)
URGENCY_THRESHOLDS_IN_SECONDS =
{
  sync_fast: 2,
  sync_slow: 5,
  async_fast: 15,
  async_slow: 300
}.freeze
RESERVED_KEYWORDS =
%w[
  checkpoint
  covered_experience
  feature_category
  urgency
  start_time
  checkpoint_time
  end_time
  elapsed_time_s
  urgency_threshold_s
  error
  error_message
  success
].freeze

Class Method Summary collapse

Class Method Details

.configurationObject



28
29
30
# File 'lib/labkit/covered_experience.rb', line 28

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



36
37
38
39
40
# File 'lib/labkit/covered_experience.rb', line 36

def configure
  yield(configuration) if block_given?
  # Reset registry when configuration changes to pick up new registry_path
  @registry = nil
end

.get(experience_id) ⇒ Experience, Null

Retrieves a covered experience using the experience_id. It retrieves from the current context when available, otherwise it instantiates a new experience with the definition from the registry.

Parameters:

  • experience_id (String, Symbol)

    The ID of the experience to retrieve.

Returns:

  • (Experience, Null)

    The found experience or a Null object if not found (in production/staging).



58
59
60
# File 'lib/labkit/covered_experience.rb', line 58

def get(experience_id)
  find_current(experience_id) || raise_or_null(experience_id)
end

.registryObject



42
43
44
# File 'lib/labkit/covered_experience.rb', line 42

def registry
  @registry ||= Registry.new(dir: configuration.registry_path)
end

.resetObject



46
47
48
49
# File 'lib/labkit/covered_experience.rb', line 46

def reset
  @registry = nil
  reset_configuration
end

.reset_configurationObject



32
33
34
# File 'lib/labkit/covered_experience.rb', line 32

def reset_configuration
  @configuration = nil
end

.resume(experience_id, **extra) ⇒ Experience, Null

Resumes a covered experience using the experience_id.

Parameters:

  • experience_id (String, Symbol)

    The ID of the experience to resume.

Returns:

  • (Experience, Null)

    The started experience or a Null object if not found (in production/staging).



75
76
77
# File 'lib/labkit/covered_experience.rb', line 75

def resume(experience_id, **extra, &)
  get(experience_id).resume(**extra, &)
end

.start(experience_id, **extra) ⇒ Experience, Null

Starts a covered experience using the experience_id.

Parameters:

  • experience_id (String, Symbol)

    The ID of the experience to start.

  • extra (Hash)

    Additional data to include in the log event.

Returns:

  • (Experience, Null)

    The started experience or a Null object if not found (in production/staging).



67
68
69
# File 'lib/labkit/covered_experience.rb', line 67

def start(experience_id, **extra, &)
  get(experience_id).start(**extra, &)
end