Class: StackifyRubyAPM::AWSLoggerClient Private

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/stackify_apm/transport/aws_lambda_logging.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

API:

  • private

Constant Summary collapse

COMPRESS_DEFAULT_LEVEL =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

6

Constants included from Log

Log::PREFIX

Instance Method Summary collapse

Methods included from Log

#debug, #error, #fatal, #info, #log, #warn

Constructor Details

#initialize(config) ⇒ AWSLoggerClient

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of AWSLoggerClient.

API:

  • private



15
16
17
18
19
20
21
22
23
# 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

Instance Method Details

#post(transactions = []) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

API:

  • private



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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