opbeat 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 157acc9610fffbf878154cc1ba1e7312a9b1f77f
4
+ data.tar.gz: 50476185d45bfafca5ce68cb542e1abb0ffbef7b
5
+ SHA512:
6
+ metadata.gz: 5ca3600ea88cae6d689c4a22cd5f25cb56a6a7682d374401b7010066e508201d03eb8d03756af6c2be4023153ccad7e7d50f9ef323ff8647562d8d79b1fdef8c
7
+ data.tar.gz: 6a689d1070878453e1e4132c4a722177663c15f14c100dd3ee9d5c0c4f9ab5fc80d2fbb06f69bcf8a12d69ec7b5d4149ed0ea979e1cac3bbaa6d06f163809532
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ coverage
2
+ pkg
3
+ ruby/
4
+ .bundle
5
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,25 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.1
7
+ gemfile:
8
+ - gemfiles/rails30.gemfile
9
+ - gemfiles/rails31.gemfile
10
+ - gemfiles/rails32.gemfile
11
+ matrix:
12
+ include:
13
+ - rvm: 1.9.2
14
+ gemfile: gemfiles/ruby192_rails31.gemfile
15
+ - rvm: 1.9.2
16
+ gemfile: gemfiles/ruby192_rails32.gemfile
17
+ exclude:
18
+ - rvm: 1.9.2
19
+ gemfile: gemfiles/rails31.gemfile
20
+ - rvm: 1.9.2
21
+ gemfile: gemfiles/rails32.gemfile
22
+ bundler_args: "--without development"
23
+ notifications:
24
+ slack:
25
+ secure: IniiL3PdFsht2zykTwd/z5Et/L1U6GzsmMC1LrgccKCrvLsdcdlBU3VrAgIb1GT9FPEFpb5sl7FEBN80p6uW15uO57onUawFaSWDhSA3eXG1ImmunVPJ20U4NkJvMbnUdZXQ9XXqOw1ggkR7GrD0PM9Nzr4puWaaGq42UJjdaq0=
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org/"
2
+ gemspec
data/Makefile ADDED
@@ -0,0 +1,3 @@
1
+ test:
2
+ bundle install
3
+ rake spec
data/README.md CHANGED
@@ -204,6 +204,19 @@ Opbeat.set_context :extra => {:device_id => my_device_id}
204
204
  Opbeat.capture_message("Hello world") # will include the context
