Module: Appsignal
- Defined in:
- lib/appsignal/rack/streaming_listener.rb,
lib/appsignal.rb,
lib/appsignal/cli.rb,
lib/appsignal/hooks.rb,
lib/appsignal/utils.rb,
lib/appsignal/config.rb,
lib/appsignal/marker.rb,
lib/appsignal/version.rb,
lib/appsignal/extension.rb,
lib/appsignal/auth_check.rb,
lib/appsignal/hooks/puma.rb,
lib/appsignal/hooks/rake.rb,
lib/appsignal/subscriber.rb,
lib/appsignal/cli/install.rb,
lib/appsignal/hooks/redis.rb,
lib/appsignal/transaction.rb,
lib/appsignal/transmitter.rb,
lib/appsignal/cli/diagnose.rb,
lib/appsignal/hooks/sequel.rb,
lib/appsignal/hooks/sidekiq.rb,
lib/appsignal/hooks/unicorn.rb,
lib/appsignal/hooks/net_http.rb,
lib/appsignal/event_formatter.rb,
lib/appsignal/hooks/celluloid.rb,
lib/appsignal/hooks/passenger.rb,
lib/appsignal/hooks/shoryuken.rb,
lib/appsignal/params_sanitizer.rb,
lib/appsignal/hooks/delayed_job.rb,
lib/appsignal/integrations/grape.rb,
lib/appsignal/integrations/resque.rb,
lib/appsignal/cli/notify_of_deploy.rb,
lib/appsignal/integrations/railtie.rb,
lib/appsignal/update_active_support.rb,
lib/appsignal/hooks/mongo_ruby_driver.rb,
lib/appsignal/js_exception_transaction.rb,
lib/appsignal/rack/js_exception_catcher.rb,
lib/appsignal/rack/rails_instrumentation.rb,
lib/appsignal/rack/generic_instrumentation.rb,
lib/appsignal/rack/sinatra_instrumentation.rb,
lib/appsignal/integrations/mongo_ruby_driver.rb,
lib/appsignal/integrations/resque_active_job.rb,
lib/appsignal/integrations/delayed_job_plugin.rb,
lib/appsignal/event_formatter/sequel/sql_formatter.rb,
lib/appsignal/event_formatter/moped/query_formatter.rb,
lib/appsignal/event_formatter/faraday/request_formatter.rb,
lib/appsignal/event_formatter/net_http/request_formatter.rb,
lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb,
lib/appsignal/event_formatter/active_record/sql_formatter.rb,
lib/appsignal/event_formatter/action_view/render_formatter.rb,
lib/appsignal/event_formatter/elastic_search/search_formatter.rb,
lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb,
lib/appsignal/event_formatter/active_record/instantiation_formatter.rb,
ext/appsignal_extension.c
Overview
Appsignal module that tracks exceptions in Streaming rack responses.
Defined Under Namespace
Modules: Grape, Integrations, Rack, UpdateActiveSupport, Utils
Classes: AuthCheck, CLI, Capistrano, Config, EventFormatter, Extension, Hooks, JSExceptionTransaction, Marker, ParamsSanitizer, ParamsSanitizerCopy, ParamsSanitizerCopyScrub, ParamsSanitizerDestructive, ParamsSanitizerDestructiveScrub, StreamWrapper, Subscriber, Transaction, Transmitter
Constant Summary
collapse
- VERSION =
'1.2.2'
- SQL_BODY_FORMAT =
1
Class Attribute Summary collapse
Class Method Summary
collapse
-
.active? ⇒ Boolean
-
.add_distribution_value(key, value) ⇒ Object
-
.extension_loaded? ⇒ Boolean
-
.extensions ⇒ Object
-
.forked ⇒ Object
-
.get_server_state(key) ⇒ Object
-
.increment_counter(key, value = 1) ⇒ Object
-
.initialize_extensions ⇒ Object
-
.is_ignored_action?(action) ⇒ Boolean
-
.is_ignored_error?(error) ⇒ Boolean
(also: is_ignored_exception?)
-
.listen_for_error(&block) ⇒ Object
(also: listen_for_exception)
-
.log_formatter ⇒ Object
-
.monitor_single_transaction(name, env = {}, &block) ⇒ Object
Monitor a transaction, stop Appsignal and wait for this single transaction to be flushed.
-
.monitor_transaction(name, env = {}) ⇒ Object
Wrap a transaction with appsignal monitoring.
-
.send_error(error, tags = nil, namespace = Appsignal::Transaction::HTTP_REQUEST) ⇒ Object
(also: send_exception)
-
.set_error(exception) ⇒ Object
(also: set_exception, add_exception)
-
.set_gauge(key, value) ⇒ Object
-
.set_host_gauge(key, value) ⇒ Object
-
.set_process_gauge(key, value) ⇒ Object
-
.start ⇒ Object
-
.start_logger(path_arg = nil) ⇒ Object
-
.stop(called_by = nil) ⇒ Object
-
.tag_request(params = {}) ⇒ Object
(also: tag_job)
-
.without_instrumentation ⇒ Object
Convenience method for skipping instrumentations around a block of code.
Class Attribute Details
.agent ⇒ Object
Returns the value of attribute agent.
18
19
20
|
# File 'lib/appsignal.rb', line 18
def agent
@agent
end
|
.config ⇒ Object
Returns the value of attribute config.
18
19
20
|
# File 'lib/appsignal.rb', line 18
def config
@config
end
|
.extension_loaded ⇒ Object
Returns the value of attribute extension_loaded.
18
19
20
|
# File 'lib/appsignal.rb', line 18
def extension_loaded
@extension_loaded
end
|
.in_memory_log ⇒ Object
Returns the value of attribute in_memory_log.
18
19
20
|
# File 'lib/appsignal.rb', line 18
def in_memory_log
@in_memory_log
end
|
.logger ⇒ Object
Returns the value of attribute logger.
18
19
20
|
# File 'lib/appsignal.rb', line 18
def logger
@logger
end
|
.subscriber ⇒ Object
Returns the value of attribute subscriber.
18
19
20
|
# File 'lib/appsignal.rb', line 18
def subscriber
@subscriber
end
|
Class Method Details
.active? ⇒ Boolean
247
248
249
|
# File 'lib/appsignal.rb', line 247
def active?
config && config.active? && extension_loaded?
end
|
.add_distribution_value(key, value) ⇒ Object
.extension_loaded? ⇒ Boolean
243
244
245
|
# File 'lib/appsignal.rb', line 243
def extension_loaded?
!!@extension_loaded
end
|
.extensions ⇒ Object
20
21
22
|
# File 'lib/appsignal.rb', line 20
def extensions
@extensions ||= []
end
|
.get_server_state(key) ⇒ Object
.increment_counter(key, value = 1) ⇒ Object
.initialize_extensions ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/appsignal.rb', line 24
def initialize_extensions
Appsignal.logger.debug('Initializing extensions')
extensions.each do |extension|
Appsignal.logger.debug("Initializing #{extension}")
extension.initializer
end
end
|
.is_ignored_action?(action) ⇒ Boolean
256
257
258
|
# File 'lib/appsignal.rb', line 256
def is_ignored_action?(action)
Appsignal.config[:ignore_actions].include?(action)
end
|
.is_ignored_error?(error) ⇒ Boolean
Also known as:
is_ignored_exception?
251
252
253
|
# File 'lib/appsignal.rb', line 251
def is_ignored_error?(error)
Appsignal.config[:ignore_errors].include?(error.class.name)
end
|
.listen_for_error(&block) ⇒ Object
Also known as:
listen_for_exception
137
138
139
140
141
142
|
# File 'lib/appsignal.rb', line 137
def listen_for_error(&block)
yield
rescue => error
send_error(error)
raise error
end
|
218
219
220
221
222
|
# File 'lib/appsignal.rb', line 218
def log_formatter
proc do |severity, datetime, progname, msg|
"[#{datetime.strftime('%Y-%m-%dT%H:%M:%S')} (process) ##{Process.pid}][#{severity}] #{msg}\n"
end
end
|
.monitor_single_transaction(name, env = {}, &block) ⇒ Object
Monitor a transaction, stop Appsignal and wait for this single transaction to be flushed.
Useful for cases such as Rake tasks and Resque-like systems where a process is forked and immediately exits after the transaction finishes.
131
132
133
134
135
|
# File 'lib/appsignal.rb', line 131
def monitor_single_transaction(name, env={}, &block)
monitor_transaction(name, env, &block)
ensure
stop
end
|
.monitor_transaction(name, env = {}) ⇒ Object
Wrap a transaction with appsignal monitoring.
.send_error(error, tags = nil, namespace = Appsignal::Transaction::HTTP_REQUEST) ⇒ Object
Also known as:
send_exception
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/appsignal.rb', line 145
def send_error(error, tags=nil, namespace=Appsignal::Transaction::HTTP_REQUEST)
return if !active? || is_ignored_error?(error)
unless error.is_a?(Exception)
logger.error('Can\'t send error, given value is not an exception')
return
end
transaction = Appsignal::Transaction.new(
SecureRandom.uuid,
namespace,
Appsignal::Transaction::GenericRequest.new({})
)
transaction.set_tags(tags) if tags
transaction.set_error(error)
transaction.complete
end
|
.set_error(exception) ⇒ Object
Also known as:
set_exception, add_exception
.set_gauge(key, value) ⇒ Object
180
181
182
183
184
|
# File 'lib/appsignal.rb', line 180
def set_gauge(key, value)
Appsignal::Extension.set_gauge(key, value.to_f)
rescue RangeError
Appsignal.logger.warn("Gauge value #{value} for key '#{key}' is too big")
end
|
.set_host_gauge(key, value) ⇒ Object
186
187
188
189
190
|
# File 'lib/appsignal.rb', line 186
def set_host_gauge(key, value)
Appsignal::Extension.set_host_gauge(key, value.to_f)
rescue RangeError
Appsignal.logger.warn("Host gauge value #{value} for key '#{key}' is too big")
end
|
.set_process_gauge(key, value) ⇒ Object
192
193
194
195
196
|
# File 'lib/appsignal.rb', line 192
def set_process_gauge(key, value)
Appsignal::Extension.set_process_gauge(key, value.to_f)
rescue RangeError
Appsignal.logger.warn("Process gauge value #{value} for key '#{key}' is too big")
end
|
.start_logger(path_arg = nil) ⇒ Object
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
# File 'lib/appsignal.rb', line 224
def start_logger(path_arg=nil)
path = Appsignal.config ? Appsignal.config.log_file_path : nil
if path && !ENV['DYNO']
@logger = Logger.new(path)
@logger.formatter = log_formatter
else
@logger = Logger.new($stdout)
@logger.formatter = lambda do |severity, datetime, progname, msg|
"appsignal: #{msg}\n"
end
end
@logger.level = Logger::INFO
@logger << @in_memory_log.string if @in_memory_log
if path_arg
@logger.info('Setting the path in start_logger has no effect anymore, set it in the config instead')
end
end
|
.stop(called_by = nil) ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/appsignal.rb', line 71
def stop(called_by=nil)
if called_by
logger.debug("Stopping appsignal (#{called_by})")
else
logger.debug('Stopping appsignal')
end
Appsignal::Extension.stop
end
|
.tag_request(params = {}) ⇒ Object
Also known as:
tag_job
172
173
174
175
176
177
|
# File 'lib/appsignal.rb', line 172
def tag_request(params={})
return unless active?
transaction = Appsignal::Transaction.current
return false unless transaction
transaction.set_tags(params)
end
|
.without_instrumentation ⇒ Object
Convenience method for skipping instrumentations around a block of code.