appsignal 1.3.6 → 1.4.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rspec +1 -3
  4. data/CHANGELOG.md +2 -28
  5. data/Rakefile +2 -2
  6. data/benchmark.rake +4 -0
  7. data/circle.yml +12 -0
  8. data/ext/agent.yml +11 -11
  9. data/ext/appsignal_extension.c +3 -3
  10. data/ext/extconf.rb +4 -4
  11. data/lib/appsignal.rb +10 -27
  12. data/lib/appsignal/cli/diagnose.rb +3 -4
  13. data/lib/appsignal/cli/install.rb +15 -16
  14. data/lib/appsignal/config.rb +7 -18
  15. data/lib/appsignal/event_formatter.rb +1 -1
  16. data/lib/appsignal/integrations/capistrano/appsignal.cap +1 -1
  17. data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +2 -2
  18. data/lib/appsignal/integrations/object.rb +4 -4
  19. data/lib/appsignal/integrations/sinatra.rb +1 -1
  20. data/lib/appsignal/integrations/webmachine.rb +1 -1
  21. data/lib/appsignal/js_exception_transaction.rb +0 -1
  22. data/lib/appsignal/marker.rb +2 -3
  23. data/lib/appsignal/rack/sinatra_instrumentation.rb +5 -12
  24. data/lib/appsignal/rack/streaming_listener.rb +2 -4
  25. data/lib/appsignal/transaction.rb +3 -3
  26. data/lib/appsignal/transmitter.rb +7 -11
  27. data/lib/appsignal/utils.rb +0 -6
  28. data/lib/appsignal/version.rb +1 -1
  29. data/spec/lib/appsignal/auth_check_spec.rb +2 -0
  30. data/spec/lib/appsignal/capistrano2_spec.rb +78 -98
  31. data/spec/lib/appsignal/capistrano3_spec.rb +77 -56
  32. data/spec/lib/appsignal/cli/diagnose_spec.rb +13 -12
  33. data/spec/lib/appsignal/cli/install_spec.rb +15 -38
  34. data/spec/lib/appsignal/cli/notify_of_deploy_spec.rb +5 -2
  35. data/spec/lib/appsignal/cli_spec.rb +5 -2
  36. data/spec/lib/appsignal/config_spec.rb +17 -131
  37. data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +2 -0
  38. data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +2 -0
  39. data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +2 -0
  40. data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +2 -0
  41. data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +2 -0
  42. data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +2 -0
  43. data/spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb +2 -0
  44. data/spec/lib/appsignal/event_formatter_spec.rb +2 -0
  45. data/spec/lib/appsignal/extension_spec.rb +1 -0
  46. data/spec/lib/appsignal/hooks/celluloid_spec.rb +2 -0
  47. data/spec/lib/appsignal/hooks/data_mapper_spec.rb +2 -0
  48. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +2 -0
  49. data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +2 -0
  50. data/spec/lib/appsignal/hooks/net_http_spec.rb +2 -0
  51. data/spec/lib/appsignal/hooks/passenger_spec.rb +2 -0
  52. data/spec/lib/appsignal/hooks/puma_spec.rb +2 -0
  53. data/spec/lib/appsignal/hooks/rake_spec.rb +1 -0
  54. data/spec/lib/appsignal/hooks/redis_spec.rb +2 -0
  55. data/spec/lib/appsignal/hooks/sequel_spec.rb +2 -0
  56. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +4 -1
  57. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +3 -2
  58. data/spec/lib/appsignal/hooks/unicorn_spec.rb +2 -0
  59. data/spec/lib/appsignal/hooks/webmachine_spec.rb +8 -2
  60. data/spec/lib/appsignal/hooks_spec.rb +2 -0
  61. data/spec/lib/appsignal/integrations/data_mapper_spec.rb +1 -0
  62. data/spec/lib/appsignal/integrations/grape_spec.rb +2 -0
  63. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +1 -0
  64. data/spec/lib/appsignal/integrations/object_spec.rb +1 -30
  65. data/spec/lib/appsignal/integrations/padrino_spec.rb +2 -0
  66. data/spec/lib/appsignal/integrations/railtie_spec.rb +2 -0
  67. data/spec/lib/appsignal/integrations/resque_active_job_spec.rb +2 -0
  68. data/spec/lib/appsignal/integrations/resque_spec.rb +3 -1
  69. data/spec/lib/appsignal/integrations/sinatra_spec.rb +7 -32
  70. data/spec/lib/appsignal/integrations/webmachine_spec.rb +11 -4
  71. data/spec/lib/appsignal/js_exception_transaction_spec.rb +2 -0
  72. data/spec/lib/appsignal/marker_spec.rb +48 -35
  73. data/spec/lib/appsignal/minutely_spec.rb +2 -0
  74. data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +2 -0
  75. data/spec/lib/appsignal/rack/js_exception_catcher_spec.rb +2 -0
  76. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +2 -0
  77. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +6 -46
  78. data/spec/lib/appsignal/rack/streaming_listener_spec.rb +4 -3
  79. data/spec/lib/appsignal/subscriber_spec.rb +2 -0
  80. data/spec/lib/appsignal/transaction_spec.rb +3 -2
  81. data/spec/lib/appsignal/transmitter_spec.rb +20 -53
  82. data/spec/lib/appsignal/update_active_support_spec.rb +2 -0
  83. data/spec/lib/appsignal/utils/params_sanitizer_spec.rb +2 -0
  84. data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +2 -0
  85. data/spec/lib/appsignal/utils_spec.rb +2 -0
  86. data/spec/lib/appsignal_spec.rb +37 -91
  87. data/spec/spec_helper.rb +28 -22
  88. metadata +5 -14
  89. data/spec/lib/appsignal/utils/gzip_spec.rb +0 -10
  90. data/spec/support/helpers/api_request_helper.rb +0 -19
  91. data/spec/support/helpers/directory_helper.rb +0 -25
  92. data/spec/support/helpers/std_streams_helper.rb +0 -35
  93. data/spec/support/helpers/very_specific_error.rb +0 -8
