class StackifyRubyAPM::AWSLoggerClient

This class will handle the writing of messages through a logfile. @api private

Constants

COMPRESS_DEFAULT_LEVEL

Public Class Methods

new(config) click to toggle source
# File lib/stackify_apm/transport/aws_lambda_logging.rb, line 15
def initialize(config)
  @config = config
  @transaction_serializers = Serializers::Transactions.new(@config)
  @logger = Logger.new(STDOUT)
  @logger.level = :debug
  @logger.formatter = proc do |severity, datetime, progname, msg|
    "STACKIFY-TRACE: #{msg}\n"
  end
end

Public Instance Methods

post(transactions = []) click to toggle source

This method will build an Array of Transactions in a json format. It will accept Array of transactions.

# File lib/stackify_apm/transport/aws_lambda_logging.rb, line 27
def post(transactions = [])
  # convert transactions to json
  json_traces = []
  transactions.each  do |transaction|
    # convert transaction to json
    json_transaction = @transaction_serializers.build_json(@config, transaction).to_json

    # add to json traces array
    json_traces.push(json_transaction)
  end

  return unless ENV['STACKIFY_RUBY_ENV'] != 'rspec'

  json_traces.each do |json_trace|
    str = StringIO.new mode='w'
    gz = Zlib::GzipWriter.new str, 6
    gz.write json_trace.to_s
    gz.close
    compressed = Base64.strict_encode64 str.string
    @logger.debug compressed
  end
  debug '[LogClient] post() Successfully write to logfile.' if ENV['STACKIFY_TRANSPORT_LOG_LEVEL'] == '0'
rescue StandardError => e
  debug "[LogClient] post() exception: #{e.inspect}"
end