Class: StackifyRubyAPM::Config Private

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

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.

Constant Summary collapse

DEFAULTS =

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.

{
  config_file: 'config/stackify_apm.yml',
  json_config_file: 'config/stackify.json',
  rum_script_src: 'https://stckjs.azureedge.net/stckjs.js',
  application_name: 'Ruby Application',
  environment_name: ENV['RAILS_ENV'] || ENV['RACK_ENV'],
  already_instrumented_flag: false,
  rum_auto_injection: false,
  rum_enabled: false,
  rum_cookie_path: '/',
  rum_cookie_name: '.Stackify.Rum',
  transport: StackifyRubyAPM::TRACE_LOG,
  instrument: true,
  debug_logging: false,
  log_path: StackifyRubyAPM::Util.host_os == 'WINDOWS' ? 'C:\ProgramData\Stackify\Ruby\log\stackify-ruby-apm-1.log' : '/usr/local/stackify/stackify-ruby-apm/log/stackify-ruby-apm-1.log',
  log_level: Logger::INFO,
  log_trace_path: StackifyRubyAPM::Util.host_os == 'WINDOWS' ? 'C:\ProgramData\Stackify\Ruby\log\\' : '/usr/local/stackify/stackify-ruby-apm/log/',

  max_queue_size: 500, # Maximum queue length of transactions before sending transactions to the APM.
  flush_interval_seconds: 1, # interval with which transactions should be sent to the APM. Default value: 1 seconds
  delay_seconds: 10, # Interval in seconds between tries
  max_retries: 3, # Number of attempts

  filter_exception_types: [],

  tracer_logger: nil,
  logger_byte_size: 50_000_000, # e.g, 50_000_000=50mb
  filenum_rotate: 20,
  debugger_byte_size: 20_000_000, # e.g, 20_000_000=20mb
  debugger_filenum_rotate: 3,
  logtime_created: 0,
  http_status: nil,
  debug_transactions: false,
  trace_log_age_in_hour: 60 * 60, # e.g, 60*60=1hour, 60*2=2mins
  check_trace_log_per_hour: '1h', # e.g, 1h=every 1hour, 2m=every 2mins

  source_lines_error_app_frames: 5,
  source_lines_span_app_frames: 5,
  source_lines_error_library_frames: 0,
  source_lines_span_library_frames: 0,
  span_frames_min_duration: -1, # it will collect stack traces for all spans

  disabled_spies: %w[json],

  view_paths: [],
  root_path: Dir.pwd,
  stackify_properties_file: '/usr/local/stackify/stackify-ruby-apm/stackify.properties',
  agent_traces_url: '/traces',
  unix_socket_path: '/usr/local/stackify/stackify.sock',
  transport_http_endpoint: 'https://localhost:10601'
}.freeze
ENV_TO_KEY =

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.

