Class: StackifyRubyAPM::LogClient Private

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/stackify_apm/transport/log_client.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.

Constant Summary

Constants included from Log

StackifyRubyAPM::Log::PREFIX

Instance Method Summary collapse

Methods included from Log

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

Constructor Details

#initialize(config) ⇒ LogClient

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 LogClient.



12
13
14
15
# File 'lib/stackify_apm/transport/log_client.rb', line 12

def initialize(config)
  @config = config
  @transaction_serializers = Serializers::Transactions.new(@config)
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.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/stackify_apm/transport/log_client.rb', line 19

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

  current_datetime = Time.now.utc.strftime('%Y-%m-%d, %H:%M:%S.%6N')

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

  json_traces.each do |json_trace|
    @config.tracer_logger.<<("#{current_datetime} > #{json_trace} \n")
  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