opbeat 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +4 -3
- data/lib/opbeat.rb +4 -1
- data/lib/opbeat/capistrano.rb +9 -0
- data/lib/opbeat/capistrano/capistrano2.rb +45 -0
- data/lib/opbeat/capistrano/capistrano3.rb +38 -0
- data/lib/opbeat/client.rb +26 -13
- data/lib/opbeat/configuration.rb +2 -2
- data/lib/opbeat/event.rb +3 -0
- data/lib/opbeat/integrations/delayed_job.rb +32 -0
- data/lib/opbeat/railtie.rb +3 -0
- data/lib/opbeat/tasks.rb +24 -0
- data/lib/opbeat/version.rb +1 -1
- metadata +31 -36
- checksums.yaml +0 -7
data/README.md
CHANGED
@@ -45,13 +45,14 @@ Basic RackUp file.
|
|
45
45
|
```ruby
|
46
46
|
require 'opbeat'
|
47
47
|
|
48
|
+
use Opbeat::Rack
|
49
|
+
|
48
50
|
Opbeat.configure do |config|
|
49
51
|
config.organization_id = '094e250818f44e82bfae13919f55fb35'
|
50
52
|
config.app_id = '094e250818'
|
51
53
|
config.secret_token = 'f0f5237a221637f561a15614f5fef218f8d6317d'
|
52
54
|
end
|
53
55
|
|
54
|
-
use Opbeat::Rack
|
55
56
|
```
|
56
57
|
|
57
58
|
### Sinatra
|
@@ -60,14 +61,14 @@ use Opbeat::Rack
|
|
60
61
|
require 'sinatra'
|
61
62
|
require 'opbeat'
|
62
63
|
|
64
|
+
use Opbeat::Rack
|
65
|
+
|
63
66
|
Opbeat.configure do |config|
|
64
67
|
config.organization_id = '094e250818f44e82bfae13919f55fb35'
|
65
68
|
config.app_id = '094e250818'
|
66
69
|
config.secret_token = 'f0f5237a221637f561a15614f5fef218f8d6317d'
|
67
70
|
end
|
68
71
|
|
69
|
-
use Opbeat::Rack
|
70
|
-
|
71
72
|
get '/' do
|
72
73
|
1 / 0
|
73
74
|
end
|
data/lib/opbeat.rb
CHANGED
@@ -10,8 +10,11 @@ require 'opbeat/interfaces/stack_trace'
|
|
10
10
|
require 'opbeat/interfaces/http'
|
11
11
|
require 'opbeat/processors/sanitizedata'
|
12
12
|
|
13
|
+
require 'opbeat/integrations/delayed_job'
|
14
|
+
|
13
15
|
require 'opbeat/railtie' if defined?(Rails::Railtie)
|
14
16
|
|
17
|
+
|
15
18
|
module Opbeat
|
16
19
|
class << self
|
17
20
|
# The client object is responsible for delivering formatted data to the Opbeat server.
|
@@ -56,7 +59,7 @@ module Opbeat
|
|
56
59
|
# evt = Opbeat::Event.new(:message => "An error")
|
57
60
|
# Opbeat.send(evt)
|
58
61
|
def send(evt)
|
59
|
-
@client.
|
62
|
+
@client.send_event(evt) if @client
|
60
63
|
end
|
61
64
|
|
62
65
|
# Capture and process any exceptions from the given block, or globally if
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
|
3
|
+
module Opbeat
|
4
|
+
module Capistrano
|
5
|
+
def self.load_into(configuration)
|
6
|
+
|
7
|
+
configuration.load do
|
8
|
+
after "deploy", "opbeat:notify"
|
9
|
+
namespace :opbeat do
|
10
|
+
desc "Notifies Opbeat of new deployments"
|
11
|
+
task :notify, :except => { :no_release => true } do
|
12
|
+
|
13
|
+
scm = fetch(:scm)
|
14
|
+
if scm.to_s != "git"
|
15
|
+
puts "Skipping Opbeat deployment notification because scm is not git."
|
16
|
+
next
|
17
|
+
end
|
18
|
+
|
19
|
+
branches = capture("cd #{current_release}; /usr/bin/env git branch --contains #{current_revision}").split
|
20
|
+
if branches.length == 1
|
21
|
+
branch = branch[0].sub("* ")
|
22
|
+
else
|
23
|
+
branch = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
notify_command = "cd #{current_release}; REV=#{current_revision} "
|
27
|
+
notify_command << "BRANCH=#{branch} " if branch
|
28
|
+
|
29
|
+
rails_env = fetch(:rails_env, "production")
|
30
|
+
notify_command << "RAILS_ENV=#{rails_env} "
|
31
|
+
|
32
|
+
executable = fetch(:rake, 'bundle exec rake ')
|
33
|
+
notify_command << "#{executable} opbeat:deployment"
|
34
|
+
capture notify_command, :once => true
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if Capistrano::Configuration.instance
|
44
|
+
Opbeat::Capistrano.load_into(Capistrano::Configuration.instance)
|
45
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
namespace :opbeat do
|
2
|
+
desc "Notifies Opbeat of new deployments"
|
3
|
+
task :notify do
|
4
|
+
on roles(:app) do
|
5
|
+
|
6
|
+
scm = fetch(:scm)
|
7
|
+
if scm.to_s != "git"
|
8
|
+
info "Skipping Opbeat deployment because scm is not git."
|
9
|
+
next
|
10
|
+
end
|
11
|
+
|
12
|
+
within repo_path do
|
13
|
+
rev = fetch(:current_revision)
|
14
|
+
|
15
|
+
branches = capture("cd #{repo_path}; /usr/bin/env git branch --contains #{rev}").split
|
16
|
+
if branches.length == 1
|
17
|
+
branch = branches[0].sub("* ", "")
|
18
|
+
else
|
19
|
+
branch = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
notify_command = "REV=#{rev} "
|
23
|
+
notify_command << "BRANCH=#{branch} " if branch
|
24
|
+
|
25
|
+
rails_env = fetch(:rails_env, "production")
|
26
|
+
notify_command << "RAILS_ENV=#{rails_env} "
|
27
|
+
|
28
|
+
executable = fetch(:rake, 'bundle exec rake ')
|
29
|
+
notify_command << "#{executable} opbeat:deployment"
|
30
|
+
capture ("cd #{release_path};" + notify_command), :once => true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
namespace :deploy do
|
37
|
+
after :publishing, "opbeat:notify"
|
38
|
+
end
|
data/lib/opbeat/client.rb
CHANGED
@@ -60,8 +60,11 @@ module Opbeat
|
|
60
60
|
raise Error.new('No app ID specified') unless self.configuration[:app_id]
|
61
61
|
|
62
62
|
Opbeat.logger.debug "Opbeat client connecting to #{self.configuration[:server]}"
|
63
|
-
@
|
64
|
-
|
63
|
+
@base_url = self.configuration[:server] +
|
64
|
+
"/api/v1/organizations/" +
|
65
|
+
self.configuration[:organization_id] +
|
66
|
+
"/apps/" + self.configuration[:app_id]
|
67
|
+
@conn ||= Faraday.new(:url => @base_url, :ssl => {:verify => self.configuration.ssl_verification}) do |builder|
|
65
68
|
builder.adapter Faraday.default_adapter
|
66
69
|
end
|
67
70
|
|
@@ -84,19 +87,11 @@ module Opbeat
|
|
84
87
|
return MultiJson.encode(event_hash)
|
85
88
|
end
|
86
89
|
|
87
|
-
def send(
|
88
|
-
return unless configuration.send_in_current_environment?
|
89
|
-
return unless state.should_try?
|
90
|
-
|
91
|
-
# Set the organization ID correctly
|
92
|
-
event.organization = self.configuration[:organization_id]
|
93
|
-
event.app = self.configuration[:app_id]
|
94
|
-
Opbeat.logger.debug "Sending event #{event.id} to Opbeat"
|
95
|
-
|
90
|
+
def send(url_postfix, message)
|
96
91
|
begin
|
97
|
-
response = self.conn.post @
|
92
|
+
response = self.conn.post @base_url + url_postfix do |req|
|
98
93
|
req.headers['Content-Type'] = 'application/json'
|
99
|
-
req.body = self.encode(
|
94
|
+
req.body = self.encode(message)
|
100
95
|
req.headers[AUTH_HEADER_KEY] = self.generate_auth_header(req.body)
|
101
96
|
req.headers["User-Agent"] = USER_AGENT
|
102
97
|
end
|
@@ -113,6 +108,24 @@ module Opbeat
|
|
113
108
|
response
|
114
109
|
end
|
115
110
|
|
111
|
+
def send_event(event)
|
112
|
+
return unless configuration.send_in_current_environment?
|
113
|
+
unless state.should_try?
|
114
|
+
Opbeat.logger.info "Temporarily skipping sending to Opbeat due to previous failure."
|
115
|
+
return
|
116
|
+
end
|
117
|
+
|
118
|
+
# Set the organization ID correctly
|
119
|
+
event.organization = self.configuration[:organization_id]
|
120
|
+
event.app = self.configuration[:app_id]
|
121
|
+
Opbeat.logger.debug "Sending event #{event.id} to Opbeat"
|
122
|
+
send("/errors/", event)
|
123
|
+
end
|
124
|
+
|
125
|
+
def send_release(release)
|
126
|
+
Opbeat.logger.debug "Sending release to Opbeat"
|
127
|
+
send("/releases/", release)
|
128
|
+
end
|
116
129
|
end
|
117
130
|
|
118
131
|
end
|
data/lib/opbeat/configuration.rb
CHANGED
@@ -48,8 +48,8 @@ module Opbeat
|
|
48
48
|
self.organization_id = ENV['OPBEAT_ORGANIZATION_ID'] if ENV['OPBEAT_ORGANIZATION_ID']
|
49
49
|
self.app_id = ENV['OPBEAT_APP_ID'] if ENV['OPBEAT_APP_ID']
|
50
50
|
@context_lines = 3
|
51
|
-
self.environments = %w[ production ]
|
52
|
-
self.current_environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || '
|
51
|
+
self.environments = %w[ development production default ]
|
52
|
+
self.current_environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
|
53
53
|
self.excluded_exceptions = []
|
54
54
|
self.processors = [Opbeat::Processor::SanitizeData]
|
55
55
|
self.timeout = 1
|
data/lib/opbeat/event.rb
CHANGED
@@ -22,6 +22,7 @@ module Opbeat
|
|
22
22
|
attr_reader :id
|
23
23
|
attr_accessor :organization, :app, :message, :timestamp, :level
|
24
24
|
attr_accessor :logger, :culprit, :hostname, :modules, :extra
|
25
|
+
attr_accessor :environment
|
25
26
|
|
26
27
|
def initialize(options={}, configuration=nil, &block)
|
27
28
|
@configuration = configuration || Opbeat.configuration
|
@@ -33,6 +34,7 @@ module Opbeat
|
|
33
34
|
@level = options[:level] || :error
|
34
35
|
@logger = options[:logger] || 'root'
|
35
36
|
@culprit = options[:culprit]
|
37
|
+
@environment = @configuration[:current_environment]
|
36
38
|
@extra = options[:extra]
|
37
39
|
|
38
40
|
# Try to resolve the hostname to an FQDN, but fall back to whatever the load name is
|
@@ -77,6 +79,7 @@ module Opbeat
|
|
77
79
|
}
|
78
80
|
data['culprit'] = self.culprit if self.culprit
|
79
81
|
data['machine'] = {'hostname' => self.hostname } if self.hostname
|
82
|
+
data['environment'] = self.environment if self.environment
|
80
83
|
data['extra'] = self.extra if self.extra
|
81
84
|
@interfaces.each_pair do |name, int_data|
|
82
85
|
data[name] = int_data.to_hash
|
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'delayed_job'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
# Based on the Sentry equivalent.
|
7
|
+
if defined?(Delayed)
|
8
|
+
|
9
|
+
module Delayed
|
10
|
+
module Plugins
|
11
|
+
class Opbeat < ::Delayed::Plugin
|
12
|
+
callbacks do |lifecycle|
|
13
|
+
lifecycle.around(:invoke_job) do |job, *args, &block|
|
14
|
+
begin
|
15
|
+
# Forward the call to the next callback in the callback chain
|
16
|
+
block.call(job, *args)
|
17
|
+
|
18
|
+
rescue Exception => exception
|
19
|
+
# Log error to Opbeat
|
20
|
+
::Opbeat.captureException(exception)
|
21
|
+
# Make sure we propagate the failure!
|
22
|
+
raise exception
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Register DelayedJob Opbeat plugin
|
31
|
+
Delayed::Worker.plugins << Delayed::Plugins::Opbeat
|
32
|
+
end
|
data/lib/opbeat/railtie.rb
CHANGED
data/lib/opbeat/tasks.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Capistrano tasks for notifying Opbeat of deploys
|
2
|
+
namespace :opbeat do
|
3
|
+
desc "Notify Opbeat of a new deploy."
|
4
|
+
task :deployment do
|
5
|
+
if defined?(Rails.root)
|
6
|
+
initializer_file = Rails.root.join('config', 'initializers','opbeat.rb')
|
7
|
+
|
8
|
+
if initializer_file.exist?
|
9
|
+
load initializer_file
|
10
|
+
else
|
11
|
+
Rake::Task[:environment].invoke
|
12
|
+
end
|
13
|
+
end
|
14
|
+
rev = ENV['REV']
|
15
|
+
|
16
|
+
unless rev
|
17
|
+
puts "No revision given. Set environment variable REV."
|
18
|
+
else
|
19
|
+
data = {'rev' => ENV['REV'], 'branch' => ENV['BRANCH'], 'status' => 'completed'}
|
20
|
+
Opbeat::client.send_release(data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/lib/opbeat/version.rb
CHANGED
metadata
CHANGED
@@ -1,72 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opbeat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Noah Kantrowitz
|
8
|
-
-
|
9
|
+
- Opbeat
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-
|
13
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: faraday
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirement: &11261960 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
20
|
- - ~>
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: 0.8.0.rc2
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
|
-
version_requirements:
|
24
|
-
requirements:
|
25
|
-
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: 0.8.0.rc2
|
25
|
+
version_requirements: *11261960
|
28
26
|
- !ruby/object:Gem::Dependency
|
29
27
|
name: uuidtools
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
28
|
+
requirement: &11261420 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
31
30
|
requirements:
|
32
|
-
- -
|
31
|
+
- - ~>
|
33
32
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
33
|
+
version: 2.1.4
|
35
34
|
type: :runtime
|
36
35
|
prerelease: false
|
37
|
-
version_requirements:
|
38
|
-
requirements:
|
39
|
-
- - '>='
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
36
|
+
version_requirements: *11261420
|
42
37
|
- !ruby/object:Gem::Dependency
|
43
38
|
name: multi_json
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirement: &11256860 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
45
41
|
requirements:
|
46
42
|
- - ~>
|
47
43
|
- !ruby/object:Gem::Version
|
48
44
|
version: '1.0'
|
49
45
|
type: :runtime
|
50
46
|
prerelease: false
|
51
|
-
version_requirements:
|
52
|
-
requirements:
|
53
|
-
- - ~>
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '1.0'
|
47
|
+
version_requirements: *11256860
|
56
48
|
- !ruby/object:Gem::Dependency
|
57
49
|
name: hashie
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirement: &11255580 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
59
52
|
requirements:
|
60
|
-
- -
|
53
|
+
- - ~>
|
61
54
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
55
|
+
version: 2.1.1
|
63
56
|
type: :runtime
|
64
57
|
prerelease: false
|
65
|
-
version_requirements:
|
66
|
-
requirements:
|
67
|
-
- - '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
58
|
+
version_requirements: *11255580
|
70
59
|
description:
|
71
60
|
email: ron@opbeat.com
|
72
61
|
executables: []
|
@@ -75,10 +64,14 @@ extra_rdoc_files:
|
|
75
64
|
- README.md
|
76
65
|
- LICENSE
|
77
66
|
files:
|
67
|
+
- lib/opbeat/capistrano/capistrano2.rb
|
68
|
+
- lib/opbeat/capistrano/capistrano3.rb
|
69
|
+
- lib/opbeat/capistrano.rb
|
78
70
|
- lib/opbeat/client.rb
|
79
71
|
- lib/opbeat/configuration.rb
|
80
72
|
- lib/opbeat/error.rb
|
81
73
|
- lib/opbeat/event.rb
|
74
|
+
- lib/opbeat/integrations/delayed_job.rb
|
82
75
|
- lib/opbeat/interfaces/exception.rb
|
83
76
|
- lib/opbeat/interfaces/http.rb
|
84
77
|
- lib/opbeat/interfaces/message.rb
|
@@ -91,31 +84,33 @@ files:
|
|
91
84
|
- lib/opbeat/rack.rb
|
92
85
|
- lib/opbeat/rails/middleware/debug_exceptions_catcher.rb
|
93
86
|
- lib/opbeat/railtie.rb
|
87
|
+
- lib/opbeat/tasks.rb
|
94
88
|
- lib/opbeat/version.rb
|
95
89
|
- lib/opbeat.rb
|
96
90
|
- README.md
|
97
91
|
- LICENSE
|
98
92
|
homepage: http://github.com/opbeat/opbeat_ruby
|
99
93
|
licenses: []
|
100
|
-
metadata: {}
|
101
94
|
post_install_message:
|
102
95
|
rdoc_options: []
|
103
96
|
require_paths:
|
104
97
|
- lib
|
105
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
106
100
|
requirements:
|
107
|
-
- - '>='
|
101
|
+
- - ! '>='
|
108
102
|
- !ruby/object:Gem::Version
|
109
103
|
version: '0'
|
110
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
111
106
|
requirements:
|
112
|
-
- - '>='
|
107
|
+
- - ! '>='
|
113
108
|
- !ruby/object:Gem::Version
|
114
109
|
version: '0'
|
115
110
|
requirements: []
|
116
111
|
rubyforge_project:
|
117
|
-
rubygems_version:
|
112
|
+
rubygems_version: 1.8.11
|
118
113
|
signing_key:
|
119
|
-
specification_version:
|
114
|
+
specification_version: 3
|
120
115
|
summary: A gem that provides a client interface for the Opbeat error logger
|
121
116
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: dfe15681e252c3094e3511bf20dbafe757f9e342
|
4
|
-
data.tar.gz: b8c85cf5621ca9e675f56480416d661773569adc
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 219eddda6bdccc4a1e4eb52c292c527c650c7fdab9f53db68388a24a8f64aee5dbae331fa9ab15f67a97b6cdba4c89f669ab42eea1c56788afd5c9b4f1bb88df
|
7
|
-
data.tar.gz: b788d34646fb4cbb258a9fbd4cff8bb23723e9803553e6af51112adf3a3888f7975c2d072268a587c5daa6e621f7bb130113d09c185de148872a7fd5f2c034ce
|