Class: NewRelic::Agent::NewRelicService::JsonMarshaller

Inherits:
Marshaller
  • Object
show all
Defined in:
lib/new_relic/agent/new_relic_service/json_marshaller.rb

Overview

Marshal collector protocol with JSON when available

Constant Summary collapse

OK_YAJL_VERSION =
Gem::Version.new('1.2.1')

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Marshaller

#prepare

Constructor Details

#initializeJsonMarshaller

Returns a new instance of JsonMarshaller.



13
14
15
# File 'lib/new_relic/agent/new_relic_service/json_marshaller.rb', line 13

def initialize
  warn_for_yajl
end

Class Method Details

.human_readable?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/new_relic/agent/new_relic_service/json_marshaller.rb', line 63

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

Instance Method Details

#default_encoderObject



51
52
53
54
55
56
57
# File 'lib/new_relic/agent/new_relic_service/json_marshaller.rb', line 51

def default_encoder
  if NewRelic::Agent.config[:simple_compression]
    Encoders::Identity
  else
    Encoders::Base64CompressedJSON
  end
end

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



30
31
32
33
34
35
36
37
38
# File 'lib/new_relic/agent/new_relic_service/json_marshaller.rb', line 30

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

  if !opts[:skip_normalization] && Agent.config[:normalize_json_string_encodings]
    prepared = NewRelic::Agent::EncodingNormalizer.normalize_object(prepared)
  end

  ::JSON.dump(prepared)
end

#formatObject



59
60
61
# File 'lib/new_relic/agent/new_relic_service/json_marshaller.rb', line 59

def format
  'json'
end

#load(data) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/new_relic/agent/new_relic_service/json_marshaller.rb', line 40

def load(data)
  if data.nil? || data.empty?
    return nil
  end

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

#warn_for_yajlObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/new_relic/agent/new_relic_service/json_marshaller.rb', line 19

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