Class: Chronos::Core::Breadcrumb

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

Overview

Immutable, bounded diagnostic marker attached to an execution.

Examples:

breadcrumb.to_h #=> {"category"=>"custom", ...}

Constant Summary collapse

CATEGORIES =
%w(custom log request query external_http cache job).freeze

Instance Method Summary collapse

Constructor Details

#initialize(attributes, clock = nil, max_bytes = 2048) ⇒ Breadcrumb

Returns a new instance of Breadcrumb.



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

def initialize(attributes, clock = nil, max_bytes = 2048)
  attributes = {} unless attributes.is_a?(Hash)
  clock ||= proc { Time.now }
  serializer = SafeSerializer.new(
    :max_depth => 5, :max_keys => 20, :max_items => 20,
    :max_string_bytes => 512, :max_nodes => 100
  )
  @data = serializer.call(build_data(attributes, clock))
  @data = compact_data(@data, max_bytes) if JSON.generate(@data).bytesize > max_bytes
  deep_freeze(@data)
  freeze
end

Instance Method Details

#to_hObject



34
35
36
# File 'lib/chronos/core/breadcrumb.rb', line 34

def to_h
  @data
end