Sha256: d6990eb0d23c0db4eda10b9b7db49e0369fa628b9cad6ccaae0f366755272174

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

# encoding: utf-8

require 'one_apm/support/marshaller'

module OneApm
  module Support
    class JsonMarshaller < Marshaller

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

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

      def warn_for_yajl
        if defined?(::Yajl)
          require 'yajl/version'
          if OneApm::VersionNumber.new(::Yajl::VERSION) < OK_YAJL_VERSION
            ::OneApm::Agent.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::Agent.logger.warn "Failed trying to watch for problematic yajl-ruby version.", err
      end

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

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

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

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

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

      def default_encoder
        Encoders::Base64CompressedJSON
      end

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

      def format
        'json'
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oneapm_rpm-1.1.2 lib/one_apm/support/json_marshaller.rb
oneapm_rpm-1.1.1 lib/one_apm/support/json_marshaller.rb
oneapm_rpm-1.1.0 lib/one_apm/support/json_marshaller.rb