class StackifyRubyAPM::AgentHTTPClient
This class will handle the sending of transaction messages through HTTP. @api private
Public Class Methods
new(config)
click to toggle source
Calls superclass method
StackifyRubyAPM::AgentBaseTransport::new
# File lib/stackify_apm/transport/agent_http_client.rb, line 13 def initialize(config) @config = config super(config) end
Public Instance Methods
get_json_headers()
click to toggle source
# File lib/stackify_apm/transport/agent_http_client.rb, line 24 def get_json_headers { 'Content-Type' => 'application/json' }.freeze end
get_protobuf_headers()
click to toggle source
# File lib/stackify_apm/transport/agent_http_client.rb, line 18 def get_protobuf_headers { 'Content-Type' => 'application/x-protobuf' }.freeze end
post(transactions = [])
click to toggle source
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
This method will send a transction message to HTTP request. It will accept Array
of transactions.
# File lib/stackify_apm/transport/agent_http_client.rb, line 35 def post(transactions = []) debug '[AgentHTTPClient] post()' if ENV['STACKIFY_TRANSPORT_LOG_LEVEL'] == '0' return unless ENV['STACKIFY_RUBY_ENV'] != 'rspec' max_retries = @config.max_retries retry_count = 0 delay = @config.delay_seconds begin message = get_json_message(transactions) conn = Faraday.new(ssl: { verify: false }) response = conn.post do |req| req.url URI(@config.transport_http_endpoint + @config.agent_traces_url).to_s req.headers = get_json_headers req.body = message end if defined?(response.status) && response.status == 200 debug '[AgentHTTPClient] Successfully send message via http request.' if ENV['STACKIFY_TRANSPORT_LOG_LEVEL'] == '0' elsif ENV['STACKIFY_TRANSPORT_LOG_LEVEL'] == '0' debug "[AgentHTTPClient] Failure sending via http request: #{response.inspect}" end rescue StandardError => e debug '[AgentHTTPClient] All retries are exhausted!' if retry_count >= max_retries retry_count += 1 if retry_count < max_retries debug "[AgentHTTPClient] post() exception: #{e.inspect}" debug "[AgentHTTPClient] An error occured. Retries left: #{max_retries - retry_count}" end sleep delay += retry_count retry if retry_count < max_retries + 1 end end