bugsnag 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 James Smith
1
+ Copyright (c) 2012 Bugsnag
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,18 +1,15 @@
1
- Official Bugsnag Notifier for Ruby
2
- ==================================
1
+ Bugsnag Notifier for Ruby
2
+ =========================
3
3
 
4
4
  The Bugsnag Notifier for Ruby gives you instant notification of exceptions
5
5
  thrown from your **Rails**, **Sinatra**, **Rack** or **plain Ruby** app.
6
6
  Any uncaught exceptions will trigger a notification to be sent to your
7
7
  Bugsnag project.
8
8
 
9
-
10
- What is Bugsnag?
11
- ----------------
12
-
13
9
  [Bugsnag](http://bugsnag.com) captures errors in real-time from your web,
14
10
  mobile and desktop applications, helping you to understand and resolve them
15
- as fast as possible. [Create a free account](http://bugsnag.com).
11
+ as fast as possible. [Create a free account](http://bugsnag.com) to start
12
+ capturing exceptions from your applications.
16
13
 
17
14
 
18
15
  How to Install (Rails)
@@ -199,6 +196,77 @@ By default, `ignore_classes` contains the following classes:
199
196
  ```
200
197
 
201
198
 
199
+ Deploy Tracking
200
+ ---------------
201
+
202
+ Bugsnag allows you to track deploys of your apps. By sending the
203
+ source revision or application version to bugsnag.com when you deploy a new
204
+ version of your app, you'll be able to see which deploy each error was
205
+ introduced in.
206
+
207
+ ### Using Capistrano
208
+
209
+ If you use [capistrano](https://github.com/capistrano/capistrano) to deploy
210
+ your apps, you can enable deploy tracking by adding the following line to your
211
+ app's `deploy.rb`:
212
+
213
+ ```ruby
214
+ require "bugsnag/capistrano"
215
+ ```
216
+
217
+ ### Using Rake
218
+
219
+ If you aren't using capistrano, you can run the following rake command from
220
+ your deploy scripts.
221
+
222
+ ```shell
223
+ rake bugsnag:deploy BUGSNAG_REVISION=source-control-revision BUGSNAG_RELEASE_STAGE=production
224
+ ```
225
+
226
+ The bugsnag rake tasks will be automatically available for Rails 3
227
+ apps, to make the rake tasks available in other apps, add the following to
228
+ your `Rakefile`:
229
+
230
+ ```ruby
231
+ require "bugsnag/tasks"
232
+ ```
233
+
234
+ ### Configuring Deploy Tracking
235
+
236
+ You can set the following environmental variables to override or specify
237
+ additional deploy information:
238
+
239
+ - **BUGSNAG_RELEASE_STAGE** -
240
+ The release stage (eg, production, staging) currently being deployed.
241
+ This is set automatically from your Bugsnag settings or rails/rack
242
+ environment.
243
+
244
+ - **BUGSNAG_API_KEY** -
245
+ Your Bugsnag API key. This is set automatically from your Bugsnag
246
+ settings in your app.
247
+
248
+ - **BUGSNAG_REPOSITORY** -
249
+ The repository from which you are deploying the code. This is set
250
+ automatically if you are using capistrano.
251
+
252
+ - **BUGSNAG_BRANCH** -
253
+ The source control branch from which you are deploying the code.
254
+ This is set automatically if you are using capistrano.
255
+
256
+ - **BUGSNAG_REVISION** -
257
+ The source control revision for the code you are currently deploying.
258
+ This is set automatically if you are using capistrano.
259
+
260
+ - **BUGSNAG_APP_VERSION** -
261
+ The app version of the code you are currently deploying. Only set this
262
+ if you tag your releases with [semantic version numbers](http://semver.org/)
263
+ and deploy infrequently.
264
+
265
+ For more information, check out the [deploy tracking api](https://bugsnag.com/docs/deploy-tracking-api)
266
+ documentation.
267
+
268
+
269
+
202
270
  Reporting Bugs or Feature Requests
203
271
  ----------------------------------
204
272
 
@@ -210,21 +278,15 @@ project here:
210
278
 
211
279
  Contributing
212
280
  ------------
213
-
214
- - Check out the latest master to make sure the feature hasn't been
215
- implemented or the bug hasn't been fixed yet
216
- - Check out the issue tracker to make sure someone already hasn't requested
217
- it and/or contributed it
218
- - Fork the project
219
- - Start a feature/bugfix branch
281
+
282
+ - [Fork](https://help.github.com/articles/fork-a-repo) the [notifier on github](https://github.com/bugsnag/bugsnag-ruby)
220
283
  - Commit and push until you are happy with your contribution
284
+ - [Make a pull request](https://help.github.com/articles/using-pull-requests)
221
285
  - Thanks!
222
286
 
223
287
 
224
288
  License
225
289
  -------
226
290
 
227
- The Bugsnag ruby notifier is released under the
228
- Apache License, Version 2.0. Read the full license here:
229
-
230
- <http://www.apache.org/licenses/LICENSE-2.0>
291
+ The Bugsnag ruby notifier is free software released under the MIT License.
292
+ See [LICENSE.txt](https://github.com/bugsnag/bugsnag-ruby/blob/master/LICENSE.txt) for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "bugsnag"
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Smith"]
12
- s.date = "2012-06-18"
12
+ s.date = "2012-07-17"
13
13
  s.description = "Ruby notifier for bugsnag.com"
14
14
  s.email = "james@bugsnag.com"
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "bugsnag.gemspec",
28
28
  "lib/bugsnag.rb",
29
+ "lib/bugsnag/capistrano.rb",
29
30
  "lib/bugsnag/configuration.rb",
30
31
  "lib/bugsnag/delay/resque.rb",
31
32
  "lib/bugsnag/helpers.rb",
@@ -35,8 +36,10 @@ Gem::Specification.new do |s|
35
36
  "lib/bugsnag/rails/action_controller_rescue.rb",
36
37
  "lib/bugsnag/rails/controller_methods.rb",
37
38
  "lib/bugsnag/railtie.rb",
39
+ "lib/bugsnag/tasks.rb",
38
40
  "lib/bugsnag/version.rb",
39
41
  "lib/resque/failure/bugsnag.rb",
42
+ "lib/tasks/bugsnag.rake",
40
43
  "rails/init.rb",
41
44
  "test/helper.rb",
42
45
  "test/test_bugsnag.rb"
@@ -44,7 +47,7 @@ Gem::Specification.new do |s|
44
47
  s.homepage = "http://github.com/bugsnag/bugsnag-ruby"
45
48
  s.licenses = ["MIT"]
46
49
  s.require_paths = ["lib"]
47
- s.rubygems_version = "1.8.15"
50
+ s.rubygems_version = "1.8.24"
48
51
  s.summary = "Ruby notifier for bugsnag.com"
49
52
 
50
53
  if s.respond_to? :specification_version then
@@ -51,6 +51,15 @@ module Bugsnag
51
51
  configuration.logger.info(LOG_PREFIX + message) if configuration.logger
52
52
  end
53
53
 
54
+ # Warning logger
55
+ def warn(message)
56
+ if configuration.logger
57
+ configuration.logger.warn(LOG_PREFIX + message)
58
+ else
59
+ puts "#{LOG_PREFIX}#{message}"
60
+ end
61
+ end
62
+
54
63
  # Configuration getter
55
64
  def configuration
56
65
  @configuration ||= Bugsnag::Configuration.new
@@ -0,0 +1,47 @@
1
+ require "httparty"
2
+ require "multi_json"
3
+
4
+ module Bugsnag
5
+ module Capistrano
6
+ ALLOWED_ENV_SETTINGS = %w{BUGSNAG_RELEASE_STAGE BUGSNAG_REPOSITORY BUGSNAG_REVISION BUGSNAG_BRANCH BUGSNAG_API_KEY BUGSNAG_APP_VERSION}
7
+
8
+ def self.load_into(configuration)
9
+ configuration.load do
10
+ after "deploy", "bugsnag:deploy"
11
+ after "deploy:migrations", "bugsnag:deploy"
12
+
13
+ namespace :bugsnag do
14
+ desc "Notify Bugsnag that new production code has been deployed"
15
+ task :deploy, :except => { :no_release => true }, :on_error => :continue do
16
+ # Build the rake command
17
+ rake = fetch(:rake, "rake")
18
+ rails_env = fetch(:rails_env, "production")
19
+ rake_command = "cd '#{current_path}' && #{rake} bugsnag:deploy RAILS_ENV=#{rails_env}"
20
+
21
+ # Build the new environment to pass through to rake
22
+ new_env = {
23
+ "BUGSNAG_RELEASE_STAGE" => rails_env,
24
+ "BUGSNAG_REVISION" => fetch(:current_revision, nil),
25
+ "BUGSNAG_REPOSITORY" => fetch(:repository, nil),
26
+ "BUGSNAG_BRANCH" => fetch(:branch, nil)
27
+ }.reject {|k,v| v.nil? }
28
+
29
+ # Pass through any existing env variables
30
+ ALLOWED_ENV_SETTINGS.each { |opt| new_env[opt] = ENV[opt] if ENV[opt] }
31
+
32
+ # Append the env to the rake command
33
+ rake_command << " #{new_env.map{|k,v| "#{k}=#{v}"}.join(" ")}"
34
+
35
+ # Run the rake command (only on one server)
36
+ run(rake_command, :once => true)
37
+
38
+ logger.info "Bugsnag deploy notification complete."
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ Bugsnag::Capistrano.load_into(Capistrano::Configuration.instance) if Capistrano::Configuration.instance
47
+
@@ -1,6 +1,5 @@
1
1
  module Bugsnag
2
2
  class Configuration
3
- # TODO:JS enforce notify_release_stages
4
3
  OPTIONS = [
5
4
  :api_key, :release_stage, :notify_release_stages, :auto_notify,
6
5
  :use_ssl, :project_root, :app_version,
@@ -39,7 +38,8 @@ module Bugsnag
39
38
  "ActionController::InvalidAuthenticityToken",
40
39
  "CGI::Session::CookieStore::TamperedWithCookie",
41
40
  "ActionController::UnknownAction",
42
- "AbstractController::ActionNotFound"
41
+ "AbstractController::ActionNotFound",
42
+ "Mongoid::Errors::DocumentNotFound"
43
43
  ]
44
44
 
45
45
 
@@ -1,9 +1,11 @@
1
1
  module Bugsnag
2
2
  module Helpers
3
+ MAX_STRING_LENGTH = 1024
4
+
3
5
  def self.cleanup_hash(hash)
4
6
  return nil unless hash
5
7
  hash.inject({}) do |h, (k, v)|
6
- h[k.to_s.gsub(/\./, "-")] = v.to_s
8
+ h[k.to_s.gsub(/\./, "-")] = v.to_s.slice(0, MAX_STRING_LENGTH)
7
9
  h
8
10
  end
9
11
  end
@@ -58,6 +58,11 @@ module Bugsnag
58
58
  def deliver
59
59
  return unless self.notify_release_stages.include?(self.release_stage)
60
60
 
61
+ unless self.api_key
62
+ Bugsnag.warn "No API key configured, couldn't notify"
63
+ return
64
+ end
65
+
61
66
  endpoint = (self.use_ssl ? "https://" : "http://") + (self.endpoint || DEFAULT_ENDPOINT)
62
67
 
63
68
  Bugsnag.log("Notifying #{endpoint} of exception")
@@ -65,7 +70,7 @@ module Bugsnag
65
70
  payload = {
66
71
  :apiKey => self.api_key,
67
72
  :notifier => notifier_identification,
68
- :errors => [{
73
+ :events => [{
69
74
  :userId => self.user_id,
70
75
  :appVersion => self.app_version,
71
76
  :releaseStage => self.release_stage,
@@ -75,7 +80,7 @@ module Bugsnag
75
80
  }.reject {|k,v| v.nil? }]
76
81
  }
77
82
 
78
- self.class.deliver_exception_payload(endpoint, MultiJson.encode(payload))
83
+ self.class.deliver_exception_payload(endpoint, MultiJson.dump(payload))
79
84
  end
80
85
 
81
86
  def ignore?
@@ -2,6 +2,18 @@ module Bugsnag
2
2
  class Rack
3
3
  def initialize(app)
4
4
  @app = app
5
+ if Bugsnag.configuration.project_root.nil? || Bugsnag.configuration.project_root.empty?
6
+ if defined?(settings)
7
+ Bugsnag.configuration.project_root = settings.root
8
+ else
9
+ caller.each do |c|
10
+ if c =~ /[\/\\]config.ru$/
11
+ Bugsnag.configuration.project_root = File.dirname(c.split(":").first)
12
+ break
13
+ end
14
+ end
15
+ end
16
+ end
5
17
  end
6
18
 
7
19
  def call(env)
@@ -6,7 +6,7 @@ require "rails"
6
6
  module Bugsnag
7
7
  class Railtie < Rails::Railtie
8
8
  rake_tasks do
9
- # TODO: Add in rake tasks
9
+ load "tasks/bugsnag.rake"
10
10
  end
11
11
 
12
12
  initializer "bugsnag.use_rack_middleware" do |app|
@@ -15,11 +15,11 @@ module Bugsnag
15
15
 
16
16
  config.after_initialize do
17
17
  Bugsnag.configure do |config|
18
- config.release_stage = Rails.env
19
- config.project_root = Rails.root
18
+ config.release_stage = ::Rails.env
19
+ config.project_root = ::Rails.root
20
20
  config.framework = "Rails: #{::Rails::VERSION::STRING}"
21
21
 
22
- config.logger ||= Rails.logger
22
+ config.logger ||= ::Rails.logger
23
23
  end
24
24
 
25
25
  if defined?(::ActionController::Base)
@@ -0,0 +1,3 @@
1
+ Dir["#{File.dirname(__FILE__)}/../tasks/*.rake"].each do |task|
2
+ load task
3
+ end
@@ -35,8 +35,7 @@ module Resque
35
35
  private
36
36
  def bugsnag_job_data
37
37
  {
38
- :user_id => nil, # TODO: How to infer a user id in resque?
39
- :context => "resque: #{queue}",
38
+ :context => "resque##{queue}",
40
39
  :meta_data => {
41
40
  :payload => payload
42
41
  }
@@ -0,0 +1,52 @@
1
+ require "bugsnag"
2
+ require "httparty"
3
+ require "multi_json"
4
+
5
+ namespace :bugsnag do
6
+ desc "Notify Bugsnag of a new deploy."
7
+ task :deploy => :load do
8
+ # Fetch and check the api key
9
+ api_key = ENV["BUGSNAG_API_KEY"] || Bugsnag.configuration.api_key
10
+ raise RuntimeError.new("No API key found when notifying deploy") if !api_key || api_key.empty?
11
+
12
+ # Build the deploy payload
13
+ payload = {
14
+ :apiKey => api_key,
15
+ :releaseStage => ENV["BUGSNAG_RELEASE_STAGE"] || Bugsnag.configuration.release_stage
16
+ }
17
+ payload[:appVersion] = ENV["BUGSNAG_APP_VERSION"] if ENV["BUGSNAG_APP_VERSION"]
18
+ payload[:revision] = ENV["BUGSNAG_REVISION"] if ENV["BUGSNAG_REVISION"]
19
+ payload[:repository] = ENV["BUGSNAG_REPOSITORY"] if ENV["BUGSNAG_REPOSITORY"]
20
+ payload[:branch] = ENV["BUGSNAG_BRANCH"] if ENV["BUGSNAG_BRANCH"]
21
+
22
+ # Post the deploy notification
23
+ begin
24
+ endpoint = (Bugsnag.configuration.use_ssl ? "https://" : "http://") \
25
+ + (Bugsnag.configuration.endpoint || Bugsnag::Notification::DEFAULT_ENDPOINT) \
26
+ + "/deploy"
27
+
28
+ HTTParty.post(endpoint, {
29
+ :body => MultiJson.dump(payload),
30
+ :headers => {"Content-Type" => "application/json"}
31
+ })
32
+ rescue Exception => e
33
+ Bugsnag.log("Deploy notification failed, #{e.inspect}")
34
+ end
35
+ end
36
+
37
+ desc "Send a test exception to Bugsnag."
38
+ task :test_exception => :load do
39
+ begin
40
+ raise RuntimeError.new("Bugsnag test exception")
41
+ rescue => e
42
+ Bugsnag.notify(e, {:context => "rake#test_exception"})
43
+ end
44
+ end
45
+ end
46
+
47
+ task :load do
48
+ begin
49
+ Rake::Task["environment"].invoke
50
+ rescue
51
+ end
52
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bugsnag
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 0
10
- version: 1.1.0
9
+ - 1
10
+ version: 1.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Smith
@@ -15,11 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-18 00:00:00 Z
18
+ date: 2012-07-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- prerelease: false
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
21
+ requirement: &id001 !ruby/object:Gem::Requirement
23
22
  none: false
24
23
  requirements:
25
24
  - - ">="
@@ -28,12 +27,12 @@ dependencies:
28
27
  segments:
29
28
  - 0
30
29
  version: "0"
31
- requirement: *id001
30
+ prerelease: false
32
31
  type: :runtime
33
32
  name: multi_json
33
+ version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- prerelease: false
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
35
+ requirement: &id002 !ruby/object:Gem::Requirement
37
36
  none: false
38
37
  requirements:
39
38
  - - ">="
@@ -42,12 +41,12 @@ dependencies:
42
41
  segments:
43
42
  - 0
44
43
  version: "0"
45
- requirement: *id002
44
+ prerelease: false
46
45
  type: :runtime
47
46
  name: httparty
47
+ version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- prerelease: false
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
49
+ requirement: &id003 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ">="
@@ -56,12 +55,12 @@ dependencies:
56
55
  segments:
57
56
  - 0
58
57
  version: "0"
59
- requirement: *id003
58
+ prerelease: false
60
59
  type: :development
61
60
  name: shoulda
61
+ version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
63
- prerelease: false
64
- version_requirements: &id004 !ruby/object:Gem::Requirement
63
+ requirement: &id004 !ruby/object:Gem::Requirement
65
64
  none: false
66
65
  requirements:
67
66
  - - ~>
@@ -72,12 +71,12 @@ dependencies:
72
71
  - 0
73
72
  - 0
74
73
  version: 1.0.0
75
- requirement: *id004
74
+ prerelease: false
76
75
  type: :development
77
76
  name: bundler
77
+ version_requirements: *id004
78
78
  - !ruby/object:Gem::Dependency
79
- prerelease: false
80
- version_requirements: &id005 !ruby/object:Gem::Requirement
79
+ requirement: &id005 !ruby/object:Gem::Requirement
81
80
  none: false
82
81
  requirements:
83
82
  - - ~>
@@ -88,12 +87,12 @@ dependencies:
88
87
  - 6
89
88
  - 4
90
89
  version: 1.6.4
91
- requirement: *id005
90
+ prerelease: false
92
91
  type: :development
93
92
  name: jeweler
93
+ version_requirements: *id005
94
94
  - !ruby/object:Gem::Dependency
95
- prerelease: false
96
- version_requirements: &id006 !ruby/object:Gem::Requirement
95
+ requirement: &id006 !ruby/object:Gem::Requirement
97
96
  none: false
98
97
  requirements:
99
98
  - - ">="
@@ -102,9 +101,10 @@ dependencies:
102
101
  segments:
103
102
  - 0
104
103
  version: "0"
105
- requirement: *id006
104
+ prerelease: false
106
105
  type: :development
107
106
  name: rcov
107
+ version_requirements: *id006
108
108
  description: Ruby notifier for bugsnag.com
109
109
  email: james@bugsnag.com
110
110
  executables: []
@@ -124,6 +124,7 @@ files:
124
124
  - VERSION
125
125
  - bugsnag.gemspec
126
126
  - lib/bugsnag.rb
127
+ - lib/bugsnag/capistrano.rb
127
128
  - lib/bugsnag/configuration.rb
128
129
  - lib/bugsnag/delay/resque.rb
129
130
  - lib/bugsnag/helpers.rb
@@ -133,8 +134,10 @@ files:
133
134
  - lib/bugsnag/rails/action_controller_rescue.rb
134
135
  - lib/bugsnag/rails/controller_methods.rb
135
136
  - lib/bugsnag/railtie.rb
137
+ - lib/bugsnag/tasks.rb
136
138
  - lib/bugsnag/version.rb
137
139
  - lib/resque/failure/bugsnag.rb
140
+ - lib/tasks/bugsnag.rake
138
141
  - rails/init.rb
139
142
  - test/helper.rb
140
143
  - test/test_bugsnag.rb
@@ -167,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
170
  requirements: []
168
171
 
169
172
  rubyforge_project:
170
- rubygems_version: 1.8.15
173
+ rubygems_version: 1.8.24
171
174
  signing_key:
172
175
  specification_version: 3
173
176
  summary: Ruby notifier for bugsnag.com