Class: OneApm::Support::JsonMarshaller

Inherits:
Marshaller
  • Object
show all
Defined in:
lib/one_apm/support/json_marshaller.rb

Constant Summary collapse

OA_OK_YAJL_VERSION =
OneApm::VersionNumber.new("1.2.1")

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Marshaller

#parsed_error, #prepare

Constructor Details

#initializeJsonMarshaller

Returns a new instance of JsonMarshaller.



11
12
13
14
# File 'lib/one_apm/support/json_marshaller.rb', line 11

def initialize
  OneApm::Manager.logger.info "Using JSON marshaller (#{OneApm::JSONWrapper.backend_name})"
  warn_for_yajl
end

Class Method Details

.human_readable?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/one_apm/support/json_marshaller.rb', line 63

def self.human_readable?
  true # for some definitions of 'human'
end

.is_supported?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/one_apm/support/json_marshaller.rb', line 55

def self.is_supported?
  OneApm::JSONWrapper.usable_for_collector_serialization?
end

Instance Method Details

#default_encoderObject



51
52
53
# File 'lib/one_apm/support/json_marshaller.rb', line 51

def default_encoder
  Encoders::Base64CompressedJSON
end

#dump(ruby, opts = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/one_apm/support/json_marshaller.rb', line 27

def dump(ruby, opts={})
  prepared = prepare(ruby, opts)

  if opts[:skip_normalization]
    normalize_encodings = false
  else
    normalize_encodings = OneApm::Manager.config[:normalize_json_string_encodings]
  end

  OneApm::JSONWrapper.dump prepared, :normalize => normalize_encodings
end

#formatObject



59
60
61
# File 'lib/one_apm/support/json_marshaller.rb', line 59

def format
  'json'
end

#load(data) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/one_apm/support/json_marshaller.rb', line 39

def load(data)
  if data.nil? || data.empty?
    OneApm::Manager.logger.error "Empty JSON response from collector: '#{data.inspect}'"
    return nil
  end

  return_value OneApm::JSONWrapper.load(data)
rescue => e
  OneApm::Manager.logger.debug "#{e.class.name} : #{e.message} encountered loading collector response: #{data}"
  raise
end

#warn_for_yajlObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/one_apm/support/json_marshaller.rb', line 16

def warn_for_yajl
  if defined?(::Yajl)
    require 'yajl/version'
    if OneApm::VersionNumber.new(::Yajl::VERSION) < OA_OK_YAJL_VERSION
      OneApm::Manager.logger.warn "Detected yajl-ruby version #{::Yajl::VERSION} which can cause segfaults with oneapm_rpm's thread profiling features. We strongly recommend you upgrade to the latest yajl-ruby version available."
    end
  end
rescue => err
  OneApm::Manager.logger.warn "Failed trying to watch for problematic yajl-ruby version.", err
end