@@ -6,7 +6,7 @@ Appsignal.logger.info("Loading Sinatra (#{Sinatra::VERSION}) integration")
6
6
  app_settings = ::Sinatra::Application.settings
7
7
  Appsignal.config = Appsignal::Config.new(
8
8
  app_settings.root || Dir.pwd,
9
- ENV.fetch('APPSIGNAL_APP_ENV'.freeze, app_settings.environment)
9
+ app_settings.environment
10
10
  )
11
11
 
12
12
  Appsignal.start_logger
@@ -25,7 +25,7 @@ module Appsignal::Integrations
25
25
  handle_exceptions_without_appsignal do
26
26
  begin
27
27
  yield
28
- rescue => e
28
+ rescue Exception => e
29
29
  Appsignal.set_error(e)
30
30
  raise e
31
31
  end
@@ -34,7 +34,6 @@ module Appsignal
34
34
  def set_sample_data
35
35
  {
36
36
  :params => @data['params'],
37
- :session_data => @data['session_data'],
38
37
  :environment => @data['environment'],
39
38
  :tags => @data['tags']
40
39
  }.each do |key, data|
@@ -10,15 +10,14 @@ module Appsignal
10
10
 
11
11
  def transmit
12
12
  transmitter = Transmitter.new(ACTION, config)
13
- puts "Notifying Appsignal of deploy with: "\
14
- "revision: #{marker_data[:revision]}, user: #{marker_data[:user]}"
13
+ puts "Notifying Appsignal of deploy with: revision: #{marker_data[:revision]}, user: #{marker_data[:user]}"
15
14
  result = transmitter.transmit(marker_data)
16
15
  if result == '200'
17
16
  puts 'Appsignal has been notified of this deploy!'
18
17
  else
