Module: OneApm::Manager

Extended by:
Manager
Included in:
Manager
Defined in:
lib/one_apm/manager.rb

Instance Method Summary collapse

Instance Method Details

#add_custom_parameters(params) ⇒ Object



210
211
212
213
214
215
216
217
# File 'lib/one_apm/manager.rb', line 210

def add_custom_parameters(params)
  if params.is_a? Hash
    txn = Transaction.tl_current
    txn.add_custom_parameters(params) if txn
  else
    ::OneApm::Manager.logger.warn("Bad argument passed to #add_custom_parameters. Expected Hash but got #{params.class}")
  end
end

#add_instrumentation(file_pattern) ⇒ Object



125
126
127
# File 'lib/one_apm/manager.rb', line 125

def add_instrumentation(file_pattern)
  OneApm::Probe.instance.add_instrumentation file_pattern
end

#after_fork(options = {}) ⇒ Object



105
106
107
# File 'lib/one_apm/manager.rb', line 105

def after_fork(options = {})
  agent.after_fork(options)
end

#agentObject



52
53
54
55
56
57
# File 'lib/one_apm/manager.rb', line 52

def agent
  return @agent if @agent
  OneApm::Manager.logger.warn("Agent unavailable as it hasn't been started.")
  OneApm::Manager.logger.warn(caller.join("\n"))
  nil
end

#agent=(new_agent) ⇒ Object



59
60
61
# File 'lib/one_apm/manager.rb', line 59

def agent=(new_agent)
  @agent = new_agent
end

#agent_should_start?Boolean

Returns:

  • (Boolean)


249
250
251
252
253
# File 'lib/one_apm/manager.rb', line 249

def agent_should_start?
    !blacklisted_constants? &&
    !blacklisted_executables? &&
    !in_blacklisted_rake_task?
end

#blacklisted?(value, &block) ⇒ Boolean

Returns:

  • (Boolean)


267
268
269
# File 'lib/one_apm/manager.rb', line 267

def blacklisted?(value, &block)
  value.split(/\s*,\s*/).any?(&block)
end

#blacklisted_constants?Boolean

Returns:

  • (Boolean)


255
256
257
258
259
# File 'lib/one_apm/manager.rb', line 255

def blacklisted_constants?
  blacklisted?(OneApm::Manager.config[:'autostart.blacklisted_constants']) do |name|
    OneApm::LanguageSupport.constant_is_defined?(name)
  end
end

#blacklisted_executables?Boolean

Returns:

  • (Boolean)


261
262
263
264
265
# File 'lib/one_apm/manager.rb', line 261

def blacklisted_executables?
  blacklisted?(OneApm::Manager.config[:'autostart.blacklisted_executables']) do |bin|
    File.basename($0) == bin
  end
end

#browser_timing_headerObject



240
241
242
# File 'lib/one_apm/manager.rb', line 240

def browser_timing_header
  agent.javascript_instrumentor.browser_timing_header
end

#configObject



92
93
94
# File 'lib/one_apm/manager.rb', line 92

def config
  @config ||= OneApm::Configuration::Manager.new
end

#disable_all_tracingObject



166
167
168
169
170
171
# File 'lib/one_apm/manager.rb', line 166

def disable_all_tracing
  agent.push_trace_execution_flag(false)
  yield
ensure
  agent.pop_trace_execution_flag
end

#disable_sql_recordingObject



133
134
135
136
137
138
139
140
# File 'lib/one_apm/manager.rb', line 133

def disable_sql_recording
  state = agent.set_record_sql(false)
  begin
    yield
  ensure
    agent.set_record_sql(state)
  end
end

#disable_transaction_tracingObject



142
143
144
145
146
147
148
149
# File 'lib/one_apm/manager.rb', line 142

def disable_transaction_tracing
  state = agent.set_record_tt(false)
  begin
    yield
  ensure
    agent.set_record_tt(state)
  end
end

#drop_buffered_dataObject



121
122
123
# File 'lib/one_apm/manager.rb', line 121

def drop_buffered_data
  agent.drop_buffered_data
end

#get_transaction_nameObject



223
224
225
226
227
228
# File 'lib/one_apm/manager.rb', line 223

def get_transaction_name
  txn = Transaction.tl_current
  if txn
    txn.best_name.sub(Regexp.new("\\A#{Regexp.escape(OneApm::TransactionNamer.prefix_for_category(txn))}"), '')
  end
end

#ignore_apdexObject



156
157
158
159
# File 'lib/one_apm/manager.rb', line 156

def ignore_apdex
  txn = OneApm::Transaction.tl_current
  txn.ignore_apdex! if txn
end

#ignore_enduserObject



161
162
163
164
# File 'lib/one_apm/manager.rb', line 161

def ignore_enduser
  txn = OneApm::Transaction.tl_current
  txn.ignore_enduser! if txn
end

#ignore_error_filter(&block) ⇒ Object



192
193
194
195
196
197
198
# File 'lib/one_apm/manager.rb', line 192

def ignore_error_filter(&block)
  if block
    OneApm::Collector::ErrorCollector.ignore_error_filter = block
  else
    OneApm::Collector::ErrorCollector.ignore_error_filter
  end
end

#ignore_transactionObject



151
152
153
154
# File 'lib/one_apm/manager.rb', line 151

def ignore_transaction
  txn = OneApm::Transaction.tl_current
  txn.ignore! if txn
end

#in_blacklisted_rake_task?Boolean

Returns:

  • (Boolean)


271
272
273
274
275
276
277
278
279
# File 'lib/one_apm/manager.rb', line 271

