Class: Chronos::Core::CorrelationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/chronos/core/correlation_context.rb

Overview

Builds the bounded release/deploy correlation shared by every event envelope.

Examples:

CorrelationContext.new(config).call("revision" => "abc123")

Constant Summary collapse

FIELDS =
%w(release revision deploy_id environment service region instance).freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CorrelationContext

Returns a new instance of CorrelationContext.



18
19
20
# File 'lib/chronos/core/correlation_context.rb', line 18

def initialize(config)
  @config = config
end

Instance Method Details

#call(overrides = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/chronos/core/correlation_context.rb', line 22

def call(overrides = {})
  values = defaults.merge(string_hash(overrides))
  result = FIELDS.each_with_object({}) do |name, correlation|
    correlation[name.freeze] = bounded(values[name], 128)
  end
  result.each_value { |value| value.freeze if value }
  result.freeze
rescue StandardError
  FIELDS.each_with_object({}) { |name, fallback| fallback[name] = nil }.freeze
end