sentry-raven 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sentry-raven might be problematic. Click here for more details.

data/README.md CHANGED
@@ -11,7 +11,12 @@ This library is still forming, so if you are looking to just use it, please chec
11
11
  Add the following to your `Gemfile`:
12
12
 
13
13
  ```ruby
14
- gem "raven", :git => "https://github.com/coderanger/raven-ruby.git"
14
+ gem "sentry-raven", :git => "https://github.com/coderanger/raven-ruby.git"
15
+ ```
16
+
17
+ Or install manually
18
+ ```bash
19
+ $ gem install sentry-raven
15
20
  ```
16
21
 
17
22
  ## Usage
@@ -53,12 +58,15 @@ require 'raven'
53
58
 
54
59
  Raven.configure do |config|
55
60
  config.dsn = 'http://public:secret@example.com/project-id'
61
+
62
+ # manually configure environment if ENV['RACK_ENV'] is not defined
63
+ config.current_environment = 'production'
56
64
  end
57
65
 
58
66
  Raven.capture # Global style
59
67
 
60
68
  Raven.capture do # Block style
61
- ...
69
+ 1 / 0
62
70
  end
63
71
  ```
64
72
 
@@ -68,3 +76,18 @@ end
68
76
  $ bundle install
69
77
  $ rake spec
70
78
  ```
79
+
80
+ ## Notifications in development mode
81
+
82
+ By default events will only be sent to Sentry if your application is running in a production environment. This is configured by default if you are running a Rack application (i.e. anytime `ENV['RACK_ENV']` is set).
83
+
84
+ You can configure Raven to run in non-production environments by configuring the `environments` whitelist:
85
+
86
+ ```ruby
87
+ require 'raven'
88
+
89
+ Raven.configure do |config|
90
+ config.dsn = 'http://public:secret@example.com/project-id'
91
+ config.environments = %w[ development production ]
92
+ end
93
+ ```
@@ -52,6 +52,8 @@ module Raven
52
52
  end
53
53
 
54
54
  def send(event)
55
+ return unless configuration.send_in_current_environment?
56
+
55
57
  # Set the project ID correctly
56
58
  event.project = self.configuration[:project_id]
57
59
  Raven.logger.debug "Sending event #{event.id} to Sentry"
@@ -19,9 +19,20 @@ module Raven
19
19
  # Number of lines of code context to capture, or nil for none
20
20
  attr_accessor :context_lines
21
21
 
22
+ # Whitelist of environments that will send notifications to Sentry
23
+ attr_accessor :environments
24
+
25
+ # Include module versions in reports?
26
+ attr_accessor :send_modules
27
+
28
+ attr_reader :current_environment
29
+
22
30
  def initialize
23
31
  self.server = ENV['SENTRY_DSN'] if ENV['SENTRY_DSN']
24
32
  @context_lines = 3
33
+ self.environments = %w[ production ]
34
+ self.current_environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
35
+ self.send_modules = true
25
36
  end
26
37
 
27
38
  def server=(value)
@@ -49,5 +60,13 @@ module Raven
49
60
  send(option)
50
61
  end
51
62
 
63
+ def current_environment=(environment)
64
+ @current_environment = environment.to_s
65
+ end
66
+
67
+ def send_in_current_environment?
68
+ environments.include? current_environment
69
+ end
70
+
52
71
  end
53
72
  end
@@ -17,25 +17,32 @@ module Raven
17
17
  "error" => 40,
18
18
  }
19
19
 
20
- BACKTRACE_RE = /^(.+?):(\d+)(?::in `(.+?)')$/
20
+ BACKTRACE_RE = /^(.+?):(\d+)(?::in `(.+?)')?$/
21
21
 
22
22
  attr_reader :id
23
23
  attr_accessor :project, :message, :timestamp, :level
24
24
  attr_accessor :logger, :culprit, :server_name, :modules, :extra
25
25
 
26
- def initialize(options={}, &block)
27
- @id = options[:id] || UUIDTools::UUID.random_create.hexdigest
26
+ def initialize(options={}, configuration=nil, &block)
27
+ configuration ||= Raven.configuration
28
28
 
29
+ @id = options[:id] || UUIDTools::UUID.random_create.hexdigest
29
30
  @message = options[:message]
30
-
31
31
  @timestamp = options[:timestamp] || Time.now.utc
32
-
33
32
  @level = options[:level] || :error
34
-
35
33
  @logger = options[:logger] || 'root'
36
34
  @culprit = options[:culprit]
37
- @server_name = options[:server_name] || Socket.gethostbyname(Socket.gethostname).first
38
- @modules = options[:modules] || Gem::Specification.each.inject({}){|memo, spec| memo[spec.name] = spec.version; memo}
35
+
36
+ # Try to resolve the hostname to an FQDN, but fall back to whatever the load name is
37
+ hostname = Socket.gethostname
38
+ hostname = Socket.gethostbyname(hostname).first rescue hostname
39
+ @server_name = options[:server_name] || hostname
40
+
41
+ if configuration.send_modules && !options.has_key?(:modules)
42
+ options[:modules] = Hash[Gem::Specification.map {|spec| [spec.name, spec.version]}]
43
+ end
44
+ @modules = options[:modules]
45
+
39
46
  @extra = options[:extra]
40
47
 
41
48
  @interfaces = {}
@@ -92,7 +99,7 @@ module Raven
92
99
  Raven.logger.info "Refusing to capture Raven error: #{exc.inspect}"
93
100
  return nil
94
101
  end
95
- self.new do |evt|
102
+ self.new({}, configuration) do |evt|
96
103
  evt.message = exc.message
97
104
  evt.level = :error
98
105
  evt.interface :exception do |int|
@@ -3,13 +3,13 @@ module Raven
3
3
  module Middleware
4
4
  module DebugExceptionsCatcher
5
5
  def self.included(base)
6
- base.send(:alias_method_chain, :render_exception, :airbrake)
6
+ base.send(:alias_method_chain, :render_exception, :raven)
7
7
  end
8
8
 
9
- def render_exception_with_airbrake(env, exception)
9
+ def render_exception_with_raven(env, exception)
10
10
  evt = Raven::Event.capture_rack_exception(exception, env)
11
11
  Raven.send(evt) if evt
12
- render_exception_without_airbrake(env, exception)
12
+ render_exception_without_raven(env, exception)
13
13
  end
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module Raven
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sentry-raven
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: "0.1"
5
+ version: "0.2"
6
6
  platform: ruby
7
7
  authors:
8
8
  - Noah Kantrowitz
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-03 00:00:00 Z
13
+ date: 2012-07-14 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  requirements: []
108
108
 
109
109
  rubyforge_project:
110
- rubygems_version: 1.8.10
110
+ rubygems_version: 1.8.24
111
111
  signing_key:
112
112
  specification_version: 3
113
113
  summary: A gem that provides a client interface for the Sentry error logger