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



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

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



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

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

#after_fork(options = {}) ⇒ Object



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

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

#agentObject



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

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



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

def agent=(new_agent)
  @agent = new_agent
end

#agent_should_start?Boolean

Returns:

  • (Boolean)


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

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

#blacklisted?(value, &block) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#blacklisted_constants?Boolean

Returns:

  • (Boolean)


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

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)


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

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

#browser_timing_headerObject



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

def browser_timing_header
  agent.javascript_instrumentor.browser_timing_header
end

#configObject



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

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

#disable_all_tracingObject



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

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

#disable_sql_recordingObject



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

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

#disable_transaction_tracingObject



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

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

#drop_buffered_dataObject



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

def drop_buffered_data
  agent.drop_buffered_data
end

#get_transaction_nameObject



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

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



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

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

#ignore_enduserObject



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

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

#ignore_error_filter(&block) ⇒ Object



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

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



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

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

#in_blacklisted_rake_task?Boolean

Returns:

  • (Boolean)


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

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



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

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



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

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

#logger=(log) ⇒ Object



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

def logger=(log)
  @logger = log
end

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



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

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

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



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

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



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

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



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

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



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

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



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

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

#reset_configObject



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

def reset_config
  @config.reset_to_defaults
end

#restartObject



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

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



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

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

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



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

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

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



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

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

#shutdown(options = {}) ⇒ Object



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

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

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



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

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



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

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

#tl_is_execution_traced?Boolean

Returns:

  • (Boolean)


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

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

#tl_is_sql_recorded?Boolean

Returns:

  • (Boolean)


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

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

#tl_is_transaction_traced?Boolean

Returns:

  • (Boolean)


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

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