appsignal 0.5.1 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGM1YThiMDUxODYwMmYxNzc3NGFhM2FkMzliNmM2NTAxY2FhMDA1Mw==
5
+ data.tar.gz: !binary |-
6
+ ZjljZWQ2YzBiMWUzNTc1ZThkYjAxYzIwZTA3YzBkZDliNDY5ZjhiZg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MmE4YWQ3MzNhYmQ4NGNlZTJlZDM5MDVkNGZlN2RjOWE5ODk3OTg5NDg3NzIw
10
+ ZjUwYTAxYWI4OTkzMWUwNzMwYzMyMmFjZTVkYjRhMWUzZGU1OTY4Y2ExZjY1
11
+ ZGFkYmQ1Zjg2ZWI2YmQ0OTgxZTk4YzBmYjcxZDcwNzE1Y2NmNjM=
12
+ data.tar.gz: !binary |-
13
+ OWFjYjM1MWM3NDgyNmFlZjk2MTE2NWNlZGZjNzkxOGY5ZGNiOTBkMzZhZGJj
14
+ MDY0NmMwYTQ4ZmU2YjY3N2RhZDBkZDg4MzllZjczNTA4YzUyM2VkN2FkODMw
15
+ NjZhYTA3ZTk3ZjY1NzUyOGY4NTEyOTcxMTI2ZDVkODg5Nzk2Mzc=
@@ -0,0 +1,6 @@
1
+ # 0.5.2
2
+
3
+ * General improvements to the rails generator
4
+ * Log to STDOUT if writing to log/appsignal.log is not possible (Heroku)
5
+ * Handle the last transactions before the rails process shuts down
6
+ * require 'erb' to enable loading of appsignal config
data/Rakefile CHANGED
@@ -43,6 +43,7 @@ task :publish do
43
43
 
44
44
  system("$EDITOR #{VERSION_FILE}")
45
45
  if changes.member?(VERSION_FILE)
46
+ Appsignal.send(:remove_const, :VERSION)
46
47
  load File.expand_path(VERSION_FILE)
47
48
  build_and_push_gem
48
49
  create_and_push_tag
@@ -51,7 +51,6 @@ module Appsignal
51
51
  def active?
52
52
  config && config[:active] == true
53
53
  end
54
-
55
54
  end
56
55
  end
57
56
 
@@ -61,6 +60,7 @@ require 'appsignal/auth_check'
61
60
  require 'appsignal/cli'
62
61
  require 'appsignal/config'
63
62
  require 'appsignal/exception_notification'
63
+ require 'appsignal/integrations/passenger'
64
64
  require 'appsignal/listener'
65
65
  require 'appsignal/marker'
66
66
  require 'appsignal/middleware'
@@ -1,8 +1,8 @@
1
1
  module Appsignal
2
2
  class Agent
3
- ACTION = 'log_entries'
3
+ ACTION = 'log_entries'.freeze
4
4
 
5
- attr_reader :aggregator, :active, :sleep_time, :transmitter
5
+ attr_reader :aggregator, :thread, :active, :sleep_time, :transmitter
6
6
 
7
7
  def initialize
8
8
  return unless Appsignal.active?
@@ -12,6 +12,7 @@ module Appsignal
12
12
  @thread = Thread.new do
13
13
  while true do
14
14
  send_queue if aggregator.has_transactions?
15
+ Appsignal.logger.debug("[#{$$}] Sleeping #{sleep_time}")
15
16
  sleep(sleep_time)
16
17
  end
17
18
  end
@@ -20,7 +21,7 @@ module Appsignal
20
21
  ACTION,
21
22
  Appsignal.config.fetch(:api_key)
22
23
  )
23
- Appsignal.logger.info 'Started the Appsignal agent'
24
+ Appsignal.logger.info("[#{$$}] Started the Appsignal agent")
24
25
  end
25
26
 
26
27
  def enqueue(transaction)
@@ -28,7 +29,7 @@ module Appsignal
28
29
  end
29
30
 
30
31
  def send_queue
31
- Appsignal.logger.debug "Sending queue"
32
+ Appsignal.logger.debug("[#{$$}] Sending queue")
32
33
  current_aggregator = aggregator
33
34
  @aggregator = Aggregator.new
34
35
  begin
@@ -36,14 +37,30 @@ module Appsignal
36
37
  rescue Exception => ex
37
38
  Appsignal.logger.error "#{ex.class} while sending queue: #{ex.message}"
38
39
  Appsignal.logger.error ex.backtrace.join('\n')
39
- stop_logging
40
40
  end
41
41
  end
42
42
 
43
+ def forked!
44
+ @forked = true
45
+ @aggregator = Aggregator.new
46
+ Appsignal.logger.info("[#{$$}] Forked the Appsignal agent")
47
+ end
48
+
49
+ def forked?
50
+ @forked ||= false
51
+ end
52
+
53
+ def shutdown(send_current_queue=false)
54
+ Appsignal.logger.info("[#{$$}] Shutting down the agent")
55
+ ActiveSupport::Notifications.unsubscribe(Appsignal.subscriber)
56
+ Thread.kill(thread) if thread
57
+ send_queue if send_current_queue && @aggregator.has_transactions?
58
+ end
59
+
43
60
  protected
44
61
 
45
62
  def handle_result(code)
46
- Appsignal.logger.debug "Queue sent, response code: #{code}"
63
+ Appsignal.logger.debug "[#{$$}] Queue sent, response code: #{code}"
47
64
  case code.to_i