{
  'STACKIFY_DEBUG' => [:bool, 'debug_logging'],
  'STACKIFY_APPLICATION_NAME' => 'application_name',
  'STACKIFY_ENVIRONMENT_NAME' => 'environment_name',
  'STACKIFY_RUM' => [:bool, 'rum_enabled'],
  'STACKIFY_RUM_AUTO_INJECT' => [:bool, 'rum_auto_injection'],
  'STACKIFY_RUM_SCRIPT_SRC' => 'rum_script_src',
  'STACKIFY_TRANSPORT' => 'transport',
  'STACKIFY_TRANSPORT_LOG_PATH' => 'log_path',
  'STACKIFY_TRANSPORT_LOG_LEVEL' => [:int, 'log_level'],
  'STACKIFY_TRANSPORT_SOCKET_PATH' => 'unix_socket_path',
  'STACKIFY_TRANSPORT_HTTP_ENDPOINT' => 'transport_http_endpoint',
  'STACKIFY_ALREADY_INSTRUMENTED_FLAG' => 'already_instrumented_flag',
  'STACKIFY_INSTRUMENT' => [:bool, 'instrument'],
  'STACKIFY_HOSTNAME' => 'hostname',
  'STACKIFY_SOURCE_LINES_ERROR_APP_FRAMES' => [:int, 'source_lines_error_app_frames'],
  'STACKIFY_SOURCE_LINES_SPAN_APP_FRAMES' => [:int, 'source_lines_span_app_frames'],
  'STACKIFY_SOURCE_LINES_ERROR_LIBRARY_FRAMES' => [:int, 'source_lines_error_library_frames'],
  'STACKIFY_SOURCE_LINES_SPAN_LIBRARY_FRAMES' => [:int, 'source_lines_span_library_frames'],
  'STACKIFY_SPAN_FRAMES_MIN_DURATION' => [:int, 'span_frames_min_duration'],
  'STACKIFY_MAX_QUEUE_SIZE' => [:int, 'max_queue_size'],
  'STACKIFY_FLUSH_INTERVAL' => 'flush_interval_seconds',
  'STACKIFY_DISABLED_SPIES' => [:list, 'disabled_spies']
}.freeze

Constants included from Log

Log::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

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

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Config

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

Yields:

  • (_self)

Yield Parameters:



93
94
95
96
97
98
99
100
101
102
# File 'lib/stackify_apm/config.rb', line 93

def initialize(options = {})
  set_defaults
  set_from_args(options)
  set_from_config_file
  set_from_env
  yield self if block_given?
  debug_logger
  StackifyRubyAPM::Util.host_os == 'WINDOWS' ? load_stackify_props_windows : load_stackify_props_linux
  validate_apm_yml
end

Instance Attribute Details

#agent_traces_urlObject

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.



118
119
120
# File 'lib/stackify_apm/config.rb', line 118

def agent_traces_url
  @agent_traces_url
end

#already_instrumented_flagObject

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.



112
113
114
# File 'lib/stackify_apm/config.rb', line 112

def already_instrumented_flag
  @already_instrumented_flag
end

#apm_disabled_in_rakeObject (readonly)

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.



163
164
165
# File 'lib/stackify_apm/config.rb', line 163

def apm_disabled_in_rake
  @apm_disabled_in_rake
end

#application_nameObject

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.



122
123
124
# File 'lib/stackify_apm/config.rb', line 122

def application_name
  @application_name
end

#check_trace_log_per_hourObject

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.



134
135
136
# File 'lib/stackify_apm/config.rb', line 134

def check_trace_log_per_hour
  @check_trace_log_per_hour
end

#client_idObject (readonly)

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.



161
162
163
# File 'lib/stackify_apm/config.rb', line 161

def client_id
  @client_id
end

#client_run_domainObject (readonly)

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.



164
165
166
# File 'lib/stackify_apm/config.rb', line 164

def client_run_domain
  @client_run_domain
end

#config_fileObject

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.



104
105
106
# File 'lib/stackify_apm/config.rb', line 104

def config_file
  @config_file
end

#debug_loggingObject

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.



128
129
130
# File 'lib/stackify_apm/config.rb', line 128

def debug_logging
  @debug_logging
end

#debug_transactionsObject

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.



153
154
155
# File 'lib/stackify_apm/config.rb', line 153

def debug_transactions
  @debug_transactions
end

#debugger_byte_sizeObject

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.



131
132
133
# File 'lib/stackify_apm/config.rb', line 131

def debugger_byte_size
  @debugger_byte_size
end

#debugger_filenum_rotateObject

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.



132
133
134
# File 'lib/stackify_apm/config.rb', line 132

def debugger_filenum_rotate
  @debugger_filenum_rotate
end

#delay_secondsObject

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.



148
149
150
# File 'lib/stackify_apm/config.rb', line 148

def delay_seconds
  @delay_seconds
end

#device_idObject (readonly)

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.



162
163
164
# File 'lib/stackify_apm/config.rb', line 162

