class StackifyRubyAPM::RootInfo

@api private

Public Class Methods

build(config, transaction) click to toggle source

rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity

# File lib/stackify_apm/root_info.rb, line 61
def self.build(config, transaction)
  new(config, transaction).build
end
new(config, transaction) click to toggle source
# File lib/stackify_apm/root_info.rb, line 8
def initialize(config, transaction)
  @transaction = transaction
  @config = config
end

Public Instance Methods

build() click to toggle source

rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity

# File lib/stackify_apm/root_info.rb, line 15
def build
  # get process id
  pid = $PID || Process.pid
  # get hostname and remove extra unwanted characters
  begin
    hostname = (@config.hostname || `hostname`).strip
  rescue StandardError
    # use socket to get hostname if `hostname` throws exception
    require 'socket'
    hostname = Socket.gethostname
  end

  hash = {
    PROFILER_VERSION: StackifyRubyAPM::VERSION,
    CATEGORY: @transaction.context.category || 'Ruby',
    APPLICATION_PATH: '/',
    APPLICATION_FILESYSTEM_PATH: @config.root_path,
    APPLICATION_NAME: @config.application_name.strip,
    APPLICATION_ENV: @config.environment_name || 'Development',
    REPORTING_URL: @transaction.name,
    TRACE_ID: @transaction.id,
    THREAD_ID: Thread.current.object_id,
    TRACE_SOURCE: 'RUBY',
    TRACE_TARGET: 'RETRACE',
    HOST_NAME: hostname,
    OS_TYPE: StackifyRubyAPM::Util.host_os,
    PROCESS_ID: pid,
    TRACE_VERSION: '2.0',
    TRACETYPE: @transaction.type || 'WEBAPP'
  }
  hash[:METHOD] = @transaction.context.request.method if @transaction.context && @transaction.context.request && @transaction.context.request.method
  hash[:STATUS] = @transaction.context.response.status_code if @transaction.context && @transaction.context.response && @transaction.context.response.status_code
  hash[:URL] = @transaction.context.request.url[:full] if @transaction.context && @transaction.context.request && @transaction.context.request.url[:full]
  hash[:RUM] = true if @config.rum_enabled.is_a?(TrueClass)
  hash[:AWS_LAMBDA_ARN] = @transaction.context.aws[:arn] if @transaction.context && @transaction.context.aws && @transaction.context.aws[:arn]
  hash[:PREFIX_RESPONSE_BODY] = @transaction.context.prefix.response_body.to_s if @transaction.context.prefix && @transaction.context.prefix.response_body
  hash[:PREFIX_RESPONSE_SIZE_BYTES] = @transaction.context.prefix.response_body.length.to_s if @transaction.context.prefix && @transaction.context.prefix.response_body
  hash[:PREFIX_RESPONSE_HEADERS] =  @transaction.context.prefix.response_headers.to_s if @transaction.context.prefix && @transaction.context.prefix.response_headers
  hash[:PREFIX_REQUEST_BODY] = @transaction.context.prefix.request_body.to_s if @transaction.context.prefix && @transaction.context.prefix.request_body
  hash[:PREFIX_REQUEST_SIZE_BYTES] = @transaction.context.prefix.request_body.length.to_s if @transaction.context.prefix && @transaction.context.prefix.request_body
  hash[:PREFIX_REQUEST_HEADERS] = @transaction.context.prefix.request_headers.to_s if @transaction.context.prefix && @transaction.context.prefix.request_headers
  hash
end

Private Instance Methods

runtime() click to toggle source
# File lib/stackify_apm/root_info.rb, line 67
def runtime
  case RUBY_ENGINE
  when 'ruby'
    { name: RUBY_ENGINE, version: RUBY_VERSION }
  when 'jruby'
    { name: RUBY_ENGINE, version: ENV['JRUBY_VERSION'] }
  end
end