48
65
  when 200 # ok
49
66
  when 420 # Enhance Your Calm
@@ -51,28 +68,23 @@ module Appsignal
51
68
  when 413 # Request Entity Too Large
52
69
  @sleep_time = sleep_time / 1.5
53
70
  when 429
54
- Appsignal.logger.error "Too many requests sent"
55
- stop_logging
71
+ Appsignal.logger.error "[#{$$}] Too many requests sent"
72
+ shutdown
56
73
  when 406
57
- Appsignal.logger.error "Your appsignal gem cannot communicate with "\
58
- "the API anymore, please upgrade."
59
- stop_logging
74
+ Appsignal.logger.error "[#{$$}] Your appsignal gem cannot "\
75
+ "communicate with the API anymore, please upgrade."
76
+ shutdown
60
77
  when 402
61
- Appsignal.logger.error "Payment required"
62
- stop_logging
78
+ Appsignal.logger.error "[#{$$}] Payment required"
79
+ shutdown
63
80
  when 401
64
- Appsignal.logger.error "API token cannot be authorized"
65
- stop_logging
81
+ Appsignal.logger.error "[#{$$}] API token cannot be authorized"
82
+ shutdown
66
83
  else
67
- Appsignal.logger.error "Unknown Appsignal response code: '#{code}'"
84
+ Appsignal.logger.error "[#{$$}] Unknown Appsignal response code: "\
85
+ "'#{code}'"
68
86
  end
69
87
  end
70
88
 
71
- def stop_logging
72
- Appsignal.logger.info("Disengaging the agent")
73
- ActiveSupport::Notifications.unsubscribe(Appsignal.subscriber)
74
- Thread.kill(@thread)
75
- end
76
-
77
89
  end
78
90
  end
@@ -58,7 +58,6 @@ module Appsignal
58
58
  transaction.convert_values_to_primitives!
59
59
  end
60
60
  end
61
-
62
61
  end
63
62
  end
64
63
 
@@ -19,9 +19,11 @@ module Appsignal
19
19
  Middleware::Chain.new do |chain|
20
20
  chain.add Appsignal::Middleware::DeleteBlanks
21
21
  chain.add Appsignal::Middleware::ActionViewSanitizer
22
- chain.add Appsignal::Middleware::ActiveRecordSanitizer
22
+ if defined?(ActiveRecord)
23
+ require 'appsignal/middleware/active_record_sanitizer'
24
+ chain.add Appsignal::Middleware::ActiveRecordSanitizer
25
+ end
23
26
  end
24
27
  end
25
-
26
28
  end
27
29
  end
@@ -1,17 +1,25 @@
1
1
  module Appsignal
2
2
  class AuthCheck
3
- delegate :uri, :to => :transmitter
4
- attr_reader :config
3
+ ACTION = 'auth'.freeze
4
+
5
+ attr_reader :environment, :logger
5
6
  attr_accessor :transmitter
6
- ACTION = 'auth'
7
+ delegate :uri, :to => :transmitter
8
+
9
+ def initialize(*args)
10
+ @environment = args.shift
11
+ options = args.empty? ? {} : args.last
12
+ @config = options[:config]
13
+ @logger = options[:logger]
14
+ end
7
15
 
8
- def initialize(environment)
9
- @config = Appsignal::Config.new(Rails.root, environment).load
16
+ def config
17
+ @config ||= Appsignal::Config.new(Rails.root, environment, logger).load
10
18
  end
11
19
 
12
20
  def perform
13
21
  self.transmitter = Appsignal::Transmitter.new(
14
- @config[:endpoint], ACTION, @config[:api_key]
22
+ config[:endpoint], ACTION, config[:api_key]
15
23
  )
16
24
  transmitter.transmit({})
17
25
  end
@@ -4,12 +4,14 @@ require 'yaml'
4
4
  require 'rails'
5
5
  require 'appsignal/version'
6
6
  require 'appsignal/config'
7
+ require 'appsignal/auth_check'
7
8
  require 'appsignal/marker'
8
9
  require 'appsignal/transmitter'
9
10
 
10
11
  module Appsignal
11
12
  class CLI
12
- AVAILABLE_COMMANDS = %w( notify_of_deploy )
13
+ AVAILABLE_COMMANDS = %w(notify_of_deploy api_check).freeze
14
+ PROJECT_ROOT = File.join(File.dirname(__FILE__), '..', '..').freeze
13
15
 
14
16
  class << self
15
17
  def run(argv=ARGV)
@@ -24,12 +26,14 @@ module Appsignal
24
26
 
25
27
  global.order!(argv)
26
28
  command = argv.shift
27
- if command then
28
- if AVAILABLE_COMMANDS.include?(command) then
29
+ if command
30
+ if AVAILABLE_COMMANDS.include?(command)
29
31
  commands[command].parse!(argv)
30
- case options[:command]
32
+ case command.to_sym
31
33
  when :notify_of_deploy
32
34
  notify_of_deploy(options)
35
+ when :api_check
36
+ api_check
33
37
  end
34
38
  else
35
39
  puts "Command '#{command}' does not exist, run appsignal -h to see the help"
@@ -48,7 +52,7 @@ module Appsignal
48
52
 
49
53
  def global_option_parser(options)
50
54
  OptionParser.new do |o|