205
205
  ```
206
206
 
207
+ ## Timeouts
208
+
209
+ Opbeat uses a low default timeout. If you frequently experience timeouts, try increasing it in the following manner:
210
+
211
+ ```ruby
212
+ Opbeat.configure do |config|
213
+ ...
214
+ config.timeout = 5
215
+ config.open_timeout = 5
216
+ end
217
+ ```
218
+
219
+
207
220
 
208
221
  ## Testing
209
222
 
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rake'
2
+ require 'rubygems/package_task'
3
+
4
+ gemspec = Gem::Specification.load(Dir['*.gemspec'].first)
5
+
6
+ Gem::PackageTask.new(gemspec).define
7
+
8
+ begin
9
+ require 'rspec/core/rake_task'
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
11
+ spec.pattern = 'spec/**/*_spec.rb'
12
+ end
13
+ rescue LoadError
14
+ task :spec do
15
+ abort "Rspec is not available. bundle install to run unit tests"
16
+ end
17
+ end
18
+
19
+ task :default => :spec
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "~> 3.0.15"
4
+ gem "rake"
5
+ gem "rspec"
6
+ gem "simplecov"
7
+ gem "delayed_job"
8
+ gem "sidekiq", "~> 2.17.0"
9
+ gem "opbeat", :path => "../"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "~> 3.1.6"
4
+ gem "rake"
5
+ gem "rspec"
6
+ gem "simplecov"
7
+ gem "delayed_job"
8
+ gem "sidekiq", "~> 2.17.0"
9
+ gem "opbeat", :path => "../"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "~> 3.2.6"
4
+ gem "rake"
5
+ gem "rspec"
6
+ gem "simplecov"
7
+ gem "delayed_job"
8
+ gem "sidekiq", "~> 2.17.0"
9
+ gem "opbeat", :path => "../"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "~> 4.0.0"
4
+ gem "rake"
5
+ gem "rspec"
6
+ gem "simplecov"
7
+ gem "delayed_job"
8
+ gem "sidekiq", "~> 2.17.0"
9
+
10
+ gem "opbeat", :path => "../"
11
+
12
+ gemspec :path => "../"
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "~> 4.1.0"
4
+ gem "rake"
5
+ gem "rspec"
6
+ gem "simplecov"
7
+ gem "delayed_job"
8
+ gem "sidekiq", "~> 2.17.0"
9
+
10
+ gem "opbeat", :path => "../"
11
+
12
+ gemspec :path => "../"
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "i18n", "~> 0.6.11" # pin to <0.7 to support ruby 1.9.2
4
+ gem "rails", "~> 3.1.6"
5
+ gem "rake"
6
+ gem "rspec"
7
+ gem "simplecov"
8
+ gem "delayed_job"
9
+ gem "sidekiq", "~> 2.17.0"
10
+ gem "opbeat", :path => "../"
11
+
12
+ gemspec :path => "../"
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "i18n", "~> 0.6.11" # pin to <0.7 to support ruby 1.9.2
4
+ gem "rails", "~> 3.2.6"
5
+ gem "rake"
6
+ gem "rspec"
7
+ gem "simplecov"
8
+ gem "delayed_job"
9
+ gem "sidekiq", "~> 2.17.0"
10
+ gem "opbeat", :path => "../"
11
+
12
+ gemspec :path => "../"
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "~> 3.2.6"
4
+ gem "rake"
5
+ gem "rspec"
6
+ gem "simplecov"
7
+ gem "delayed_job"
8
+ gem "sidekiq", "~> 3.1.0"
9
+ gem "opbeat", :path => "../"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,44 @@
1
+ require 'set'
2
+
3
+ module Opbeat
4
+ module BetterAttrAccessor
5
+
6
+ def attributes
7
+ Hash[
8
+ self.class.attributes.map do |attr|
9
+ [attr, send(attr)]
10
+ end
11
+ ]
12
+ end
13
+
14
+ def self.included(base)
15
+ base.extend ClassMethods
16
+ end
17
+
18
+ module ClassMethods
19
+ def attributes
20
+ @attributes ||= Set.new
21
+
22
+ if superclass.include? BetterAttrAccessor
23
+ @attributes + superclass.attributes
24
+ else
25
+ @attributes
26
+ end
27
+ end
28
+
29
+ def attr_accessor(attr, options = {})
30
+ @attributes ||= Set.new
31
+ @attributes << attr.to_s
32
+
33
+ define_method attr do
34
+ if instance_variable_defined? "@#{attr}"
35
+ instance_variable_get "@#{attr}"
36
+ elsif options.key? :default
37
+ instance_variable_set "@#{attr}", options[:default].dup
38
+ end
39
+ end
40
+ attr_writer attr
41
+ end
42
+ end
43
+ end
44
+ end
@@ -8,26 +8,14 @@ namespace :opbeat do
8
8
  info "Skipping Opbeat deployment because scm is not git."
9
9
  next
10
10
  end
11
-
12
- within repo_path do
13
- rev = fetch(:current_revision)
14
11
 
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} "
12
+ rev = fetch(:current_revision)
13
+ branch = fetch(:branch, 'master')
27
14
 
28
- executable = fetch(:rake, 'bundle exec rake ')
29
- notify_command << "#{executable} opbeat:deployment"
30
- capture ("cd #{release_path};" + notify_command), :once => true
15
+ within release_path do
16
+ with rails_env: fetch(:rails_env), rev: rev, branch: branch do
17
+ capture :rake, 'opbeat:deployment'
18
+ end
31
19
  end
32
20
  end
33
21
  end
@@ -35,4 +23,4 @@ end
35
23
 
36
24
  namespace :deploy do
37
25
  after :publishing, "opbeat:notify"
38
- end
26
+ end
data/lib/opbeat/client.rb CHANGED
@@ -17,7 +17,7 @@ module Opbeat
17
17
 
18
18
  def should_try?
19
19
  return true if @status == :online
20
-
20
+
21
21
  interval = ([@retry_number, 6].min() ** 2) * @configuration[:backoff_multiplier]
22
22
  return true if Time.now - @last_check > interval
23
23
 
@@ -40,7 +40,7 @@ module Opbeat
40
40
  class Client
41
41
 
42
42
  PROTOCOL_VERSION = '1.0'
43
- USER_AGENT = "opbeat/#{Opbeat::VERSION}"
43
+ USER_AGENT = "opbeat-ruby/#{Opbeat::VERSION}"
44
44
  AUTH_HEADER_KEY = 'Authorization'
45
45
 
46
46
  attr_accessor :configuration
@@ -79,11 +79,11 @@ module Opbeat
79
79
 
80
80
  def encode(event)
81
81
  event_hash = event.to_hash
82
-
82
+
83
83
  @processors.each do |p|
84
84
  event_hash = p.process(event_hash)
85
85
  end
86
-
86
+
87
87
  return MultiJson.encode(event_hash)
88
88
  end
89
89
 
@@ -95,7 +95,7 @@ module Opbeat
95
95
  req.headers[AUTH_HEADER_KEY] = self.generate_auth_header(req.body)
96
96
  req.headers["User-Agent"] = USER_AGENT
97
97
  end
98
- unless response.status == 202
98
+ if !response.status.between?(200, 299)
99
99
  raise Error.new("Error from Opbeat server (#{response.status}): #{response.body}")
100
100
  end
101
101
  rescue
data/lib/opbeat/event.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'socket'
3
- require 'uuidtools'
4
3
 
5
4
  require 'opbeat/error'
6
5
  require 'opbeat/linecache'
@@ -28,7 +27,7 @@ module Opbeat
28
27
  @configuration = configuration || Opbeat.configuration
29
28
  @interfaces = {}
30
29
 
31
- @id = options[:id] || UUIDTools::UUID.random_create.hexdigest
30
+ @id = options[:id]
32
31
  @message = options[:message]
33
32
  @timestamp = options[:timestamp] || Time.now.utc
34
33
  @level = options[:level] || :error
@@ -72,12 +71,12 @@ module Opbeat
72
71
 
73
72
  def to_hash
74
73
  data = {
75
- 'client_supplied_id' => self.id,
76
74
  'message' => self.message,
77
75
  'timestamp' => self.timestamp,
78
76
  'level' => self.level,
79
77
  'logger' => self.logger,
80
78
  }
79
+ data['client_supplied_id'] = self.id if self.id
81
80
  data['culprit'] = self.culprit if self.culprit
82
81
  data['machine'] = {'hostname' => self.hostname } if self.hostname
83
82
  data['environment'] = self.environment if self.environment
@@ -87,6 +86,7 @@ module Opbeat
87
86
  if self.user[:id] or self.user[:email] or self.user[:username]
88
87
  data['user'][:is_authenticated] = true
89
88
  end
89
+ data['user'][:is_authenticated] = false if !data['user'][:is_authenticated]
90
90
  end
91
91
  @interfaces.each_pair do |name, int_data|
92
92
  data[name] = int_data.to_hash
@@ -5,9 +5,9 @@ module Opbeat
5
5
  class ExceptionInterface < Interface
6
6
 
7
7
  name 'exception'
8
- property :type, :required => true
9
- property :value, :required => true
10
- property :module
8
+ attr_accessor :type
9
+ attr_accessor :value
10
+ attr_accessor :module
11
11
 
12
12
  end
13
13
 
@@ -5,15 +5,15 @@ module Opbeat
5
5
  class HttpInterface < Interface
6
6
 
7
7
  name 'http'
8
- property :url, :required => true
9
- property :method, :required => true
10
- property :data
11
- property :query_string
12
- property :cookies
13
- property :headers
14
- property :remote_host
15
- property :http_host
16
- property :env
8
+ attr_accessor :url
9
+ attr_accessor :method
10
+ attr_accessor :data
11
+ attr_accessor :query_string
12
+ attr_accessor :cookies
13
+ attr_accessor :headers
14
+ attr_accessor :remote_host
15
+ attr_accessor :http_host
16
+ attr_accessor :env
17
17
 
18
18
  def initialize(*arguments)
19
19
  self.headers = {}
@@ -5,8 +5,8 @@ module Opbeat
5
5
  class MessageInterface < Interface
6
6
 
7
7
  name 'param_message'
8
- property :message, :required => true
9
- property :params
8
+ attr_accessor :message
9
+ attr_accessor :params
10
10
 
11
11
  def initialize(*arguments)
12
12
  self.params = []
@@ -1,5 +1,3 @@
1
- require 'hashie'
2
-
3
1
  require 'opbeat/interfaces'
4
2
 
5
3
  module Opbeat
@@ -7,7 +5,7 @@ module Opbeat
7
5
  class StacktraceInterface < Interface
8
6
 
9
7
  name 'stacktrace'
10
- property :frames, :default => []
8
+ attr_accessor :frames, :default => []
11
9
 
12
10
  def initialize(*arguments)
13
11
  self.frames = []
@@ -26,21 +24,14 @@ module Opbeat
26
24
 
27
25
  # Not actually an interface, but I want to use the same style
28
26
  class Frame < Interface
29
- property :abs_path
30
- property :filename, :required => true
31
- property :function
32
- property :vars
33
- property :pre_context
34
- property :post_context
35
- property :context_line
36
- property :lineno, :required => true
37
-
38
- def initialize(*arguments)
39
- self.vars= {}
40
- self.pre_context = []
41
- self.post_context = []
42
- super(*arguments)
43
- end
27
+ attr_accessor :abs_path
28
+ attr_accessor :filename
29
+ attr_accessor :function
30
+ attr_accessor :vars, :default => {}
31
+ attr_accessor :pre_context, :default => []
32
+ attr_accessor :post_context, :default => []
33
+ attr_accessor :context_line
34
+ attr_accessor :lineno
44
35
 
45
36
  def to_hash
46
37
  data = super
@@ -1,25 +1,23 @@
1
- require 'hashie'
1
+ require 'opbeat/better_attr_accessor'
2
2
 
3
3
  module Opbeat
4
4
 
5
5
  INTERFACES = {}
6
6
 
7
- class Interface < Hashie::Dash
8
- def initialize(attributes={}, &block)
9
- @check_required = false
10
- super(attributes)
11
- block.call(self) if block
12
- @check_required = true
13
- assert_required_properties_set!
14
- end
7
+ class Interface
8
+ include BetterAttrAccessor
9
+ alias_method :to_hash, :attributes
10
+
11
+ def initialize(attributes = nil)
12
+ attributes.each do |attr, value|
13
+ send "#{attr}=", value
14
+ end if attributes
15
15
 
16
- def assert_required_properties_set!
17
- super if @check_required
16
+ yield self if block_given?
18
17
  end
19
18
 
20
- def self.name(value=nil)
21
- @interface_name = value if value
22
- @interface_name
19
+ def self.name(value = nil)
20
+ @interface_name ||= value
23
21
  end
24
22
  end
25
23
 
@@ -1,3 +1,3 @@
1
1
  module Opbeat
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
data/opbeat.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'opbeat/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "opbeat"
8
+ gem.version = Opbeat::VERSION
9
+ gem.authors = ["Thomas Watson Steen", "Ron Cohen", "Noah Kantrowitz"]
10
+ gem.email = "support@opbeat.com"
11
+ gem.summary = "The official Opbeat Ruby client"
12
+ gem.homepage = "https://github.com/opbeat/opbeat_ruby"
13
+ gem.license = "Apache-2.0"
14
+
15
+ gem.files = `git ls-files -z`.split("\x0")
16
+ gem.require_paths = ["lib"]
17
+ gem.extra_rdoc_files = ["README.md", "LICENSE"]
18
+
19
+ gem.add_dependency "faraday", [">= 0.7.6", "< 0.10"]
20
+ gem.add_dependency "multi_json", "~> 1.0"
21
+
22
+ gem.add_development_dependency "bundler", "~> 1.7"
23
+ gem.add_development_dependency "rake", "~> 10.0"
24
+ gem.add_development_dependency "rspec", ">= 2.14"
25
+ gem.add_development_dependency "simplecov"
26
+ gem.add_development_dependency "delayed_job"
27
+ gem.add_development_dependency "sidekiq", "~> 2.17.0"
28
+ end
@@ -0,0 +1,99 @@
1
+ require File::expand_path('../../spec_helper', __FILE__)
2
+ require 'opbeat'
3
+
4
+ describe Opbeat::BetterAttrAccessor do
5
+
6
+ let :klass do
7
+ Class.new do
8
+ include Opbeat::BetterAttrAccessor
9
+
10
+ attr_accessor :a
11
+ attr_accessor :b, :default => []
12
+ attr_accessor :c
13
+ end
14
+ end
15
+
16
+ let :child do
17
+ Class.new klass do
18
+ attr_accessor :d
19
+ end
20
+ end
21
+
22
+ subject{ klass.new }
23
+
24
+ describe 'the reader method' do
25
+ context 'when a value is not set' do
26
+ it 'should default to nil' do
27
+ expect(subject.a).to eq nil
28
+ end
29
+ it 'should use a default value if provided' do
30
+ expect(subject.b).to eq []
31
+ expect(subject.instance_variable_get '@b').to eq []
32
+ end
33
+ end
34
+
35
+ context 'when a value is set' do
36
+ before do
37
+ subject.a = 'foo'
38
+ subject.b = :bar
39
+ subject.c = false
40
+ end
41
+
42
+ it 'should save the value' do
43
+ expect(subject.a).to eq 'foo'
44
+ end
45
+ it 'should save a boolean `false` value' do
46
+ expect(subject.c).to eq false
47
+ end
48
+ it 'should no longer return the default' do
49
+ expect(subject.b).to eq :bar
50
+ end
51
+ end
52
+
53
+ context 'when a default value is directly modified' do
54
+ before { subject.b << 9 }
55
+ it 'should not affect a new instance' do
56
+ expect(klass.new.b).to eq []
57
+ end
58
+ end
59
+ end
60
+
61
+ describe '.attributes' do
62
+ it 'should be a Set of all attributes set up' do
63
+ expect(klass.attributes).to be_a Set
64
+ expect(klass.attributes).to eq %w[a b c].to_set
65
+ end
66
+ it 'should work with inheritance' do
67
+ expect(child.attributes).to eq %w[d a b c].to_set
68
+ end
69
+ end
70
+
71
+ describe '#attributes' do
72
+ it 'should return a hash of all attributes' do
73
+ subject.a = {'foo' => :bar}
74
+ subject.b << 8
75
+ expect(subject.attributes).to eq \
76
+ 'a' => {'foo' => :bar},
77
+ 'b' => [8],
78
+ 'c' => nil
79
+ end
80
+
81
+ describe 'inheritance' do
82
+ subject{ child.new }
83
+
84
+ before do
85
+ subject.a = 21
86
+ subject.d = true
87
+ end
88
+
89
+ it 'should work' do
90
+ expect(subject.attributes).to eq \
91
+ 'a' => 21,
92
+ 'b' => [],
93
+ 'c' => nil,
94
+ 'd' => true
95
+ end
96
+ end
97
+ end
98
+
99
+ end
@@ -0,0 +1,25 @@
1
+ require File::expand_path('../../spec_helper', __FILE__)
2
+ require 'opbeat'
3
+
4
+ describe Opbeat::Client do
5
+ before do
6
+
7
+ @configuration = Opbeat::Configuration.new
8
+ @configuration.environments = ["test"]
9
+ @configuration.current_environment = :test
10
+ @client = Opbeat::Client.new(@configuration)
11
+ allow(@client).to receive(:send)
12
+ end
13
+
14
+ it 'send_release should send' do
15
+ message = "Test message"
16
+ expect(@client).to receive(:send).with("/releases/", message)
17
+ @client.send_release(message)
18
+ end
19
+
20
+ it 'send_message should send' do
21
+ event = Opbeat::Event.new :message => "my message"
22
+ expect(@client).to receive(:send).with("/errors/", event)
23
+ @client.send_event(event)
24
+ end
25
+ end