Class: Raygun::Apm::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/raygun/apm/config.rb

Constant Summary collapse

LOGLEVELS =
{
  "None" => Tracer::LOG_NONE,
  "Info" => Tracer::LOG_INFO,
  "Warning" => Tracer::LOG_WARNING,
  "Error" => Tracer::LOG_ERROR,
  "Verbose" => Tracer::LOG_VERBOSE,
  "Debug" => Tracer::LOG_DEBUG,
  "Everything" => Tracer::LOG_EVERYTHING,
  # ruby profiler specific
  "Blacklist" => Tracer::LOG_BLACKLIST
}
ENVIRONMENTS =
{
  "development" => Tracer::ENV_DEVELOPMENT,
  "production" => Tracer::ENV_PRODUCTION
}
DEFAULT_BLACKLIST_PATH_UNIX =
"/usr/share/Raygun/Blacklist"
DEFAULT_BLACKLIST_PATH_WINDOWS =
"C:\\ProgramData\\Raygun\\Blacklist"
UDP_SINK_HOST =

Initial constants for ProtonAgentTail.exe

TCP_SINK_HOST = TCP_MANAGEMENT_HOST = '127.0.0.1'
UDP_SINK_MULTICAST_HOST =
'239.100.15.215'
UDP_SINK_PORT =
TCP_SINK_PORT = 2799
TCP_MANAGEMENT_PORT =
2790

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = ENV) ⇒ Config

Returns a new instance of Config.



25
26
27
# File 'lib/raygun/apm/config.rb', line 25

def initialize(env=ENV)
  @env = env
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



24
25
26
# File 'lib/raygun/apm/config.rb', line 24

def env
  @env
end

Class Method Details

.cast_to_boolean(x) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/raygun/apm/config.rb', line 29

def self.cast_to_boolean(x)
  case x
  when true, 'true', 'True', 1, '1' then true
  else
    false
  end
end

.config_var(attr, opts = {}, &blk) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/raygun/apm/config.rb', line 37

def self.config_var(attr, opts={}, &blk)
  define_method attr.downcase do
    val = if x = env[attr]
      if opts[:as] == Integer
        Integer(x)
      elsif opts[:as] == String
        x.to_s
      elsif opts[:as] == :boolean
        self.class.cast_to_boolean(x)
      end
    else
      opts[:default]
    end
    blk ? blk.call(val) : val
  end
end

Instance Method Details

#blacklist_fileObject

Prefer what is set by PROTON_USER_OVERRIDES_FILE env



99
100
101
102
103
# File 'lib/raygun/apm/config.rb', line 99

def blacklist_file
  return proton_user_overrides_file if proton_user_overrides_file
  path = Gem.win_platform? ? DEFAULT_BLACKLIST_PATH_WINDOWS : DEFAULT_BLACKLIST_PATH_UNIX
  "#{File.join(path, proton_api_key)}.txt"
end

#environmentObject



93
94
95
96
# File 'lib/raygun/apm/config.rb', line 93

def environment
  environment = env['RACK_ENV'] || env['RAILS_ENV'] || 'production'
  ENVIRONMENTS[environment] || Tracer::ENV_PRODUCTION
end

#loglevelObject



89
90
91
# File 'lib/raygun/apm/config.rb', line 89

def loglevel
  LOGLEVELS[proton_debug_loglevel] || raise(ArgumentError, "invalid log level")
end

#PROTON_API_KEYObject

Enumerate all PROTON_ constants



61
# File 'lib/raygun/apm/config.rb', line 61

config_var 'PROTON_API_KEY', as: String, default: ''

#PROTON_HOOK_REDISObject

Conditional hooks



74
# File 'lib/raygun/apm/config.rb', line 74

config_var 'PROTON_HOOK_REDIS', as: :boolean, default: 'True'

#proton_tcp_hostObject



85
86
87
# File 'lib/raygun/apm/config.rb', line 85

def proton_tcp_host
  env['PROTON_TCP_HOST'] ? env['PROTON_TCP_HOST'].to_s : TCP_SINK_HOST
end

#proton_udp_hostObject



77
78
79
80
81
82
83
# File 'lib/raygun/apm/config.rb', line 77

def proton_udp_host
  if proton_use_multicast == 'True'
    UDP_SINK_MULTICAST_HOST
  else
    env['PROTON_UDP_HOST'] ? env['PROTON_UDP_HOST'].to_s : UDP_SINK_HOST
  end
end

#PROTON_UDP_HOSTObject

New - Ruby profiler



69
# File 'lib/raygun/apm/config.rb', line 69

config_var 'PROTON_UDP_HOST', as: String, default: UDP_SINK_HOST