51
- o.banner = %Q{Usage: appsignal <command> [options]}
55
+ o.banner = 'Usage: appsignal <command> [options]'
52
56
 
53
57
  o.on '-v', '--version', "Print version and exit" do |arg|
54
58
  puts "Appsignal #{Appsignal::VERSION}"
@@ -68,8 +72,7 @@ module Appsignal
68
72
  def command_option_parser(options)
69
73
  {
70
74
  'notify_of_deploy' => OptionParser.new do |o|
71
- o.banner = %Q{Usage: appsignal notify_of_deploy [options] }
72
- options[:command] = :notify_of_deploy
75
+ o.banner = 'Usage: appsignal notify_of_deploy [options]'
73
76
 
74
77
  o.on '--revision=<revision>', "The revision you're deploying" do |arg|
75
78
  options[:revision] = arg
@@ -86,6 +89,13 @@ module Appsignal
86
89
  o.on '--environment=<rails_env>', "The environment you're deploying to" do |arg|
87
90
  options[:environment] = arg
88
91
  end
92
+ end,
93
+ 'api_check' => OptionParser.new do |o|
94
+ o.banner = %q(Usage: appsignal api_check
95
+
96
+ This command checks the config file in config/appsignal.yml
97
+ and tries to use the api_keys available in each environment to
98
+ see if they work.)
89
99
  end
90
100
  }
91
101
  end
@@ -104,6 +114,38 @@ module Appsignal
104
114
  ).transmit
105
115
  end
106
116
 
117
+ def api_check
118
+ puts "\nReading config/appsignal.yml and attempting to use the config "\
119
+ "in order to check if it is set up the way it should be.\n\n"
120
+ Appsignal::Config.new(
121
+ PROJECT_ROOT, '', logger
122
+ ).load_all.each do |env, config|
123
+ auth_check = ::Appsignal::AuthCheck.new(
124
+ env,
125
+ {:config => config, :logger => logger}
126
+ )
127
+ puts "[#{env}]"
128
+ puts ' * Configured not to monitor this environment' unless config[:active]
129
+ begin
130
+ result = auth_check.perform
131
+ case result
132
+ when '200'
133
+ puts ' * AppSignal has confirmed authorisation!'
134
+ when '401'
135
+ puts ' * API key not valid with AppSignal...'
136
+ else
137
+ puts ' * Could not confirm authorisation: '\
138
+ "#{result.nil? ? 'nil' : result}"
139
+ end
140
+ rescue Exception => e
141
+ puts "Something went wrong while trying to "\
142
+ "authenticate with AppSignal: #{e}"
143
+ end
144
+ end
145
+ end
146
+
147
+ protected
148
+
107
149
  def validate_required_options(required_options, options)
108
150
  missing = required_options.select do |required_option|
109
151
  options[required_option].blank?
@@ -1,7 +1,9 @@
1
+ require 'erb'
2
+ require 'yaml'
1
3
  require 'appsignal/careful_logger'
4
+ require 'erb'
2
5
 
3
6
  module Appsignal
4
-
5
7
  class Config
6
8
  include Appsignal::CarefulLogger
7
9
 
@@ -28,6 +30,17 @@ module Appsignal
28
30
  DEFAULT_CONFIG.merge(configurations[env])
29
31
  end
30
32
 
33
+ def load_all
34
+ return unless load_configurations_from_disk
35
+ return unless used_unique_api_keys
36
+
37
+ {}.tap do |result|
38
+ configurations.each do |env, config|
39
+ result[env] = DEFAULT_CONFIG.merge(config)
40
+ end
41
+ end
42
+ end
43
+
31
44
  protected
32
45
 
33
46
  def load_configurations_from_disk
@@ -57,7 +70,5 @@ module Appsignal
57
70
  carefully_log_error "config for '#{env}' not found"
58
71
  false
59
72
  end
60
-
61
73
  end
62
-
63
74
  end
@@ -0,0 +1,11 @@
1
+ if defined?(PhusionPassenger)
2
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
3
+ Appsignal.logger.debug("[#{$$}] starting worker process")
4
+ Appsignal.agent.forked!
5
+ end
6
+
7
+ PhusionPassenger.on_event(:stopping_worker_process) do
8
+ Appsignal.logger.debug("[#{$$}] stopping worker process")
9
+ Appsignal.agent.shutdown(true)
10
+ end
11
+ end
@@ -1,4 +1,3 @@
1
1
  require 'appsignal/middleware/chain'
2
2
  require 'appsignal/middleware/delete_blanks'
3
3
  require 'appsignal/middleware/action_view_sanitizer'
4
- require 'appsignal/middleware/active_record_sanitizer'
@@ -1,5 +1,3 @@
1
- require 'active_record'
2
-
3
1
  module Appsignal
4
2
  module Middleware
5
3
  class ActiveRecordSanitizer
@@ -1,16 +1,24 @@
1
1
  module Appsignal
2
2
  class Railtie < Rails::Railtie
3
+
3
4
  initializer "appsignal.configure_rails_initialization" do |app|
4
5
  # Some apps when run from the console do not have Rails.root set, there's
5
6
  # currently no way to spec this.
6
7
  if Rails.root
7
- Appsignal.logger = Logger.new(Rails.root.join('log/appsignal.log')).tap do |l|
8
+ if File.writable?('log')
9
+ output = Rails.root.join('log/appsignal.log')
10
+ else
11
+ output = STDOUT
12
+ end
13
+ Appsignal.logger = Logger.new(output).tap do |l|
8
14
  l.level = Logger::INFO