19
18
  raise "#{result} at #{transmitter.uri}"
20
19
  end
21
- rescue => e
20
+ rescue Exception => e
22
21
  puts "Something went wrong while trying to notify Appsignal: #{e}"
23
22
  end
24
23
  end
@@ -29,7 +29,7 @@ module Appsignal
29
29
  def initialize(app, options = {})
30
30
  Appsignal.logger.debug 'Initializing Appsignal::Rack::SinatraInstrumentation'
31
31
  @app, @options = app, options
32
- @raise_errors_on = raise_errors?(@app)
32
+ @raise_errors_on = @app.settings.raise_errors
33
33
  end
34
34
 
35
35
  def call(env)
@@ -73,23 +73,16 @@ module Appsignal
73
73
  end
74
74
 
75
75
  def action_name(env)
76
- return unless env['sinatra.route']
77
-
78
- if env['SCRIPT_NAME']
76
+ if @options.fetch(:mounted_at, nil)
77
+ method, route = env['sinatra.route'].split(" ")
78
+ "#{method} #{@options[:mounted_at]}#{route}"
79
+ elsif env['SCRIPT_NAME']
79
80
  method, route = env['sinatra.route'].split(" ")
80
81
  "#{method} #{env['SCRIPT_NAME']}#{route}"
81
82
  else
82
83
  env['sinatra.route']
83
84
  end
84
85
  end
85
-
86
- private
87
-
88
- def raise_errors?(app)
89
- app.respond_to?(:settings) &&
90
- app.settings.respond_to?(:raise_errors) &&
91
- app.settings.raise_errors
92
- end
93
86
  end
94
87
  end
95
88
  end
@@ -54,15 +54,13 @@ module Appsignal
54
54
  def each
55
55
  @stream.each { |c| yield(c) }
56
56
  rescue Exception => e
57
- @transaction.set_error(e)
58
- raise e
57
+ @transaction.set_error(e); raise e
59
58
  end
60
59
 
61
60
  def close
62
61
  @stream.close if @stream.respond_to?(:close)
63
62
  rescue Exception => e
64
- @transaction.set_error(e)
65
- raise e
63
+ @transaction.set_error(e); raise e
66
64
  ensure
67
65
  Appsignal::Transaction.complete_current!
68
66
  end
@@ -52,7 +52,7 @@ module Appsignal
52
52
 
53
53
  def complete_current!
54
54
  current.complete
55
- rescue => e
55
+ rescue Exception => e
56
56
  Appsignal.logger.error("Failed to complete transaction ##{current.transaction_id}. #{e.message}")
57
57
  ensure
58
58
  Thread.current[:appsignal_transaction] = nil
@@ -269,9 +269,9 @@ module Appsignal
269
269
  params =
270
270
  begin
271
271
  request.send options[:params_method]
272
- rescue => e
272
+ rescue Exception => ex
273
273
  # Getting params from the request has been know to fail.
274
- Appsignal.logger.debug "Exception while getting params: #{e}"
274
+ Appsignal.logger.debug "Exception while getting params: #{ex}"
275
275
  nil
276
276
  end
277
277
  return unless params
@@ -8,6 +8,7 @@ module Appsignal
8
8
  class Transmitter
9
9
  CONTENT_TYPE = 'application/json; charset=UTF-8'.freeze
10
10
  CONTENT_ENCODING = 'gzip'.freeze
11
+ CA_FILE_PATH = File.expand_path(File.join(__FILE__, '../../../resources/cacert.pem'))
11
12
 
