Sha256: bd47fb04aa509604a6da6650591dfe0920531f1eee3cc947c144ae5a9a10f1b0

Contents?: true

Size: 1.93 KB

Versions: 5

Compression:

Stored size: 1.93 KB

Contents

# encoding: utf-8

require 'one_apm/support/marshaller'

module OneApm
  module Support
    class JsonMarshaller < Marshaller

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

      def initialize
        OneApm::Manager.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) < 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

      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

      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

      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

5 entries across 5 versions & 1 rubygems

Version Path
oneapm_rpm-1.4.2 lib/one_apm/support/json_marshaller.rb
oneapm_rpm-1.4.1 lib/one_apm/support/json_marshaller.rb
oneapm_rpm-1.4.0 lib/one_apm/support/json_marshaller.rb
oneapm_rpm-1.3.7 lib/one_apm/support/json_marshaller.rb
oneapm_rpm-1.3.7.rc1 lib/one_apm/support/json_marshaller.rb