Module: Julewire::GCP::FormatterOptions

Defined in:
lib/julewire/gcp/formatter_options.rb

Constant Summary collapse

ALLOWED_KEYS =
%i[
  label_formatter
  label_options
  max_label_key_bytes
  max_label_value_bytes
  max_labels
  span_id_path
  trace_id_path
  trace_sampled_path
].freeze

Class Method Summary collapse

Class Method Details

.label_formatter(options) ⇒ Object



30
31
32
# File 'lib/julewire/gcp/formatter_options.rb', line 30

def label_formatter(options)
  options[:label_formatter] || LabelFormatter.new(**label_options(options))
end

.label_options(options) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/julewire/gcp/formatter_options.rb', line 34

def label_options(options)
  label_options = options.fetch(:label_options, {}).dup
  %i[max_labels max_label_key_bytes max_label_value_bytes].each do |key|
    label_options[key] = options[key] if options.key?(key)
  end
  label_options
end

.trace_headers_paths(paths) ⇒ Object



22
23
24
# File 'lib/julewire/gcp/formatter_options.rb', line 22

def trace_headers_paths(paths)
  Array(paths).filter_map { normalize_path(it, min_length: 1) }.freeze
end

.trace_value_path(path) ⇒ Object



26
27
28
# File 'lib/julewire/gcp/formatter_options.rb', line 26

def trace_value_path(path)
  normalize_path(path, min_length: 2)
end

.validate!(options) ⇒ Object



18
19
20
# File 'lib/julewire/gcp/formatter_options.rb', line 18

def validate!(options)
  Core::Validation.validate_options!(options, ALLOWED_KEYS, name: :formatter)
end