12
13
  HTTP_ERRORS = [
13
14
  EOFError,
@@ -41,7 +42,7 @@ module Appsignal
41
42
  end
42
43
 
43
44
  def transmit(payload)
44
- config.logger.debug "Transmitting payload to #{uri}"
45
+ Appsignal.logger.debug "Transmitting payload to #{uri}"
45
46
  http_client.request(http_post(payload)).code
46
47
  end
47
48
 
@@ -51,8 +52,10 @@ module Appsignal
51
52
  Net::HTTP::Post.new(uri.request_uri).tap do |request|
52
53
  request['Content-Type'] = CONTENT_TYPE
53
54
  request['Content-Encoding'] = CONTENT_ENCODING
54
- request.body = Appsignal::Utils::Gzip.compress \
55
- Appsignal::Utils::JSON.generate(payload)
55
+ request.body = Zlib::Deflate.deflate(
56
+ Appsignal::Utils.json_generate(payload),
57
+ Zlib::BEST_SPEED
58
+ )
56
59
  end
57
60
  end
58
61
 
@@ -68,14 +71,7 @@ module Appsignal
68
71
  http.use_ssl = true
69
72
  http.ssl_version = :TLSv1
70
73
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
71
-
72
- ca_file = config[:ca_file_path]
73
- if ca_file && File.exist?(ca_file) && File.readable?(ca_file)
74
- http.ca_file = ca_file
75
- else
76
- config.logger.warn "Ignoring non-existing or unreadable "\
77
- "`ca_file_path`: #{ca_file}"
78
- end
74
+ http.ca_file = CA_FILE_PATH
79
75
  end
80
76
  end
81
77
  end
@@ -52,11 +52,5 @@ module Appsignal
52
52
 
53
53
  extend ClassMethods
54
54
  end
55
-
56
- class Gzip
57
- def self.compress(body)
58
- Zlib::Deflate.deflate(body, Zlib::BEST_SPEED)
59
- end
60
- end
61
55
  end
62
56
  end
@@ -1,5 +1,5 @@
1
1
  require 'yaml'
2
2
 
3
3
  module Appsignal
4
- VERSION = '1.3.6'
4
+ VERSION = '1.4.0.alpha.1'
5
5
  end
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe Appsignal::AuthCheck do
2
4
  let(:config) { project_fixture_config }
3
5
  let(:logger) { Logger.new(StringIO.new) }
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  if capistrano2_present?
2
4
  require 'capistrano'
3
5
  require 'capistrano/configuration'
@@ -6,36 +8,39 @@ if capistrano2_present?
6
8
  describe "Capistrano 2 integration" do
7
9
  let(:out_stream) { StringIO.new }
8
10
  let(:config) { project_fixture_config }
9
- let(:capistrano_config) do
10
- Capistrano::Configuration.new.tap do |c|
11
- c.set(:rails_env, 'production')
12
- c.set(:repository, 'master')
13
- c.set(:deploy_to, '/home/username/app')
14
- c.set(:current_release, '')
15
- c.set(:current_revision, '503ce0923ed177a3ce000005')
16
- c.dry_run = false
17
- end
18
- end
11
+
19
12
  before do
20
- Appsignal::Capistrano.tasks(capistrano_config)
13
+ @original_stdout = $stdout
14
+ $stdout = out_stream
15
+ end
16
+ after do
17
+ $stdout = @original_stdout
21
18
  end
22
- around do |example|
23
- capture_stdout(out_stream) { example.run }
19
+
20
+ before :all do
21
+ @capistrano_config = Capistrano::Configuration.new
22
+ Appsignal::Capistrano.tasks(@capistrano_config)
24
23
  end
25
24
 
26
25
  it "should have a deploy task" do
27
- capistrano_config.find_task('appsignal:deploy').should_not be_nil
26
+ @capistrano_config.find_task('appsignal:deploy').should_not be_nil
28
27
  end
29
28
 
30
29
  describe "appsignal:deploy task" do
31
30
  before do
31
+ @capistrano_config.set(:rails_env, 'production')
32
+ @capistrano_config.set(:repository, 'master')
33
+ @capistrano_config.set(:deploy_to, '/home/username/app')
34
+ @capistrano_config.set(:current_release, '')
35
+ @capistrano_config.set(:current_revision, '503ce0923ed177a3ce000005')
36
+ @capistrano_config.dry_run = false
32
37
  ENV['USER'] = 'batman'
33
38
  ENV['PWD'] = project_fixture_path
34
39
  end
35
40
 
36
41
  context "config" do
37
42
  before do
38
- capistrano_config.dry_run = true
43
+ @capistrano_config.dry_run = true
39
44
  end
40
45
 
41
46
  it "should be instantiated with the right params" do
@@ -49,7 +54,7 @@ if capistrano2_present?
49
54
 
50
55
  context "when appsignal_config is available" do
51
56
  before do
52
- capistrano_config.set(:appsignal_config, :name => 'AppName')
57
+ @capistrano_config.set(:appsignal_config, :name => 'AppName')
53
58
  end
54
59
 
55
60
  it "should be instantiated with the right params" do
@@ -63,8 +68,8 @@ if capistrano2_present?
63
68
 
64
69
  context "when rack_env is used instead of rails_env" do
65
70
  before do
66
- capistrano_config.unset(:rails_env)
67
- capistrano_config.set(:rack_env, 'rack_production')
71
+ @capistrano_config.unset(:rails_env)
72
+ @capistrano_config.set(:rack_env, 'rack_production')
68
73
  end
69
74
 
70
75
  it "should be instantiated with the right params" do
@@ -76,51 +81,12 @@ if capistrano2_present?
76
81
  )
