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: true,
  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',

  queue: true,
  lambda_handler: '',
  prefix_enabled: false
}.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'],
  'STACKIFY_QUEUE' => [:bool, 'queue'],
  'STACKIFY_LAMBDA_HANDLER' => 'lambda_handler',
  'STACKIFY_PREFIX_ENABLED' => [:bool, 'prefix_enabled']
}.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:



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/stackify_apm/config.rb', line 105

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



183
184
185
186
187
188
189
190
191
# File 'lib/stackify_apm/config.rb', line 183

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)


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

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



200
201
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 200

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



259
260
261
262
263
264
265
266
267
268
# File 'lib/stackify_apm/config.rb', line 259

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



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/stackify_apm/config.rb', line 234

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.



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

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