module Elastics::Instrumentation

Constants

PRETTIFIERS

Public Class Methods

body_prettifier=(value) click to toggle source
# File lib/elastics/instrumentation.rb, line 12
def body_prettifier=(value)
  @body_prettifier = case value
  when Proc, nil, false then value
  else PRETTIFIERS[value] or raise 'Invalid prettifier'
  end
end
prettify_body(str) click to toggle source
# File lib/elastics/instrumentation.rb, line 19
def prettify_body(str)
  if @body_prettifier
    @body_prettifier.call(str)
  else
    str
  end
end
prettify_json(str, &block) click to toggle source
# File lib/elastics/instrumentation.rb, line 27
def prettify_json(str, &block)
  data = [JSON.parse(str)] rescue nil
  data ||= str.split("\n").map { |x| JSON.parse(x) } rescue nil
  if data
    data.map(&block).join("\n")
  else
    str
  end
end