77
82
  end
78
83
  end
79
-
80
- context "when stage is used instead of rack_env / rails_env" do
81
- before do
82
- capistrano_config.unset(:rails_env)
83
- capistrano_config.set(:stage, 'stage_production')
84
- end
85
-
86
- it "should be instantiated with the right params" do
87
- Appsignal::Config.should_receive(:new).with(
88
- project_fixture_path,
89
- 'stage_production',
90
- {:name => 'AppName'},
91
- kind_of(Logger)
92
- )
93
- end
94
- end
95
-
96
- context "when appsignal_env is set" do
97
- before do
98
- capistrano_config.set(:rack_env, 'rack_production')
99
- capistrano_config.set(:stage, 'stage_production')
100
- capistrano_config.set(:appsignal_env, 'appsignal_production')
101
- end
102
-
103
- it "should prefer the appsignal_env rather than stage, rails_env and rack_env" do
104
- Appsignal::Config.should_receive(:new).with(
105
- project_fixture_path,
106
- 'appsignal_production',
107
- {:name => 'AppName'},
108
- kind_of(Logger)
109
- )
110
- end
111
- end
112
84
  end
113
85
 
114
- after do
115
- capistrano_config.find_and_execute_task('appsignal:deploy')
116
- end
86
+ after { @capistrano_config.find_and_execute_task('appsignal:deploy') }
117
87
  end
118
88
 
119
- describe "markers" do
120
- def stub_marker_request(data = {})
121
- stub_api_request config, 'markers', marker_data.merge(data)
122
- end
123
-
89
+ context "send marker" do
124
90
  let(:marker_data) do