9
15
  end
10
16
  Appsignal.flush_in_memory_log
11
17
  end
12
18
 
13
19
  if Appsignal.active?
20
+ Appsignal.logger.info("Activating appsignal-#{Appsignal::VERSION}")
21
+ at_exit { Appsignal.agent.shutdown(true) }
14
22
  app.middleware.
15
23
  insert_before(ActionDispatch::RemoteIp, Appsignal::Listener)
16
24
 
@@ -1,6 +1,5 @@
1
1
  module Appsignal
2
2
  module ToAppsignalHash
3
-
4
3
  def to_appsignal_hash
5
4
  {
6
5
  :name => name,
@@ -10,7 +9,6 @@ module Appsignal
10
9
  :payload => payload
11
10
  }
12
11
  end
13
-
14
12
  end
15
13
  end
16
14
 
@@ -128,6 +128,5 @@ module Appsignal
128
128
  Appsignal::ParamsSanitizer.sanitize(request.session)
129
129
  @fullpath = request.fullpath
130
130
  end
131
-
132
131
  end
133
132
  end
@@ -1,8 +1,7 @@
1
- require 'forwardable'
1
+ require 'delegate'
2
2
 
3
3
  module Appsignal
4
4
  class TransactionFormatter < SimpleDelegator
5
-
6
5
  def initialize(transaction)
7
6
  super(transaction)
8
7
  end
@@ -54,6 +53,5 @@ module Appsignal
54
53
  def add_events_to_hash!
55
54
  hash[:events] = events.map(&:to_appsignal_hash)
56
55
  end
57
-
58
56
  end
59
57
  end
@@ -1,3 +1,3 @@
1
1
  module Appsignal
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.3'
3
3
  end
@@ -1,26 +1,32 @@
1
1
  require 'appsignal'
2
2
 
3
3
  class AppsignalGenerator < Rails::Generators::Base
4
+ EXCLUDED_ENVIRONMENTS = [:test].freeze
5
+
4
6
  source_root File.expand_path('../templates', __FILE__)
7
+ argument :environment, :type => :string
5
8
  argument :push_key, :type => :string
6
- class_option :environment, :type => :string, :default => 'production',
7
- :desc => 'Install AppSignal for a different environment'
8
-
9
9
  desc "Install the config file for AppSignal with your PUSH_KEY."
10
+
10
11
  def copy_config_file
11
12
  template_file = 'appsignal.yml'
12
13
  appsignal_file = File.join('config', template_file)
13
14
  if File.exists?(appsignal_file)
14
- if environment_setup?(appsignal_file)
15
- say_status :error, "Environment already setup", :red
16
- else
17
- append_to_file appsignal_file, "\n"+new_template_content(template_file)
18
- end
15
+ say_status(:error, "Looks like you already have a config file.", :red)
16
+ say_status(:error, "Add the following to config/appsignal.yml:\n\n", :red)
17
+ say_status(:error, "#{environment}:", :red)
18
+ say_status(:error, " api_key: #{push_key}\n\n", :red)
19
+ say_status(:info, "Then run:\n\n", :red)
20
+ say_status(:info, " rake appsignal:check", :red)
19
21
  else
20
22
  template template_file, appsignal_file
23
+ capyistrano_install
24
+ check_key
21
25
  end
22
26
  end
23
27
 
28
+ protected
29
+
24
30
  def capyistrano_install
25
31
  deploy_file = File.expand_path(File.join('config', 'deploy.rb'))
26
32
  cap_file = File.expand_path('Capfile')
@@ -39,7 +45,7 @@ class AppsignalGenerator < Rails::Generators::Base
39
45
 
40
46
  def check_key
41
47
  begin
42
- auth_check = ::Appsignal::AuthCheck.new(options.environment)
48
+ auth_check = ::Appsignal::AuthCheck.new(environment)
43
49
  result = auth_check.perform
44
50
  if result == '200'
45
51
  say_status :success, "AppSignal has confirmed authorisation!"
@@ -47,7 +53,7 @@ class AppsignalGenerator < Rails::Generators::Base
47
53
  say_status :error, "Push key not valid with AppSignal...", :red
48
54
  else
49
55
  say_status :error, "Could not confirm authorisation: "\
50
- "#{result.nil? ? 'nil' : result} at #{auth_check.uri}", :red
56
+ "#{result.nil? ? 'nil' : result}", :red
51
57
  end
52
58
  rescue Exception => e
53
59
  say_status :error, "Something went wrong while trying to authenticate "\
@@ -57,9 +63,17 @@ class AppsignalGenerator < Rails::Generators::Base
57
63
 
58
64
  private
59
65
 
66
+ alias :selected_environment :environment
67
+
68
+ def environments
69
+ @environments ||= Dir.glob(
70
+ File.join(%w(. config environments *.rb))
71
+ ).map { |o| File.basename(o, ".rb").to_sym } - EXCLUDED_ENVIRONMENTS
72
+ end
73
+
60
74
  def environment_setup?(config_file)
61
75
  file_contents = File.read(config_file)
62
- file_contents =~ Regexp.new("#{options.environment}:")
76
+ file_contents =~ Regexp.new("#{environment}:")
63
77
  end
64
78
 
65
79
  # As based on Thor's template method
