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\debug\stackify-ruby-apm-1.log' : '/usr/local/stackify/stackify-ruby-apm/debug/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',

  queue: true,
  lambda_handler: '',
  prefix_enabled: false,

  rum_script_url: 'https://stckjs.stackify.com/stckjs.js',
  rum_key: ''
}.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',
  'RETRACE_RUMV2_ENABLED' => [: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'],
  'STACKIFY_QUEUE' => [:bool, 'queue'],
  'STACKIFY_LAMBDA_HANDLER' => 'lambda_handler',
  'STACKIFY_PREFIX_ENABLED' => [:bool, 'prefix_enabled'],
  'RETRACE_RUM_SCRIPT_URL' => 'rum_script_url',
  'RETRACE_RUM_KEY' => 'rum_key'
}.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:



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/stackify_apm/config.rb', line 110

def initialize(options = {})
  set_defaults
  set_from_args(options)
  set_from_config_file
  set_from_env
  set_prefix_paths if @prefix_enabled
  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.



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

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.



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

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.



185
186
187
# File 'lib/stackify_apm/config.rb', line 185

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.



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

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.



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

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.



183
184
185
# File 'lib/stackify_apm/config.rb', line 183

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.



186
187
188
# File 'lib/stackify_apm/config.rb', line 186

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.



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

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.



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

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.



171
172
173
# File 'lib/stackify_apm/config.rb', line 171

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.



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

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.



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

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.



166
167
168
# File 'lib/stackify_apm/config.rb', line 166

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.



184
185
186
# File 'lib/stackify_apm/config.rb', line 184

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.



173
174
175
# File 'lib/stackify_apm/config.rb', line 173

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.



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

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.



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

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.



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

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.



169
170
171
# File 'lib/stackify_apm/config.rb', line 169

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.



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

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.



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

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.



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

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.



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

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.



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

def json_config_file
  @json_config_file
end

#lambda_handlerObject

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.



180
181
182
# File 'lib/stackify_apm/config.rb', line 180

def lambda_handler
  @lambda_handler
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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



167
168
169
# File 'lib/stackify_apm/config.rb', line 167

def max_retries
  @max_retries
end

#prefix_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.



181
182
183
# File 'lib/stackify_apm/config.rb', line 181

def prefix_enabled
  @prefix_enabled
end

#queueObject

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.



179
180
181
# File 'lib/stackify_apm/config.rb', line 179

def queue
  @queue
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.



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

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.



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

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.



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

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.



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

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.



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

def rum_enabled
  @rum_enabled
end

#rum_keyObject

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.



189
190
191
# File 'lib/stackify_apm/config.rb', line 189

def rum_key
  @rum_key
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.



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

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.



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

def rum_script_src
  @rum_script_src
end

#rum_script_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.



188
189
190
# File 'lib/stackify_apm/config.rb', line 188

def rum_script_url
  @rum_script_url
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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



175
176
177
# File 'lib/stackify_apm/config.rb', line 175

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.



191
192
193
194
195
196
197
198
199
# File 'lib/stackify_apm/config.rb', line 191

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)


201
202
203
204
205
# File 'lib/stackify_apm/config.rb', line 201

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



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/stackify_apm/config.rb', line 208

def available_spies
  %w[
    action_dispatch
    mongo
    net_http
    custom_instrumenter
    httpclient
    redis
    sequel
    tilt
    httprb
    curb
    curb/easy
    curb/multi
    httparty
    stackify_logger
    sidekiq
    delayed_job 
    faraday
    sucker_punch
    dynamo_db
  ]
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.

Default Transport

initialize default logger transport



267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/stackify_apm/config.rb', line 267

def debug_logger
  case @transport.downcase
  # For unix socket we don't create a trace log file
  when StackifyRubyAPM::TRACE_LOG
    debugger_logpath = log_path == '-' ? $stdout : log_path
    if (debugger_logpath == log_path)
      dir_name = File.dirname(debugger_logpath)
      Util.checkOrCreateFolder(dir_name)
    end
    logger = StackifyLogger.new(debugger_logpath, debugger_filenum_rotate, debugger_byte_size)
    logger.level = log_level
    self.logger = logger
  end
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.



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/stackify_apm/config.rb', line 242

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 + prefix_spies - disabled_spies
end

#prefix_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.



232
233
234
235
236
237
238
239
240
# File 'lib/stackify_apm/config.rb', line 232

def prefix_spies
  return [] unless @prefix_enabled
  %w[
    logger
    logging
    log4r
    yell
  ]
end