125
91
  {
126
92
  :revision => '503ce0923ed177a3ce000005',
@@ -129,66 +95,80 @@ if capistrano2_present?
129
95
  end
130
96
 
131
97
  context "when active for this environment" do
132
- it "transmits marker" do
133
- stub_marker_request.to_return(:status => 200)
134
- capistrano_config.find_and_execute_task('appsignal:deploy')
135
-
136
- expect(out_stream.string).to include \
137
- 'Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
138
- 'Appsignal has been notified of this deploy!'
98
+ before do
99
+ @marker = Appsignal::Marker.new(
100
+ marker_data,
101
+ config
102
+ )
103
+ Appsignal::Marker.stub(:new => @marker)
139
104
  end
140
105
 
141
- context "with overridden revision" do
106
+ context "proper setup" do
142
107
  before do
143
- capistrano_config.set(:appsignal_revision, 'abc123')
144
- stub_marker_request(:revision => 'abc123').to_return(:status => 200)
145
- capistrano_config.find_and_execute_task('appsignal:deploy')
108
+ @transmitter = double
109
+ Appsignal::Transmitter.should_receive(:new).and_return(@transmitter)
146
110
  end
147
111
 
148
- it "transmits the overriden revision" do
149
- expect(out_stream.string).to include \
150
- 'Notifying Appsignal of deploy with: revision: abc123, user: batman',
151
- 'Appsignal has been notified of this deploy!'
112
+ it "should add the correct marker data" do
113
+ Appsignal::Marker.should_receive(:new).with(
114
+ marker_data,
115
+ kind_of(Appsignal::Config)
116
+ ).and_return(@marker)
117
+
118
+ @capistrano_config.find_and_execute_task('appsignal:deploy')
152
119
  end
153
- end
154
120
 
155
- context "with failed request" do
156
- before do
157
- stub_marker_request.to_return(:status => 500)
158
- capistrano_config.find_and_execute_task('appsignal:deploy')
121
+ it "should transmit data" do
122
+ @transmitter.should_receive(:transmit).and_return('200')
123
+ @capistrano_config.find_and_execute_task('appsignal:deploy')
124
+ out_stream.string.should include('Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman')
125
+ out_stream.string.should include('Appsignal has been notified of this deploy!')
159
126
  end
160
127
 
161
- it "does not transmit marker" do
162
- output = out_stream.string
163
- expect(output).to include \
164
- 'Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
165
- 'Something went wrong while trying to notify Appsignal:'
166
- expect(output).to_not include 'Appsignal has been notified of this deploy!'
128
+ context "with overridden revision" do
129
+ before do
130
+ @capistrano_config.set(:appsignal_revision, 'abc123')
131
+ end
132
+ it "should add the correct marker data" do
133
+ Appsignal::Marker.should_receive(:new).with(
134
+ {
135
+ :revision => 'abc123',
136
+ :user => 'batman'
137
+ },
138
+ kind_of(Appsignal::Config)
139
+ ).and_return(@marker)
140
+
141
+ @capistrano_config.find_and_execute_task('appsignal:deploy')
142
+ end
167
143
  end
168
144
  end
169
145
 
170
- context "when dry run" do
171
- before do
172
- capistrano_config.dry_run = true
173
- capistrano_config.find_and_execute_task('appsignal:deploy')
174
- end
146
+ it "should not transmit data" do
147
+ @capistrano_config.find_and_execute_task('appsignal:deploy')
148
+ out_stream.string.should include('Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman')
149
+ out_stream.string.should include('Something went wrong while trying to notify Appsignal:')
150
+ end
151
+
152
+ context "dry run" do
153
+ before { @capistrano_config.dry_run = true }
175
154
 
176
- it "does not transmit marker" do
177
- expect(out_stream.string).to include \
178
- 'Dry run: AppSignal deploy marker not actually sent.'
155
+ it "should not send deploy marker" do
156
+ @marker.should_not_receive(:transmit)
157
+ @capistrano_config.find_and_execute_task('appsignal:deploy')
158
+ out_stream.string.should include('Dry run: AppSignal deploy marker not actually sent.')
179
159
  end
180
160
  end
181
161
  end
182
162
 
183
163
  context "when not active for this environment" do
184
164
  before do
185
- capistrano_config.set(:rails_env, 'nonsense')
186
- capistrano_config.find_and_execute_task('appsignal:deploy')
165
+ @capistrano_config.set(:rails_env, 'nonsense')
187
166
  end
188
167
 
189
- it "does not transmit marker" do
190
- expect(out_stream.string).to include \
191
- "Not notifying of deploy, config is not active for environment: nonsense"
168
+ it "should not send deploy marker" do
169
+ Appsignal::Marker.should_not_receive(:new)
170
+ @capistrano_config.find_and_execute_task('appsignal:deploy')
171
+ out_stream.string.should include('Not notifying of deploy, config is not active')
192
172
  end
193
173
  end
194
174
  end