@@ -1,4 +1,25 @@
1
- <%= options.environment %>:
1
+ ---
2
+ # Unlisted environments will not be visible on the AppSignal site,
3
+ # Active environments count towards the account plan limit.
4
+ <%- environments.each do |environment| -%>
5
+ <%= environment %>:
6
+ <%- if selected_environment.to_sym == environment -%>
7
+ # The API key used by the AppSignal gem to push this specific environment to
8
+ # AppSignal. (required)
9
+ #
10
+ # It is possible to use ERB.
11
+ # api_key: "<%%= ENV['APPSIGNAL_API_KEY'] %>"
2
12
  api_key: "<%= push_key %>"
13
+
14
+ # The cuttoff point above which a request is considered slow. (default: 200)
15
+ # slow_request_threshold: 200
16
+
17
+ # Change whether this environment should be monitored. (default: false)
3
18
  active: true
4
- slow_request_threshold: 200
19
+ <%- else -%>
20
+ # Go to https://appsignal.com if you want to monitor your <%= environment %>
21
+ # environment to obtain an api key.
22
+ # api_key: <<%= environment.upcase %>-API-KEY>
23
+ active: false
24
+ <%- end -%>
25
+ <%- end -%>
@@ -31,7 +31,6 @@ describe Appsignal::Agent do
31
31
  PostProcessingException.new('Message')
32
32
  )
33
33
 
34
- subject.should_receive(:stop_logging)
35
34
  Appsignal.logger.should_receive(:error).
36
35
  with('PostProcessingException while sending queue: Message').
37
36
  once
@@ -44,7 +43,7 @@ describe Appsignal::Agent do
44
43
  subject.transmitter.stub(:transmit).and_raise(
45
44
  Exception.new('Message')
46
45
  )
47
- subject.should_receive(:stop_logging)
46
+
48
47
  Appsignal.logger.should_receive(:error).
49
48
  with('Exception while sending queue: Message').
50
49
  once
@@ -56,6 +55,58 @@ describe Appsignal::Agent do
56
55
  after { subject.send_queue }
57
56
  end
58
57
 
58
+ describe "#shutdown" do
59
+ before do
60
+ ActiveSupport::Notifications.should_receive(:unsubscribe).with(Appsignal.subscriber)
61
+ Thread.should_receive(:kill).with(subject.thread)
62
+ end
63
+
64
+ context "when not sending the current queue" do
65
+ context "with an empty queue" do
66
+ it "should shutdown" do
67
+ subject.shutdown
68
+ end
69
+ end
70
+
71
+ context "with a queue with transactions" do
72
+ it "should shutdown" do
73
+ subject.enqueue(slow_transaction)
74
+ subject.should_not_receive(:send_queue)
75
+
76
+ subject.shutdown
77
+ end
78
+ end
79
+ end
80
+
81
+ context "when the queue is to be sent" do
82
+ context "with an empty queue" do
83
+ it "should shutdown" do
84
+ subject.should_not_receive(:send_queue)
85
+
86
+ subject.shutdown(true)
87
+ end
88
+ end
89
+
90
+ context "with a queue with transactions" do
91
+ it "should send the queue and shutdown" do
92
+ subject.enqueue(slow_transaction)
93
+ subject.should_receive(:send_queue)
94
+
95
+ subject.shutdown(true)
96
+ end
97
+ end
98
+
99
+ context "when we're a child process" do
100
+ it "should shutdown" do
101
+ subject.stub(:forked? => true)
102
+ subject.should_not_receive(:send_queue)
103
+
104
+ subject.shutdown(true)
105
+ end
106
+ end
107
+ end
108
+ end
109
+
59
110
  describe '#handle_result' do
60
111
  before { subject.aggregator.add(transaction) }
61
112
  before { subject.instance_variable_set(:@sleep_time, 3.0) }
@@ -91,7 +142,7 @@ describe Appsignal::Agent do
91
142
  let(:code) { '429' }
92
143
 
93
144
  it "calls a stop to logging" do
94
- subject.should_receive :stop_logging
145
+ subject.should_receive(:shutdown)
95
146
  end
96
147
  end
97
148
 
@@ -99,7 +150,7 @@ describe Appsignal::Agent do
99
150
  let(:code) { '406' }
100
151
 
101
152
  it "calls a stop to logging" do
102
- subject.should_receive :stop_logging
153
+ subject.should_receive(:shutdown)
103
154
  end
104
155
  end
105
156
 
@@ -107,7 +158,7 @@ describe Appsignal::Agent do
107
158
  let(:code) { '402' }
108
159
 
109
160
  it "calls a stop to logging" do
110
- subject.should_receive :stop_logging
161
+ subject.should_receive(:shutdown)
111
162
  end
112
163
  end
113
164
 
@@ -115,7 +166,7 @@ describe Appsignal::Agent do
115
166
  let(:code) { '401' }
116
167
 
117
168
  it "calls a stop to logging" do
118
- subject.should_receive :stop_logging
169
+ subject.should_receive(:shutdown)
119
170
  end
120
171
  end
121
172
 
@@ -131,9 +182,9 @@ describe Appsignal::Agent do
131
182
  end
132
183
  end
133
184
 
134
- describe "#stop_logging" do
185
+ describe "#shutdown" do
135
186
  it "does not raise exceptions" do
136
- expect { subject.send :stop_logging }.not_to raise_error
187
+ expect { subject.send(:shutdown) }.not_to raise_error
137
188
  end
138
189
  end
139
190
 
