lib/appsignal.rb in appsignal-1.4.0.alpha.2 vs lib/appsignal.rb in appsignal-1.4.0.beta.1
- old
+ new
@@ -1,23 +1,12 @@
require 'json'
require 'logger'
require 'securerandom'
-# Make sure we have the notification system
-begin
- require 'active_support/notifications'
- ActiveSupport::Notifications::Fanout::Subscribers::Timed # See it it's recent enough
-rescue LoadError
- require 'vendor/active_support/notifications'
-rescue NameError
- require 'appsignal/update_active_support'
- Appsignal::UpdateActiveSupport.run
-end
-
module Appsignal
class << self
- attr_accessor :config, :subscriber, :agent, :extension_loaded
+ attr_accessor :config, :agent, :extension_loaded
attr_writer :logger, :in_memory_log
def extensions
@extensions ||= []
end
@@ -56,17 +45,21 @@
config.write_to_environment
Appsignal::Extension.start
Appsignal::Hooks.load_hooks
Appsignal::EventFormatter.initialize_formatters
initialize_extensions
- Appsignal::Extension.install_allocation_event_hook if config[:enable_allocation_tracking]
+
+ if config[:enable_allocation_tracking]
+ Appsignal::Extension.install_allocation_event_hook
+ end
+
if config[:enable_gc_instrumentation]
- Appsignal::Extension.install_gc_event_hooks
+ GC::Profiler.enable
Appsignal::Minutely.add_gc_probe
end
+
Appsignal::Minutely.start if config[:enable_minutely_probes]
- @subscriber = Appsignal::Subscriber.new
else
logger.info("Not starting, not active for #{config.env}")
end
else
logger.error('Not starting, no valid config for this environment')
@@ -93,11 +86,10 @@
def forked
return unless active?
Appsignal.start_logger
logger.debug('Forked process, resubscribing and restarting extension')
Appsignal::Extension.start
- @subscriber.resubscribe
end
def get_server_state(key)
Appsignal::Extension::get_server_state(key)
end
@@ -121,11 +113,11 @@
SecureRandom.uuid,
namespace,
request
)
begin
- ActiveSupport::Notifications.instrument(name) do
+ Appsignal.instrument(name) do
yield
end
rescue => error
transaction.set_error(error)
raise error
@@ -190,15 +182,19 @@
end
alias :tag_job :tag_request
def instrument(name, title=nil, body=nil, body_format=Appsignal::EventFormatter::DEFAULT)
Appsignal::Transaction.current.start_event
- r = yield
+ return_value = yield
Appsignal::Transaction.current.finish_event(name, title, body, body_format)
- r
+ return_value
end
+ def instrument_sql(name, title=nil, body=nil, &block)
+ instrument(name, title, body, Appsignal::EventFormatter::SQL_BODY_FORMAT, &block)
+ end
+
def set_gauge(key, value)
Appsignal::Extension.set_gauge(key.to_s, value.to_f)
rescue RangeError
Appsignal.logger.warn("Gauge value #{value} for key '#{key}' is too big")
end
@@ -233,26 +229,30 @@
l.formatter = log_formatter
end
end
def log_formatter
- proc do |severity, datetime, progname, msg|
- "[#{datetime.strftime('%Y-%m-%dT%H:%M:%S')} (process) ##{Process.pid}][#{severity}] #{msg}\n"
- end
+ proc do |severity, datetime, progname, msg|
+ "[#{datetime.strftime('%Y-%m-%dT%H:%M:%S')} (process) ##{Process.pid}][#{severity}] #{msg}\n"
+ end
end
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"
+ if path && !Appsignal::System.heroku?
+ begin
+ @logger = Logger.new(path)
+ @logger.formatter = log_formatter
+ rescue SystemCallError => error
+ start_stdout_logger
+ logger.warn "appsignal: Unable to start logger with log path '#{path}'."
+ logger.warn "appsignal: #{error}"
end
+ else
+ start_stdout_logger
end
+
if config && config[:debug]
@logger.level = Logger::DEBUG
else
@logger.level = Logger::INFO
end
@@ -290,10 +290,19 @@
Appsignal::Transaction.current.pause! if Appsignal::Transaction.current
yield
ensure
Appsignal::Transaction.current.resume! if Appsignal::Transaction.current
end
+
+ private
+
+ def start_stdout_logger
+ @logger = Logger.new($stdout)
+ @logger.formatter = lambda do |severity, datetime, progname, msg|
+ "appsignal: #{msg}\n"
+ end
+ end
end
end
require 'appsignal/utils'
require 'appsignal/extension'
@@ -302,15 +311,16 @@
require 'appsignal/event_formatter'
require 'appsignal/hooks'
require 'appsignal/marker'
require 'appsignal/minutely'
require 'appsignal/params_sanitizer'
+require 'appsignal/garbage_collection_profiler'
require 'appsignal/integrations/railtie' if defined?(::Rails)
require 'appsignal/integrations/resque'
require 'appsignal/integrations/resque_active_job'
-require 'appsignal/subscriber'
require 'appsignal/transaction'
require 'appsignal/version'
require 'appsignal/rack/generic_instrumentation'
require 'appsignal/rack/js_exception_catcher'
require 'appsignal/js_exception_transaction'
require 'appsignal/transmitter'
+require 'appsignal/system'