def device_id
  @device_id
end

#disabled_spiesObject

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.



155
156
157
# File 'lib/stackify_apm/config.rb', line 155

def disabled_spies
  @disabled_spies
end

#enabled_environmentsObject

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.



115
116
117
# File 'lib/stackify_apm/config.rb', line 115

def enabled_environments
  @enabled_environments
end

#environment_nameObject

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.



106
107
108
# File 'lib/stackify_apm/config.rb', line 106

def environment_name
  @environment_name
end

#filenum_rotateObject

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.



130
131
132
# File 'lib/stackify_apm/config.rb', line 130

def filenum_rotate
  @filenum_rotate
end

#filter_exception_typesObject

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.



151
152
153
# File 'lib/stackify_apm/config.rb', line 151

def filter_exception_types
  @filter_exception_types
end

#flush_interval_secondsObject

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.



147
148
149
# File 'lib/stackify_apm/config.rb', line 147

def flush_interval_seconds
  @flush_interval_seconds
end

#hostnameObject

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.



123
124
125
# File 'lib/stackify_apm/config.rb', line 123

def hostname
  @hostname
end

#http_statusObject

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.



159
160
161
# File 'lib/stackify_apm/config.rb', line 159

def http_status
  @http_status
end

#instrumentObject

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.



114
115
116
# File 'lib/stackify_apm/config.rb', line 114

def instrument
  @instrument
end

#json_config_fileObject

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.



105
106
107
# File 'lib/stackify_apm/config.rb', line 105

def json_config_file
  @json_config_file
end

#log_levelObject

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.



126
127
128
# File 'lib/stackify_apm/config.rb', line 126

def log_level
  @log_level
end

#log_pathObject

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.



125
126
127
# File 'lib/stackify_apm/config.rb', line 125

def log_path
  @log_path
end

#log_trace_pathObject

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.



139
140
141
# File 'lib/stackify_apm/config.rb', line 139

def log_trace_path
  @log_trace_path
end

#loggerObject

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.



127
128
129
# File 'lib/stackify_apm/config.rb', line 127

def logger
  @logger
end

#logger_byte_sizeObject

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.



129
130
131
# File 'lib/stackify_apm/config.rb', line 129

def logger_byte_size
  @logger_byte_size
end

#logtime_createdObject

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.



137
138
139
# File 'lib/stackify_apm/config.rb', line 137

def logtime_created
  @logtime_created
end

#max_queue_sizeObject

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.



146
147
148
# File 'lib/stackify_apm/config.rb', line 146

def max_queue_size
  @max_queue_size
end

#max_retriesObject

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.



149
150
151
# File 'lib/stackify_apm/config.rb', line 149

def max_retries
  @max_retries
end

#root_pathObject

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.



158
159
160
# File 'lib/stackify_apm/config.rb', line 158

def root_path
  @root_path
end

#rum_auto_injectionObject

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.



108
109
110
# File 'lib/stackify_apm/config.rb', line 108

def rum_auto_injection
  @rum_auto_injection
end

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.



111
112
113
# File 'lib/stackify_apm/config.rb', line 111

def rum_cookie_name
  @rum_cookie_name
end

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.



110
111
112
# File 'lib/stackify_apm/config.rb', line 110

def rum_cookie_path
  @rum_cookie_path
end

#rum_enabledObject

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.



109
110
111
# File 'lib/stackify_apm/config.rb', line 109

def rum_enabled
  @rum_enabled
end

#rum_script_injectedObject

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.



113
114
115
# File 'lib/stackify_apm/config.rb', line 113

def rum_script_injected
  @rum_script_injected
end

#rum_script_srcObject

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.



107
108
109
# File 'lib/stackify_apm/config.rb', line 107

def rum_script_src
  @rum_script_src
end

#source_lines_error_app_framesObject

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.



140
141
142
# File 'lib/stackify_apm/config.rb', line 140

