appsignal 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -40,9 +40,7 @@ Appsignal.postprocessing_middleware.add MiddlewareTemplate
40
40
  ```ruby
41
41
  class RemoveBoringPayload
42
42
  def call(event)
43
- unless event.name == 'interesting'
44
- event.payload = {}
45
- end
43
+ event.payload.clear unless event.name == 'interesting'
46
44
  yield
47
45
  end
48
46
  end
@@ -1,8 +1,10 @@
1
1
  development: &development
2
2
  endpoint: "http://localhost:3000/1"
3
3
  api_key: "abc"
4
- active: true
4
+ active: <%= 'true' %>
5
5
  production:
6
6
  <<: *development
7
+ api_key: "def"
7
8
  test:
8
9
  <<: *development
10
+ api_key: "ghi"
@@ -11,28 +11,51 @@ module Appsignal
11
11
  :slow_request_threshold => 200
12
12
  }.freeze
13
13
 
14
- attr_accessor :root_path, :rails_env
14
+ attr_reader :configurations, :project_path, :env
15
15
 
16
- def initialize(root_path, rails_env, logger=Appsignal.logger)
17
- @root_path = root_path
18
- @rails_env = rails_env
16
+ def initialize(project_path, env, logger=Appsignal.logger)
17
+ @project_path = project_path
18
+ @env = env.to_sym
19
19
  @logger = logger
20
+ @configurations = {}
20
21
  end
21
22
 
22
23
  def load
23
- file = File.join(@root_path, 'config/appsignal.yml')
24
+ return unless load_configurations_from_disk
25
+ return unless used_unique_api_keys
26
+ return unless current_environment_present
27
+
28
+ DEFAULT_CONFIG.merge(configurations[env])
29
+ end
30
+
31
+ protected
32
+
33
+ def load_configurations_from_disk
34
+ file = File.join(project_path, 'config', 'appsignal.yml')
24
35
  unless File.exists?(file)
25
- carefully_log_error "config not found at: #{file}"
26
- return
36
+ carefully_log_error "config not found at: '#{file}'"
37
+ return false
27
38
  end
39
+ @configurations = YAML.load(ERB.new(IO.read(file)).result)
40
+ configurations.each { |k,v| v.symbolize_keys! }
41
+ configurations.symbolize_keys!
42
+ true
43
+ end
28
44
 
29
- config = YAML.load_file(file)[@rails_env]
30
- unless config
31
- carefully_log_error "config for '#{@rails_env}' not found"
32
- return
45
+ def used_unique_api_keys
46
+ keys = configurations.each_value.map { |config| config[:api_key] }.compact
47
+ if keys.uniq.count < keys.count
48
+ carefully_log_error('Duplicate API keys found in appsignal.yml')
49
+ false
50
+ else
51
+ true
33
52
  end
53
+ end
34
54
 
35
- DEFAULT_CONFIG.merge(config.symbolize_keys)
55
+ def current_environment_present
56
+ return true if configurations[env].present?
57
+ carefully_log_error "config for '#{env}' not found"
58
+ false
36
59
  end
37
60
 
38
61
  end
@@ -1,10 +1,14 @@
1
1
  module Appsignal
2
2
  class Railtie < Rails::Railtie
3
3
  initializer "appsignal.configure_rails_initialization" do |app|
4
- Appsignal.logger = Logger.new(Rails.root.join('log/appsignal.log')).tap do |l|
5
- l.level = Logger::INFO
4
+ # Some apps when run from the console do not have Rails.root set, there's
5
+ # currently no way to spec this.
6
+ if Rails.root
7
+ Appsignal.logger = Logger.new(Rails.root.join('log/appsignal.log')).tap do |l|
8
+ l.level = Logger::INFO
9
+ end
10
+ Appsignal.flush_in_memory_log
6
11
  end
7
- Appsignal.flush_in_memory_log
8
12
 
9
13
  if Appsignal.active?
10
14
  app.middleware.
@@ -1,3 +1,3 @@
1
1
  module Appsignal
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -5,7 +5,7 @@ describe Appsignal::AuthCheck do
5
5
  before do
6
6
  @transmitter = mock
7
7
  Appsignal::Transmitter.should_receive(:new).
8
- with('http://localhost:3000/1', 'auth', 'abc').
8
+ with('http://localhost:3000/1', 'auth', 'def').
9
9
  and_return(@transmitter)
10
10
  end
11
11
 
@@ -89,13 +89,15 @@ describe Appsignal::CLI do
89
89
  end
90
90
  end
91
91
 
92
- describe "notify_of_deploy" do
92
+ describe "#notify_of_deploy" do
93
93
  it "should validate that all options have been supplied" do
94
94
  options = {}
95
95
  cli.should_receive(:validate_required_options).with(
96
96
  [:revision, :repository, :user, :environment],
97
97
  options
98
98
  )
99
+ Appsignal::Marker.should_receive(:new).
100
+ and_return(mock(:transmit => true))
99
101
  cli.notify_of_deploy(options)
100
102
  end
101
103
 
@@ -104,7 +106,7 @@ describe Appsignal::CLI do
104
106
  Appsignal::Transmitter.should_receive(:new).with(
105
107
  'http://localhost:3000/1',
106
108
  'markers',
107
- 'abc'
109
+ 'def'
108
110
  ).and_return(transmitter)
109
111
  transmitter.should_receive(:transmit).with(
110
112
  :revision => 'aaaaa',
@@ -2,63 +2,114 @@ require 'spec_helper'
2
2
 
3
3
  describe Appsignal::Config do
4
4
  let(:logger_parameter) { [] }
5
- subject { Appsignal::Config.new(Dir.pwd, 'test', *logger_parameter).load }
6
-
7
- it {
8
- should == {
9
- :ignore_exceptions => [],
10
- :endpoint => 'http://localhost:3000/1',
11
- :slow_request_threshold => 200,
12
- :api_key => 'abc',
13
- :active => true
5
+ let(:path) { Dir.pwd }
6
+ let(:config) { Appsignal::Config.new(path, 'test', *logger_parameter) }
7
+
8
+ describe "#load" do
9
+ subject { config.load }
10
+
11
+ it "should never have logged an error" do
12
+ Appsignal.logger.should_not_receive(:error)
13
+ subject
14
+ end
15
+
16
+ it {
17
+ should == {
18
+ :ignore_exceptions => [],
19
+ :endpoint => 'http://localhost:3000/1',
20
+ :slow_request_threshold => 200,
21
+ :api_key => 'ghi',
22
+ :active => true
23
+ }
14
24
  }
15
- }
16
25
 
17
- context 'when there is no config file' do
18
- before { Dir.stub(:pwd => '/not/existing') }
26
+ context 'when there is no config file' do
27
+ before { Dir.stub(:pwd => '/not/existing') }
19
28
 
20
- it "should log error" do
21
- Appsignal.logger.should_receive(:error).with(
22
- "config not found at:"\
23
- " /not/existing/config/appsignal.yml"
24
- )
29
+ it { should be_nil }
25
30
  end
26
31
 
27
- context "when the logger has no #error method" do
28
- let(:logger) { mock(:logger) }
29
- let(:logger_parameter) { [logger] }
32
+ context "the env is not in the config" do
33
+ before { config.stub(:current_environment_present => false) }
30
34
 
31
- it "should log the error using #important" do
32
- logger.should_receive(:important).with(
33
- "config not found at:"\
34
- " /not/existing/config/appsignal.yml"
35
- )
36
- end
35
+ it { should be_nil }
37
36
  end
38
37
 
39
- after { subject }
38
+ context "when an api key is used for more then one environment" do
39
+ before { config.stub(:used_unique_api_keys => false) }
40
+
41
+ it { should be_nil }
42
+ end
40
43
  end
41
44
 
42
- context "the env is not in the config" do
43
- subject { Appsignal::Config.new(Dir.pwd, 'staging', *logger_parameter).load }
45
+ # protected
44
46
 
45
- it "should generate error" do
46
- Appsignal.logger.should_receive(:error).with(
47
- "config for 'staging' not found"
48
- )
47
+ describe "#load_configurations_from_disk" do
48
+ subject do
49
+ config.send(:load_configurations_from_disk)
50
+ config.configurations
49
51
  end
50
52
 
51
- context "when the logger has no #error method" do
52
- let(:logger) { mock(:logger) }
53
- let(:logger_parameter) { [logger] }
53
+ context "when the file is present" do
54
+ before { config.should_not_receive(:carefully_log_error) }
54
55
 
55
- it "should log the error using #important" do
56
- logger.should_receive(:important).with(
57
- "config for 'staging' not found"
58
- )
56
+ it { should_not be_empty }
57
+ end
58
+
59
+ context "when the file is not present" do
60
+ before do
61
+ config.should_receive(:carefully_log_error)
62
+ config.stub(:project_path => '/non/existing')
59
63
  end
64
+
65
+ it { should be_empty }
60
66
  end
67
+ end
68
+
69
+ describe "#used_unique_api_keys" do
70
+ let(:env) { {:api_key => :foo} }
71
+ subject { config.send(:used_unique_api_keys) }
61
72
 
62
- after { subject }
73
+ context "when using all unique keys" do
74
+ before do
75
+ config.should_not_receive(:carefully_log_error)
76
+ config.stub(:configurations => {1 => env})
77
+ end
78
+
79
+ it { should be_true }
80
+ end
81
+
82
+ context "when using non-unique keys" do
83
+ before do
84
+ config.should_receive(:carefully_log_error).
85
+ with("Duplicate API keys found in appsignal.yml")
86
+ config.stub(:configurations => {:production => env, :staging => env})
87
+ end
88
+
89
+ it { should be_false }
90
+ end
91
+ end
92
+
93
+ describe "#current_environment_present" do
94
+ subject { config.send(:current_environment_present) }
95
+
96
+ context "when the current environment is present" do
97
+ before do
98
+ config.should_not_receive(:carefully_log_error)
99
+ config.stub(:configurations => {:test => :foo})
100
+ end
101
+
102
+ it { should be_true }
103
+ end
104
+
105
+ context "when the current environment is absent" do
106
+ before do
107
+ config.should_receive(:carefully_log_error).
108
+ with("config for 'test' not found")
109
+ config.stub(:configurations => {})
110
+ end
111
+
112
+ it { should be_false }
113
+ end
63
114
  end
64
115
  end
@@ -1,11 +1,10 @@
1
1
  module NotificationHelpers
2
2
 
3
3
  def notification_event(args={})
4
- time = Time.parse('01-01-2001 10:01:00')
5
4
  args = {
6
5
  :name => 'process_action.action_controller',
7
- :start => time,
8
- :ending => time + 0.100,
6
+ :start => fixed_time,
7
+ :ending => fixed_time + 0.1,
9
8
  :tid => '1',
10
9
  :payload => create_payload
11
10
  }.merge(args)
@@ -1,5 +1,9 @@
1
1
  module TransactionHelpers
2
2
 
3
+ def fixed_time
4
+ @fixed_time ||= Time.at(978364860.0)
5
+ end
6
+
3
7
  def transaction_with_exception
4
8
  appsignal_transaction.tap do |o|
5
9
  begin
@@ -18,24 +22,22 @@ module TransactionHelpers
18
22
  end
19
23
 
20
24
  def slow_transaction(args={})
21
- time = Time.parse('01-01-2001 10:01:00')
22
25
  appsignal_transaction(
23
26
  {
24
27
  :process_action_event => notification_event(
25
- :start => time,
26
- :ending => time + Appsignal.config[:slow_request_threshold] / 1000.0
28
+ :start => fixed_time,
29
+ :ending => fixed_time + Appsignal.config[:slow_request_threshold] / 1000.0
27
30
  )
28
31
  }.merge(args)
29
32
  )
30
33
  end
31
34
 
32
35
  def slower_transaction(args={})
33
- time = Time.parse('01-01-2001 10:01:00')
34
36
  appsignal_transaction(
35
37
  {
36
38
  :process_action_event => notification_event(
37
- :start => time,
38
- :ending => time + Appsignal.config[:slow_request_threshold] / 500.0
39
+ :start => fixed_time,
40
+ :ending => fixed_time + Appsignal.config[:slow_request_threshold] / 500.0
39
41
  )
40
42
  }.merge(args)
41
43
  )
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
5
4
  prerelease:
5
+ version: 0.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Robert Beekman
@@ -13,120 +13,120 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-04-12 00:00:00.000000000 Z
16
+ date: 2013-04-18 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
- name: rails
20
- requirement: !ruby/object:Gem::Requirement
21
- none: false
19
+ version_requirements: !ruby/object:Gem::Requirement
22
20
  requirements:
23
21
  - - ~>
24
22
  - !ruby/object:Gem::Version
25
23
  version: '3.0'
26
- type: :runtime
27
- prerelease: false
28
- version_requirements: !ruby/object:Gem::Requirement
29
24
  none: false
25
+ prerelease: false
26
+ name: rails
27
+ requirement: !ruby/object:Gem::Requirement
30
28
  requirements:
31
29
  - - ~>
32
30
  - !ruby/object:Gem::Version
33
31
  version: '3.0'
32
+ none: false
33
+ type: :runtime
34
34
  - !ruby/object:Gem::Dependency
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ none: false
41
+ prerelease: false
35
42
  name: rake
36
43
  requirement: !ruby/object:Gem::Requirement
37
- none: false
38
44
  requirements:
39
45
  - - ! '>='
40
46
  - !ruby/object:Gem::Version
41
47
  version: '0'
48
+ none: false
42
49
  type: :runtime
43
- prerelease: false
50
+ - !ruby/object:Gem::Dependency
44
51
  version_requirements: !ruby/object:Gem::Requirement
45
- none: false
46
52
  requirements:
47
53
  - - ! '>='
48
54
  - !ruby/object:Gem::Version
49
55
  version: '0'
50
- - !ruby/object:Gem::Dependency
56
+ none: false
57
+ prerelease: false
51
58
  name: json
52
59
  requirement: !ruby/object:Gem::Requirement
53
- none: false
54
60
  requirements:
55
61
  - - ! '>='
56
62
  - !ruby/object:Gem::Version
57
63
  version: '0'
64
+ none: false
58
65
  type: :runtime
59
- prerelease: false
66
+ - !ruby/object:Gem::Dependency
60
67
  version_requirements: !ruby/object:Gem::Requirement
61
- none: false
62
68
  requirements:
63
69
  - - ! '>='
64
70
  - !ruby/object:Gem::Version
65
71
  version: '0'
66
- - !ruby/object:Gem::Dependency
72
+ none: false
73
+ prerelease: false
67
74
  name: rspec
68
75
  requirement: !ruby/object:Gem::Requirement
69
- none: false
70
76
  requirements:
71
77
  - - ! '>='
72
78
  - !ruby/object:Gem::Version
73
79
  version: '0'
80
+ none: false
74
81
  type: :development
75
- prerelease: false
82
+ - !ruby/object:Gem::Dependency
76
83
  version_requirements: !ruby/object:Gem::Requirement
77
- none: false
78
84
  requirements:
79
85
  - - ! '>='
80
86
  - !ruby/object:Gem::Version
81
87
  version: '0'
82
- - !ruby/object:Gem::Dependency
88
+ none: false
89
+ prerelease: false
83
90
  name: capistrano
84
91
  requirement: !ruby/object:Gem::Requirement
85
- none: false
86
92
  requirements:
87
93
  - - ! '>='
88
94
  - !ruby/object:Gem::Version
89
95
  version: '0'
96
+ none: false
90
97
  type: :development
91
- prerelease: false
98
+ - !ruby/object:Gem::Dependency
92
99
  version_requirements: !ruby/object:Gem::Requirement
93
- none: false
94
100
  requirements:
95
101
  - - ! '>='
96
102
  - !ruby/object:Gem::Version
97
103
  version: '0'
98
- - !ruby/object:Gem::Dependency
104
+ none: false
105
+ prerelease: false
99
106
  name: generator_spec
100
107
  requirement: !ruby/object:Gem::Requirement
101
- none: false
102
108
  requirements:
103
109
  - - ! '>='
104
110
  - !ruby/object:Gem::Version
105
111
  version: '0'
112
+ none: false
106
113
  type: :development
107
- prerelease: false
114
+ - !ruby/object:Gem::Dependency
108
115
  version_requirements: !ruby/object:Gem::Requirement
109
- none: false
110
116
  requirements:
111
117
  - - ! '>='
112
118
  - !ruby/object:Gem::Version
113
119
  version: '0'
114
- - !ruby/object:Gem::Dependency
120
+ none: false
121
+ prerelease: false
115
122
  name: pry
116
123
  requirement: !ruby/object:Gem::Requirement
117
- none: false
118
124
  requirements:
119
125
  - - ! '>='
120
126
  - !ruby/object:Gem::Version
121
127
  version: '0'
122
- type: :development
123
- prerelease: false
124
- version_requirements: !ruby/object:Gem::Requirement
125
128
  none: false
126
- requirements:
127
- - - ! '>='
128
- - !ruby/object:Gem::Version
129
- version: '0'
129
+ type: :development
130
130
  description: The official appsignal.com gem
131
131
  email:
132
132
  - contact@appsignal.com
@@ -212,20 +212,26 @@ rdoc_options: []
212
212
  require_paths:
213
213
  - lib
214
214
  required_ruby_version: !ruby/object:Gem::Requirement
215
- none: false
216
215
  requirements:
217
216
  - - ! '>='
218
217
  - !ruby/object:Gem::Version
219
218
  version: '0'
220
- required_rubygems_version: !ruby/object:Gem::Requirement
219
+ segments:
220
+ - 0
221
+ hash: -3609057050199006546
221
222
  none: false
223
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
224
  requirements:
223
225
  - - ! '>='
224
226
  - !ruby/object:Gem::Version
225
227
  version: '0'
228
+ segments:
229
+ - 0
230
+ hash: -3609057050199006546
231
+ none: false
226
232
  requirements: []
227
233
  rubyforge_project:
228
- rubygems_version: 1.8.23
234
+ rubygems_version: 1.8.24
229
235
  signing_key:
230
236
  specification_version: 3
231
237
  summary: Logs performance and exception data from your app toappsignal.com