Sha256: e59871e15cbbe9dad9f93c930680d1989dca43510c673ec8fc936142c6e8fa8c

Contents?: true

Size: 1.48 KB

Versions: 13

Compression:

Stored size: 1.48 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

require 'json'
require 'stringio'
require 'zlib'
require 'new_relic/base64'

module NewRelic
  module Agent
    class NewRelicService
      module Encoders
        module Identity
          def self.encode(data, opts = nil)
            data
          end
        end

        module Compressed
          module Deflate
            def self.encode(data, opts = nil)
              Zlib::Deflate.deflate(data, Zlib::DEFAULT_COMPRESSION)
            end
          end

          module Gzip
            BINARY = 'BINARY'.freeze

            def self.encode(data, opts = nil)
              output = StringIO.new
              output.set_encoding(BINARY)
              gz = Zlib::GzipWriter.new(output, Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY)
              gz.write(data)
              gz.close
              output.rewind
              output.string
            end
          end
        end

        module Base64CompressedJSON
          def self.encode(data, opts = {})
            if !opts[:skip_normalization] && Agent.config[:normalize_json_string_encodings]
              data = NewRelic::Agent::EncodingNormalizer.normalize_object(data)
            end
            json = ::JSON.dump(data)
            NewRelic::Base64.encode64(Compressed::Deflate.encode(json))
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
newrelic_rpm-9.16.0 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.13.0 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.11.0 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.10.2 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.10.1 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.10.0 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.9.0 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.8.0 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.7.1 lib/new_relic/agent/new_relic_service/encoders.rb
newrelic_rpm-9.7.0 lib/new_relic/agent/new_relic_service/encoders.rb