sentry-raven 0.4.6 → 0.4.7

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
@@ -16,7 +16,11 @@ gem "sentry-raven" #, :github => "getsentry/raven-ruby"
16
16
 
17
17
  ## Usage
18
18
 
19
- You'll want to set your ```SENTRY_DSN``` environment variable to the URL on your project's API Keys setting page (e.g. ```https://secret:public@app.getsentry.com/9999```). For more information, see [Configuration](#configuration).
19
+ The easiest way to configure Raven is by setting the ``SENTRY_DSN`` environment variable.
20
+
21
+ You'll find this value on your project settings page, and it should resemble something like ```https://secret:public@app.getsentry.com/9999```.
22
+
23
+ For alternative configuration methods, and other options see [Configuration](#configuration).
20
24
 
21
25
  ### Rails 3
22
26
 
@@ -93,13 +97,6 @@ The following attributes are available:
93
97
  * `tags`: a mapping of [tags](https://www.getsentry.com/docs/tags/) describing this event
94
98
  * `extra`: a mapping of arbitrary context
95
99
 
96
- ## Testing
97
-
98
- ```bash
99
- $ bundle install
100
- $ rake spec
101
- ```
102
-
103
100
  ## Configuration
104
101
 
105
102
  ### SENTRY_DSN
@@ -160,12 +157,44 @@ Raven.configure do |config|
160
157
  end
161
158
  ```
162
159
 
163
- ## Command Line Interface
160
+ ## Testing Your Configuration
164
161
 
165
- Raven includes a basic CLI for testing your DSN:
162
+ To ensure you've setup your configuration correctly we recommend running the
163
+ included rake task::
166
164
 
167
- ```ruby
168
- ruby -Ilib ./bin/raven test <DSN>
165
+ ```bash
166
+ $ rake raven:test[https://public:secret@app.getsentry.com/3825]
167
+ Client configuration:
168
+ -> server: https://app.getsentry.com
169
+ -> project_id: 3825
170
+ -> public_key: public
171
+ -> secret_key: secret
172
+
173
+ Sending a test event:
174
+ -> event ID: 033c343c852b45c2a3add98e425ea4b4
175
+
176
+ Done!
177
+ ```
178
+
179
+ A couple of things to note:
180
+
181
+ * This won't test your environment configuration. The test CLI forces the your
182
+ coniguration to represent itself as if it were running in the production env.
183
+ * If you're running within Rails (or anywhere else that will bootstrap the
184
+ rake environment), you should be able to omit the DSN argument.
185
+
186
+ ## Contributing
187
+
188
+ ### Bootstrap
189
+
190
+ ```bash
191
+ $ bundle install
192
+ ```
193
+
194
+ ### Running the test suite
195
+
196
+ ```bash
197
+ $ rake spec
169
198
  ```
170
199
 
171
200
  Resources
data/bin/raven CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "raven"
4
+ require "raven/cli"
4
5
  require "optparse"
5
6
 
6
7
  options = {}
@@ -34,21 +35,7 @@ case ARGV[0]
34
35
  if !dsn
35
36
  puts "Usage: raven test <dsn>"
36
37
  else
37
- Raven.configure do |config|
38
- config.dsn = dsn
39
- config.current_environment = 'production'
40
- end
41
-
42
- puts "Sending test event"
43
-
44
- begin
45
- 1 / 0
46
- rescue ZeroDivisionError => exception
47
- Raven.capture_exception(exception)
48
- end
49
-
50
- puts "Done!"
51
-
38
+ Raven::CLI::test(dsn)
52
39
  end
53
40
  else
54
41
  puts parser
@@ -11,6 +11,7 @@ require 'raven/interfaces/exception'
11
11
  require 'raven/interfaces/stack_trace'
12
12
  require 'raven/interfaces/http'
13
13
  require 'raven/processors/sanitizedata'
14
+ require 'raven/tasks'
14
15
 
15
16
  require 'raven/railtie' if defined?(Rails::Railtie)
16
17
  require 'raven/sidekiq' if defined?(Sidekiq)
@@ -104,14 +105,14 @@ module Raven
104
105
  end
105
106
 
106
107
  def capture_exception(exception, options={})
107
- if evt = Event.capture_exception(exception, options)
108
+ if evt = Event.from_exception(exception, options)
108
109
  yield evt if block_given?
109
110
  send(evt)
110
111
  end
111
112
  end
112
113
 
113
114
  def capture_message(message, options={})
114
- if evt = Event.capture_message(message, options)
115
+ if evt = Event.from_message(message, options)
115
116
  yield evt if block_given?
116
117
  send(evt)
117
118
  end
@@ -149,6 +150,10 @@ module Raven
149
150
  self.context.extra.merge!(options)
150
151
  end
151
152
 
153
+ def rack_context(env)
154
+ self.context.rack_env = env
155
+ end
156
+
152
157
  # For cross-language compat
153
158
  alias :captureException :capture_exception
154
159
  alias :captureMessage :capture_message
@@ -11,7 +11,7 @@ module Raven
11
11
  # regexp (optionnally allowing leading X: for windows support)
12
12
  INPUT_FORMAT = %r{^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$}.freeze
13
13
 
14
- APP_DIRS_PATTERN = /^\/?(bin|app|config|lib|test)/
14
+ APP_DIRS_PATTERN = /^(bin|app|config|lib|test)/
15
15
 
16
16
  # The file portion of the line (such as app/models/user.rb)
17
17
  attr_reader :file
@@ -37,13 +37,18 @@ module Raven
37
37
  end
38
38
 
39
39
  def in_app
40
- if self.file =~ APP_DIRS_PATTERN
40
+ if (project_root && self.file.start_with?(project_root)) ||
41
+ (self.file =~ APP_DIRS_PATTERN)
41
42
  true
42
43
  else
43
44
  false
44
45
  end
45
46
  end
46
47
 
48
+ def project_root
49
+ @project_root ||= Raven.configuration.project_root && Raven.configuration.project_root.to_s
50
+ end
51
+
47
52
  # Reconstructs the line in a readable fashion
48
53
  def to_s
49
54
  "#{file}:#{number}:in `#{method}'"
@@ -0,0 +1,62 @@
1
+ require 'raven'
2
+
3
+ module Raven
4
+ class CLI
5
+ def self.test(dsn=nil)
6
+ require 'logger'
7
+
8
+ logger = ::Logger.new(STDOUT)
9
+ logger.level = ::Logger::ERROR
10
+ logger.formatter = proc do |severity, datetime, progname, msg|
11
+ "-> #{msg}\n"
12
+ end
13
+
14
+ Raven.configuration.logger = logger
15
+
16
+ if dsn then
17
+ Raven.configuration.dsn = dsn
18
+ end
19
+
20
+ # wipe out env settings to ensure we send the event
21
+ if !Raven.configuration.send_in_current_environment? then
22
+ env_name = Raven.coniguration.environments[0]
23
+ puts "Setting environment to #{env_name}"
24
+ Raven.configuration.current_environment = env_name
25
+ end
26
+
27
+ if !Raven.configuration.server then
28
+ puts "Your client is not configured!"
29
+ exit 1
30
+ end
31
+
32
+ puts "Client configuration:"
33
+ ['server', 'project_id', 'public_key', 'secret_key'].each do |key|
34
+ if !Raven.configuration[key] then
35
+ puts "Missing configuration for #{key}"
36
+ exit 1
37
+ end
38
+ puts "-> #{key}: #{Raven.configuration[key]}"
39
+ end
40
+ puts ""
41
+
42
+ puts "Sending a test event:"
43
+
44
+ begin
45
+ 1 / 0
46
+ rescue ZeroDivisionError => exception
47
+ evt = Raven.capture_exception(exception)
48
+ end
49
+
50
+ if evt then
51
+ puts "-> event ID: #{evt.id}"
52
+ else
53
+ puts ""
54
+ puts "An error occurred while attempting to send the event."
55
+ exit 1
56
+ end
57
+
58
+ puts ""
59
+ puts "Done!"
60
+ end
61
+ end
62
+ end
@@ -22,7 +22,10 @@ module Raven
22
22
  end
23
23
 
24
24
  def send(event)
25
- return unless configuration.send_in_current_environment?
25
+ if !configuration.send_in_current_environment?
26
+ Raven.logger.debug "Event not sent due to excluded environment: #{configuration.current_environment}"
27
+ return
28
+ end
26
29
 
27
30
  # Set the project ID correctly
28
31
  event.project = self.configuration.project_id
@@ -32,9 +35,12 @@ module Raven
32
35
  begin
33
36
  transport.send(generate_auth_header(encoded_data), encoded_data,
34
37
  :content_type => content_type)
35
- rescue
36
- Raven.logger.error "Unable to record event with remote Sentry server"
38
+ rescue => e
39
+ Raven.logger.error "Unable to record event with remote Sentry server (#{e.class} - #{e.message})"
40
+ return
37
41
  end
42
+
43
+ return event
38
44
  end
39
45
 
40
46
  private
@@ -52,6 +52,9 @@ module Raven
52
52
  # Should the SSL certificate of the server be verified?
53
53
  attr_accessor :ssl_verification
54
54
 
55
+ # Ssl settings passed direactly to faraday's ssl option
56
+ attr_accessor :ssl
57
+
55
58
  attr_reader :current_environment
56
59
 
57
60
  # The Faraday adapter to be used. Will default to Net::HTTP when not set.
@@ -9,11 +9,13 @@ module Raven
9
9
  end
10
10
 
11
11
  attr_reader :extra, :tags, :user
12
+ attr_accessor :rack_env
12
13
 
13
14
  def initialize
14
- @extra = {}
15
- @tags = {}
16
- @user = {}
15
+ @extra = {}
16
+ @tags = {}
17
+ @user = {}
18
+ @rack_env = nil
17
19
  end
18
20
  end
19
21
  end
@@ -57,6 +57,12 @@ module Raven
57
57
 
58
58
  block.call(self) if block
59
59
 
60
+ if !self[:http] && context.rack_env
61
+ self.interface :http do |int|
62
+ int.from_rack(context.rack_env)
63
+ end
64
+ end
65
+
60
66
  # Some type coercion
61
67
  @timestamp = @timestamp.strftime('%Y-%m-%dT%H:%M:%S') if @timestamp.is_a?(Time)
62
68
  @level = LOG_LEVELS[@level.to_s.downcase] if @level.is_a?(String) || @level.is_a?(Symbol)
@@ -110,7 +116,7 @@ module Raven
110
116
  data
111
117
  end
112
118
 
113
- def self.capture_exception(exc, options={}, &block)
119
+ def self.from_exception(exc, options={}, &block)
114
120
  configuration = options[:configuration] || Raven.configuration
115
121
  if exc.is_a?(Raven::Error)
116
122
  # Try to prevent error reporting loops
@@ -150,7 +156,7 @@ module Raven
150
156
  end
151
157
  end
152
158
 
153
- def self.capture_message(message, options={})
159
+ def self.from_message(message, options={})
154
160
  new(options) do |evt|
155
161
  evt.message = message
156
162
  evt.level = options[:level] || :error
@@ -173,7 +179,7 @@ module Raven
173
179
 
174
180
  def get_culprit(frames)
175
181
  lastframe = frames.reverse.detect { |f| f.in_app } || frames.last
176
- "#{lastframe.filename} in #{lastframe.function}" if lastframe
182
+ "#{lastframe.filename} in #{lastframe.function} at line #{lastframe.lineno}" if lastframe
177
183
  end
178
184
 
179
185
  def parse_exception(exception)
@@ -186,8 +192,10 @@ module Raven
186
192
 
187
193
  # For cross-language compat
188
194
  class << self
189
- alias :captureException :capture_exception
190
- alias :captureMessage :capture_message
195
+ alias :captureException :from_exception
196
+ alias :captureMessage :from_message
197
+ alias :capture_exception :from_exception
198
+ alias :capture_message :from_message
191
199
  end
192
200
 
193
201
  private
@@ -31,7 +31,9 @@ module Raven
31
31
  # Header
32
32
  http_key = key[5..key.length-1].split('_').map{|s| s.capitalize}.join('-')
33
33
  self.headers[http_key] = value.to_s
34
- else
34
+ elsif ['CONTENT_TYPE', 'CONTENT_LENGTH'].include? key
35
+ self.headers[key.capitalize] = value.to_s
36
+ elsif ['REMOTE_ADDR', 'SERVER_NAME', 'SERVER_PORT'].include? key
35
37
  # Environment
36
38
  self.env[key] = value.to_s
37
39
  end
@@ -39,6 +39,10 @@ module Raven
39
39
  end
40
40
 
41
41
  def call(env)
42
+ # store the current environment in our local context for arbitrary
43
+ # callers
44
+ Raven.rack_context(env)
45
+
42
46
  begin
43
47
  response = @app.call(env)
44
48
  rescue Error => e
@@ -28,6 +28,10 @@ module Raven
28
28
  ::ActionDispatch::ShowExceptions.send(:include, Raven::Rails::Middleware::DebugExceptionsCatcher)
29
29
  end
30
30
  end
31
+
32
+ rake_tasks do
33
+ require 'raven/tasks'
34
+ end
31
35
  end
32
36
  end
33
37
 
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'raven'
3
+ require 'raven/cli'
4
+
5
+ namespace :raven do
6
+ desc "Send a test event to the remote Sentry server"
7
+ task :test, [:dsn] do |t, args|
8
+ Raven::CLI::test(args.dsn)
9
+ end
10
+ end
@@ -27,9 +27,12 @@ module Raven
27
27
 
28
28
  Raven.logger.debug "Raven HTTP Transport connecting to #{self.configuration.server}"
29
29
 
30
+ ssl_configuration = self.configuration.ssl || {}
31
+ ssl_configuration[:verify] = self.configuration.ssl_verification if self.configuration.ssl_verification
32
+
30
33
  conn = Faraday.new(
31
34
  :url => self.configuration[:server],
32
- :ssl => {:verify => self.configuration.ssl_verification}
35
+ :ssl => ssl_configuration
33
36
  ) do |builder|
34
37
  builder.adapter(*adapter)
35
38
  end
@@ -1,3 +1,3 @@
1
1
  module Raven
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-raven
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-24 00:00:00.000000000 Z
13
+ date: 2013-05-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
17
- requirement: &70157840148660 !ruby/object:Gem::Requirement
17
+ requirement: &70216994650660 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.7.6
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70157840148660
25
+ version_requirements: *70216994650660
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: uuidtools
28
- requirement: &70157840148260 !ruby/object:Gem::Requirement
28
+ requirement: &70216994650180 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70157840148260
36
+ version_requirements: *70216994650180
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: multi_json
39
- requirement: &70157840147720 !ruby/object:Gem::Requirement
39
+ requirement: &70216994649560 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,21 +44,21 @@ dependencies:
44
44
  version: '1.0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70157840147720
47
+ version_requirements: *70216994649560
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: hashie
50
- requirement: &70157840147300 !ruby/object:Gem::Requirement
50
+ requirement: &70216994648520 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: 1.1.0
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70157840147300
58
+ version_requirements: *70216994648520
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rake
61
- requirement: &70157840163200 !ruby/object:Gem::Requirement
61
+ requirement: &70216994648060 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70157840163200
69
+ version_requirements: *70216994648060
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec
72
- requirement: &70157840162700 !ruby/object:Gem::Requirement
72
+ requirement: &70216994647080 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '2.10'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70157840162700
80
+ version_requirements: *70216994647080
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: simplecov
83
- requirement: &70157840162260 !ruby/object:Gem::Requirement
83
+ requirement: &70216994646440 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70157840162260
91
+ version_requirements: *70216994646440
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: coveralls
94
- requirement: &70157840161800 !ruby/object:Gem::Requirement
94
+ requirement: &70216994645920 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,7 +99,7 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70157840161800
102
+ version_requirements: *70216994645920
103
103
  description:
104
104
  email: noah@coderanger.net
105
105
  executables:
@@ -110,6 +110,7 @@ extra_rdoc_files:
110
110
  - LICENSE
111
111
  files:
112
112
  - lib/raven/backtrace.rb
113
+ - lib/raven/cli.rb
113
114
  - lib/raven/client.rb
114
115
  - lib/raven/configuration.rb
115
116
  - lib/raven/context.rb
@@ -129,6 +130,7 @@ files:
129
130
  - lib/raven/rails/middleware/debug_exceptions_catcher.rb
130
131
  - lib/raven/railtie.rb
131
132
  - lib/raven/sidekiq.rb
133
+ - lib/raven/tasks.rb
132
134
  - lib/raven/transports/http.rb
133
135
  - lib/raven/transports/udp.rb
134
136
  - lib/raven/transports.rb