@@ -50,14 +50,18 @@ describe Appsignal::CLI do
50
50
  cli.run(['nonsense'])
51
51
  }.should raise_error(SystemExit)
52
52
 
53
- out_stream.string.should include "Command 'nonsense' does not exist, run appsignal -h to see the help"
53
+ out_stream.string.should include "Command 'nonsense' does not exist, run "\
54
+ "appsignal -h to see the help"
54
55
  end
55
56
 
57
+ # protected
58
+
56
59
  describe "#validate_required_options" do
57
60
  let(:required_options) { [:option_1, :option_2, :option_3] }
58
61
 
59
62
  it "should do nothing with all options supplied" do
60
- cli.validate_required_options(
63
+ cli.send(
64
+ :validate_required_options,
61
65
  required_options,
62
66
  :option_1 => 1,
63
67
  :option_2 => 2,
@@ -68,7 +72,8 @@ describe Appsignal::CLI do
68
72
 
69
73
  it "should print a message with one option missing" do
70
74
  lambda {
71
- cli.validate_required_options(
75
+ cli.send(
76
+ :validate_required_options,
72
77
  required_options,
73
78
  :option_1 => 1,
74
79
  :option_2 => 2
@@ -79,7 +84,8 @@ describe Appsignal::CLI do
79
84
 
80
85
  it "should print a message with multiple options missing" do
81
86
  lambda {
82
- cli.validate_required_options(
87
+ cli.send(
88
+ :validate_required_options,
83
89
  required_options,
84
90
  :option_1 => 1,
85
91
  :option_2 => ''
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe "Passenger integration" do
5
+ let(:file) { File.expand_path('lib/appsignal/integrations/passenger.rb') }
6
+ before(:all) { module PhusionPassenger ; end }
7
+
8
+ it "adds behavior to stopping_worker_process and starting_worker_process" do
9
+ PhusionPassenger.should_receive(:on_event).with(:starting_worker_process)
10
+ PhusionPassenger.should_receive(:on_event).with(:stopping_worker_process)
11
+ load file
12
+ end
13
+
14
+ context "without passenger" do
15
+ before(:all) { Object.send(:remove_const, :PhusionPassenger) }
16
+
17
+ specify { expect { PhusionPassenger }.to raise_error(NameError) }
18
+ specify { expect { load file }.to_not raise_error }
19
+ end
20
+ end
@@ -1,4 +1,6 @@
1
1
  require 'spec_helper'
2
+ require 'active_record'
3
+ require 'appsignal/middleware/active_record_sanitizer'
2
4
 
3
5
  describe Appsignal::Middleware::ActiveRecordSanitizer do
4
6
  let(:klass) { Appsignal::Middleware::ActiveRecordSanitizer }
@@ -22,7 +22,7 @@ describe AppsignalGenerator do
22
22
  authcheck = mock()
23
23
  Appsignal::AuthCheck.should_receive(:new).and_return(authcheck)
24
24
  authcheck.should_receive(:perform).and_return('200')
25
- run_generator_in_tmp %w(my_app_key)
25
+ run_generator_in_tmp %w(production my_app_key)
26
26
  end
27
27
 
28
28
  specify "should mention successful auth check" do
@@ -36,7 +36,7 @@ describe AppsignalGenerator do
36
36
  authcheck = mock()
37
37
  Appsignal::AuthCheck.should_receive(:new).and_return(authcheck)
38
38
  authcheck.should_receive(:perform).and_return('401')
39
- run_generator_in_tmp %w(my_app_key)
39
+ run_generator_in_tmp %w(production my_app_key)
40
40
  end
41
41
 
42
42
  specify "should mention invalid key" do
@@ -50,12 +50,11 @@ describe AppsignalGenerator do
50
50
  authcheck = mock()
51
51
  Appsignal::AuthCheck.should_receive(:new).and_return(authcheck)
52
52
  authcheck.should_receive(:perform).and_return('500')
53
- authcheck.should_receive(:uri).and_return('auth')
54
- run_generator_in_tmp %w(my_app_key)
53
+ run_generator_in_tmp %w(production my_app_key)
55
54
  end
56
55
 
57
56
  specify "should mention failed check" do
58
- @output.should include('Could not confirm authorisation: 500 at auth')
57
+ @output.should include('error Could not confirm authorisation: 500')
59
58
  end
60
59
  end
61
60
 
@@ -63,7 +62,7 @@ describe AppsignalGenerator do
63
62
  before do
64
63
  prepare_destination
65
64
  Appsignal::AuthCheck.should_receive(:new) { raise }
66
- run_generator_in_tmp %w(my_app_key)
65
+ run_generator_in_tmp %w(production my_app_key)
67
66
  end
68
67
 
69
68
  specify "should mention internal failure" do
@@ -92,16 +91,13 @@ describe AppsignalGenerator do
92
91
  context "without capistrano" do
93
92
  before :all do
94
93
  prepare_destination
95
- run_generator_in_tmp %w(my_app_key)
94
+ run_generator_in_tmp %w(production my_app_key)
96
95
  end
97
96
 
98
97
  specify "config file is created" do
99
98
  destination_root.should have_structure {
100
99
  directory 'config' do
101
- file 'appsignal.yml' do
102
- contains 'production:'
103
- contains 'api_key: "my_app_key"'
104
- end
100
+ file 'appsignal.yml'
105
101
  no_file 'deploy.rb'
106
102
  end
107
103
  }
@@ -122,7 +118,7 @@ describe AppsignalGenerator do
122
118
  deploy_file = File.expand_path(File.join('config', 'deploy.rb'),
123
119
  destination_root)
124
120
  File.open(deploy_file, 'w') {}
125
- run_generator_in_tmp %w(my_app_key)
121
+ run_generator_in_tmp %w(production my_app_key)
126
122
  end
127
123
 
128
124
  specify "config file is created and capistrano deploy file modified" do
@@ -146,16 +142,13 @@ describe AppsignalGenerator do
146
142
  context "with custom environment" do
147
143
  before do
148
144
  prepare_destination
149
- run_generator_in_tmp %w(my_app_key --environment=development)
145
+ run_generator_in_tmp %w(development my_app_key)
150
146
  end
151
147
 
152
148
  specify "config file is created" do
153
149
  destination_root.should have_structure {
154
150
  directory 'config' do
155
- file 'appsignal.yml' do
156
- contains 'development:'
157
- contains 'api_key: "my_app_key"'
158
- end
151
+ file 'appsignal.yml'
159
152
  no_file 'deploy.rb'
160
153
  end
161
154
  }
@@ -171,52 +164,11 @@ describe AppsignalGenerator do
171
164
  File.open(File.expand_path(config_file, destination_root), 'w') do |f|
172
165
  f.write("production:\n api_key: 111")
173
166
  end
174
- run_generator_in_tmp %w(my_app_key --environment=development)
175
- end
176
-
177
- specify "config file is created" do
178
- destination_root.should have_structure {
179
- directory 'config' do
180
- file 'appsignal.yml' do
181
- contains 'production:'
182
- contains "\ndevelopment:"
183
- contains 'api_key: "my_app_key"'
184
- end
185
- no_file 'deploy.rb'
186
- end
187
- }
188
- end
189
-
190
- specify "should not give error about conflicting environment" do
191
- @output.should_not include('error Environment already setup')
192
- end
193
- end
194
-
195
- context "with existing environment" do
196
- before :all do
197
- prepare_destination
198
- FileUtils.mkdir(File.expand_path('config', destination_root))
199
- config_file = File.join('config', 'appsignal.yml')
200
- File.open(File.expand_path(config_file, destination_root), 'w') do |f|
201
- f.write("development:\n api_key: \"111\"")
202
- end
203
- run_generator_in_tmp %w(my_app_key --environment=development)
204
- end
205
-
206
- specify "config file is created" do
207
- destination_root.should have_structure {
208
- directory 'config' do
209
- file 'appsignal.yml' do
210
- contains "development:"
211
- contains 'api_key: "111"'
212
- end
213
- no_file 'deploy.rb'
214
- end
215
- }
167
+ run_generator_in_tmp %w(development my_app_key)
216
168
  end
217
169
 
218
- specify "should give error about conflicting environment" do
219
- @output.should include('error Environment already setup')
170
+ it "exits and tells to manually edit config/appsignal.yml" do
171
+ @output.should include('error Looks like you already have a config file')
220
172
  end
221
173
  end
222
174
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.5.1
4
+ version: 0.5.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Robert Beekman
@@ -13,120 +12,106 @@ authors:
13
12
  autorequire:
14
13
  bindir: bin
15
14
  cert_chain: []
16
- date: 2013-04-18 00:00:00.000000000 Z
15
+ date: 2013-05-16 00:00:00.000000000 Z
17
16
  dependencies:
18
17
  - !ruby/object:Gem::Dependency
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
23
- version: '3.0'
24
- none: false
25
- prerelease: false
26
18
  name: rails
27
19
  requirement: !ruby/object:Gem::Requirement
28
20
  requirements:
29
21
  - - ~>
30
22
  - !ruby/object:Gem::Version
31
23
  version: '3.0'
32
- none: false
33
24
  type: :runtime
34
- - !ruby/object:Gem::Dependency
25
+ prerelease: false
35
26
  version_requirements: !ruby/object:Gem::Requirement
36
27
  requirements:
37
- - - ! '>='
28
+ - - ~>
38
29
  - !ruby/object:Gem::Version
39
- version: '0'
40
- none: false
41
- prerelease: false
30
+ version: '3.0'
31
+ - !ruby/object:Gem::Dependency
42
32
  name: rake
43
33
  requirement: !ruby/object:Gem::Requirement
44
34
  requirements:
45
35
  - - ! '>='
46
36
  - !ruby/object:Gem::Version
47
37
  version: '0'
48
- none: false
49
38
  type: :runtime
50
- - !ruby/object:Gem::Dependency
39
+ prerelease: false
51
40
  version_requirements: !ruby/object:Gem::Requirement
52
41
  requirements:
53
42
  - - ! '>='
54
43
  - !ruby/object:Gem::Version
55
44
  version: '0'
56
- none: false
57
- prerelease: false
45
+ - !ruby/object:Gem::Dependency
58
46
  name: json
59
47
  requirement: !ruby/object:Gem::Requirement
60
48
  requirements:
61
49
  - - ! '>='
62
50
  - !ruby/object:Gem::Version
63
51
  version: '0'
64
- none: false
65
52
  type: :runtime
66
- - !ruby/object:Gem::Dependency
53
+ prerelease: false
67
54
  version_requirements: !ruby/object:Gem::Requirement
68
55
  requirements:
69
56
  - - ! '>='
70
57
  - !ruby/object:Gem::Version
71
58
  version: '0'
72
- none: false
73
- prerelease: false
59
+ - !ruby/object:Gem::Dependency
74
60
  name: rspec
75
61
  requirement: !ruby/object:Gem::Requirement
76
62
  requirements:
77
63
  - - ! '>='
78
64
  - !ruby/object:Gem::Version
79
65
  version: '0'
80
- none: false
81
66
  type: :development
82
- - !ruby/object:Gem::Dependency
67
+ prerelease: false
83
68
  version_requirements: !ruby/object:Gem::Requirement
84
69
  requirements:
85
70
  - - ! '>='
86
71
  - !ruby/object:Gem::Version
87
72
  version: '0'
88
- none: false
89
- prerelease: false
73
+ - !ruby/object:Gem::Dependency
90
74
  name: capistrano
91
75
  requirement: !ruby/object:Gem::Requirement
92
76
  requirements:
93
77
  - - ! '>='
94
78
  - !ruby/object:Gem::Version
95
79
  version: '0'
96
- none: false
97
80
  type: :development
98
- - !ruby/object:Gem::Dependency
81
+ prerelease: false
99
82
  version_requirements: !ruby/object:Gem::Requirement
100
83
  requirements:
101
84
  - - ! '>='
102
85
  - !ruby/object:Gem::Version
103
86
  version: '0'
104
- none: false
105
- prerelease: false
87
+ - !ruby/object:Gem::Dependency
106
88
  name: generator_spec
107
89
  requirement: !ruby/object:Gem::Requirement
108
90
  requirements:
109
91
  - - ! '>='
110
92
  - !ruby/object:Gem::Version
111
93
  version: '0'
112
- none: false
113
94
  type: :development
114
- - !ruby/object:Gem::Dependency
95
+ prerelease: false
115
96
  version_requirements: !ruby/object:Gem::Requirement
116
97
  requirements:
117
98
  - - ! '>='
118
99
  - !ruby/object:Gem::Version
119
100
  version: '0'
120
- none: false
121
- prerelease: false
101
+ - !ruby/object:Gem::Dependency
122
102
  name: pry
123
103
  requirement: !ruby/object:Gem::Requirement
124
104
  requirements:
125
105
  - - ! '>='
126
106
  - !ruby/object:Gem::Version
127
107
  version: '0'
128
- none: false
129
108
  type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
130
115
  description: The official appsignal.com gem
131
116
  email:
132
117
  - contact@appsignal.com
@@ -138,6 +123,7 @@ files:
138
123
  - .gitignore
139
124
  - .ruby-version
140
125
  - .travis.yml
126
+ - CHANGELOG.md
141
127
  - Gemfile
142
128
  - LICENCE
143
129
  - README.md
@@ -159,6 +145,7 @@ files:
159
145
  - lib/appsignal/cli.rb
160
146
  - lib/appsignal/config.rb
161
147
  - lib/appsignal/exception_notification.rb
148
+ - lib/appsignal/integrations/passenger.rb
162
149
  - lib/appsignal/listener.rb
163
150
  - lib/appsignal/marker.rb
164
151
  - lib/appsignal/middleware.rb
@@ -187,6 +174,7 @@ files:
187
174
  - spec/appsignal/config_spec.rb
188
175
  - spec/appsignal/exception_notification_spec.rb
189
176
  - spec/appsignal/inactive_railtie_spec.rb
177
+ - spec/appsignal/integrations/passenger_spec.rb
190
178
  - spec/appsignal/listener_spec.rb
191
179
  - spec/appsignal/marker_spec.rb
192
180
  - spec/appsignal/middleware/action_view_sanitizer_spec.rb
@@ -207,6 +195,7 @@ files:
207
195
  - spec/support/helpers/transaction_helpers.rb
208
196
  homepage: http://github.com/80beans/appsignal
209
197
  licenses: []
198
+ metadata: {}
210
199
  post_install_message:
211
200
  rdoc_options: []
212
201
  require_paths:
@@ -216,24 +205,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
216
205
  - - ! '>='
217
206
  - !ruby/object:Gem::Version
218
207
  version: '0'
219
- segments:
220
- - 0
221
- hash: -3609057050199006546
222
- none: false
223
208
  required_rubygems_version: !ruby/object:Gem::Requirement
224
209
  requirements:
225
210
  - - ! '>='
226
211
  - !ruby/object:Gem::Version
227
212
  version: '0'
228
- segments:
229
- - 0
230
- hash: -3609057050199006546
231
- none: false
232
213
  requirements: []
233
214
  rubyforge_project:
234
- rubygems_version: 1.8.24
215
+ rubygems_version: 2.0.3
235
216
  signing_key:
236
- specification_version: 3
217
+ specification_version: 4
237
218
  summary: Logs performance and exception data from your app toappsignal.com
238
219
  test_files:
239
220
  - spec/appsignal/agent_spec.rb
@@ -245,6 +226,7 @@ test_files:
245
226
  - spec/appsignal/config_spec.rb
246
227
  - spec/appsignal/exception_notification_spec.rb
247
228
  - spec/appsignal/inactive_railtie_spec.rb
229
+ - spec/appsignal/integrations/passenger_spec.rb
248
230
  - spec/appsignal/listener_spec.rb
249
231
  - spec/appsignal/marker_spec.rb
250
232
  - spec/appsignal/middleware/action_view_sanitizer_spec.rb