def in_blacklisted_rake_task?
  tasks = begin
            ::Rake.application.top_level_tasks
          rescue => e
            OneApm::Manager.logger.debug("Not in Rake environment so skipping blacklisted_rake_tasks check: #{e}")
            []
          end
  !(tasks & OneApm::Manager.config[:'autostart.blacklisted_rake_tasks'].split(/\s*,\s*/)).empty?
end

#increment_metric(metric_name, amount = 1) ⇒ Object



115
116
117
118
119
# File 'lib/one_apm/manager.rb', line 115

def increment_metric(metric_name, amount = 1)
  agent.stats_engine.tl_record_unscoped_metrics(metric_name) do |stats|
    stats.increment_count(amount)
  end
end

#loggerObject



84
85
86
# File 'lib/one_apm/manager.rb', line 84

def logger
  @logger || OneApm::Logger::StartupLogger.instance
end

#logger=(log) ⇒ Object



88
89
90
# File 'lib/one_apm/manager.rb', line 88

def logger=(log)
  @logger = log
end

#notice_error(exception, options = {}) ⇒ Object



200
201
202
203
# File 'lib/one_apm/manager.rb', line 200

def notice_error(exception, options = {})
  Transaction.notice_error(exception, options)
  nil
end

#notice_sql(sql, metric, config, elapsed_time, state, &explainer) ⇒ Object



205
206
207
208
# File 'lib/one_apm/manager.rb', line 205

def notice_sql(sql, metric, config, elapsed_time, state, &explainer)
  agent.transaction_sampler.notice_sql(sql, config, elapsed_time, state, &explainer)
  agent.sql_sampler.notice_sql(sql, metric, config, elapsed_time, state, &explainer)
end

#notify(event_type, *args) ⇒ Object



234
235
236
237
238
# File 'lib/one_apm/manager.rb', line 234

def notify(event_type, *args)
  agent.events.notify( event_type, *args )
rescue
  OneApm::Manager.logger.debug "Ignoring exception during %p event notification" % [event_type]
end

#record_custom_event(event_type, event_attrs) ⇒ Object



173
174
175
176
177
178
# File 'lib/one_apm/manager.rb', line 173

def record_custom_event(event_type, event_attrs)
  if agent && OneApm::Manager.config[:'custom_insights_events.enabled']
    agent.custom_event_aggregator.record(event_type, event_attrs)
  end
  nil
end

#record_metric(metric_name, value) ⇒ Object



109
110
111
112
113
# File 'lib/one_apm/manager.rb', line 109

def record_metric(metric_name, value)
  value_to_store = value
  value_to_store = OneApm::Metrics::Stats.create_from_hash(value) if value.is_a?(Hash)
  agent.stats_engine.tl_record_unscoped_metrics(metric_name, value_to_store)
end

#require_test_helperObject



244
245
246
247
# File 'lib/one_apm/manager.rb', line 244

def require_test_helper
  path = File.join(__FILE__, '..', '..', '..', 'test', 'agent_helper')
  require File.expand_path(path)
end

#reset_configObject



96
97
98
# File 'lib/one_apm/manager.rb', line 96

def reset_config
  @config.reset_to_defaults
end

#restartObject



75
76
77
78
79
80
81
82
# File 'lib/one_apm/manager.rb', line 75

def restart
  shutdown
  agent.harvest_samplers.clear
  agent.instance_variable_set(:@connect_state, :pending)
  agent.instance_variable_set(:@worker_thread, nil)
  agent.harvester.instance_variable_set(:@starting_pid, nil)
  OneApm::Probe.init({:agent_enabled => true, :sync_startup => true})
end

#revert_to_default_configurationObject



100
101
102
103
# File 'lib/one_apm/manager.rb', line 100

def revert_to_default_configuration
  @config.remove_config_type(:manual)
  @config.remove_config_type(:server)
end

#set_sql_obfuscator(type = :replace, &block) ⇒ Object



129
130
131
# File 'lib/one_apm/manager.rb', line 129

def set_sql_obfuscator(type = :replace, &block)
  OneApm::Agent::Database.set_sql_obfuscator(type, &block)
end

#set_transaction_name(name, options = {}) ⇒ Object



219
220
221
# File 'lib/one_apm/manager.rb', line 219

def set_transaction_name(name, options={})
  Transaction.set_overriding_transaction_name(name, options[:category])
end

#shutdown(options = {}) ⇒ Object



71
72
73
# File 'lib/one_apm/manager.rb', line 71

def shutdown(options={})
  agent.shutdown(options) if agent
end

#start(options = {}) ⇒ Object Also known as: manual_start



63
64
65
66
67
# File 'lib/one_apm/manager.rb', line 63

def start(options = {})
  raise "Options must be a hash" unless Hash === options
  OneApm::Support::ForkedProcessChannel.listener.start if options[:start_channel_listener]
  OneApm::Probe.init({:agent_enabled => true, :sync_startup => true}.merge(options))
end

#subscribe(event_type, &handler) ⇒ Object



230
231
232
# File 'lib/one_apm/manager.rb', line 230

def subscribe(event_type, &handler)
  agent.events.subscribe( event_type, &handler )
end

#tl_is_execution_traced?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/one_apm/manager.rb', line 180

def tl_is_execution_traced?
  OneApm::TransactionState.tl_get.is_execution_traced?
end

#tl_is_sql_recorded?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/one_apm/manager.rb', line 188

def tl_is_sql_recorded?
  OneApm::TransactionState.tl_get.is_sql_recorded?
end

#tl_is_transaction_traced?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/one_apm/manager.rb', line 184

def tl_is_transaction_traced?
  OneApm::TransactionState.tl_get.is_transaction_traced?
end