def source_lines_error_app_frames
  @source_lines_error_app_frames
end

#source_lines_error_library_framesObject

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.



142
143
144
# File 'lib/stackify_apm/config.rb', line 142

def source_lines_error_library_frames
  @source_lines_error_library_frames
end

#source_lines_span_app_framesObject

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.



141
142
143
# File 'lib/stackify_apm/config.rb', line 141

def source_lines_span_app_frames
  @source_lines_span_app_frames
end

#source_lines_span_library_framesObject

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.



143
144
145
# File 'lib/stackify_apm/config.rb', line 143

def source_lines_span_library_frames
  @source_lines_span_library_frames
end

#span_frames_min_durationObject

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.



144
145
146
# File 'lib/stackify_apm/config.rb', line 144

def span_frames_min_duration
  @span_frames_min_duration
end

#stackify_properties_fileObject

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.



116
117
118
# File 'lib/stackify_apm/config.rb', line 116

def stackify_properties_file
  @stackify_properties_file
end

#trace_log_age_in_hourObject

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.



133
134
135
# File 'lib/stackify_apm/config.rb', line 133

def trace_log_age_in_hour
  @trace_log_age_in_hour
end

#tracer_loggerObject

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.



136
137
138
# File 'lib/stackify_apm/config.rb', line 136

def tracer_logger
  @tracer_logger
end

#transportObject

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.



117
118
119
# File 'lib/stackify_apm/config.rb', line 117

def transport
  @transport
end

#transport_http_endpointObject

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.



120
121
122
# File 'lib/stackify_apm/config.rb', line 120

def transport_http_endpoint
  @transport_http_endpoint
end

#unix_socket_pathObject

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.



119
120
121
# File 'lib/stackify_apm/config.rb', line 119

def unix_socket_path
  @unix_socket_path
end

#view_pathsObject

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.



157
158
159
# File 'lib/stackify_apm/config.rb', line 157

def view_paths
  @view_paths
end

Instance Method Details

#app=(app) ⇒ 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.



166
167
168
169
170
171
172
173
174
# File 'lib/stackify_apm/config.rb', line 166

def app=(app)
  case app_type?(app)
  when :rails
    set_rails(app)
  else
    # TODO: define custom?
    self.application_name = 'ruby'
  end
end

#app_type?(app) ⇒ Boolean

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:

  • (Boolean)


176
177
178
179
180
# File 'lib/stackify_apm/config.rb', line 176

def app_type?(app)
  return :rails if defined?(::Rails) && app.is_a?(Rails::Application)

  nil
end

#available_spiesObject

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.

available spies to use when framework is rails



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/stackify_apm/config.rb', line 183

def available_spies
  %w[
    action_dispatch
    mongo
    net_http
    custom_instrumenter
    httpclient
    redis
    sequel
    tilt
    httprb
    curb
    curb/easy
    curb/multi
    httparty
    stackify_logger
  ]
end

#debug_loggerObject

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.



224
225
226
227
228
229
# File 'lib/stackify_apm/config.rb', line 224

def debug_logger
  debugger_logpath = log_path == '-' ? $stdout : log_path
  logger = StackifyLogger.new(debugger_logpath, debugger_filenum_rotate, debugger_byte_size)
  logger.level = log_level
  self.logger = logger
end

#enabled_spiesObject

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.



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/stackify_apm/config.rb', line 202

def enabled_spies
  # check if the framework is rails or sinatra
  sinatra_activerecord_spies = %w[
    sinatra
    sinatra_activerecord/mysql_adapter
    sinatra_activerecord/postgresql_adapter
    sinatra_activerecord/sqlite_adapter
  ]

  new_available_spies = if defined? ::Sinatra::Base
                          if defined? ActiveRecord
                            available_spies + sinatra_activerecord_spies
                          else
                            available_spies
                          end
                        else
                          available_spies
                        end

  new_available_spies - disabled_spies
end