sentry-raven 0.4.2 → 0.4.3

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.

@@ -1,9 +1,10 @@
1
1
  require 'raven/version'
2
2
  require 'raven/backtrace'
3
3
  require 'raven/configuration'
4
- require 'raven/logger'
4
+ require 'raven/context'
5
5
  require 'raven/client'
6
6
  require 'raven/event'
7
+ require 'raven/logger'
7
8
  require 'raven/rack'
8
9
  require 'raven/interfaces/message'
9
10
  require 'raven/interfaces/exception'
@@ -25,13 +26,15 @@ module Raven
25
26
  # values for all Raven configuration options. See Raven::Configuration.
26
27
  attr_writer :configuration
27
28
 
28
- def logger
29
- @logger ||= Logger.new
29
+ # Additional context for events
30
+ attr_writer :context
31
+
32
+ def context
33
+ @context ||= Context.new
30
34
  end
31
35
 
32
- # Tell the log that the client is good to go
33
- def report_ready
34
- self.logger.info "Raven #{VERSION} ready to catch errors"
36
+ def logger
37
+ @logger ||= Logger.new
35
38
  end
36
39
 
37
40
  # The configuration object.
@@ -45,6 +48,11 @@ module Raven
45
48
  @client ||= Client.new(configuration)
46
49
  end
47
50
 
51
+ # Tell the log that the client is good to go
52
+ def report_ready
53
+ self.logger.info "Raven #{VERSION} ready to catch errors"
54
+ end
55
+
48
56
  # Call this method to modify defaults in your initializers.
49
57
  #
50
58
  # @example
@@ -108,22 +116,16 @@ module Raven
108
116
  send(evt) if evt
109
117
  end
110
118
 
111
- # Bind context for any future events
112
- #
113
- # @example
114
- # Raven.context({
115
- # :tags => {
116
- # 'key' => 'value',
117
- # }
118
- # })
119
- def context(hash = {})
120
- Thread.current[:sentry_context] ||= {}
121
- Thread.current[:sentry_context].merge!(hash)
122
- self
119
+ def user_context(options={})
120
+ self.context.user.merge!(options)
121
+ end
122
+
123
+ def tags_context(options={})
124
+ self.context.tags.merge!(options)
123
125
  end
124
126
 
125
- def clear!
126
- Thread.current[:sentry_context] = nil
127
+ def extra_context(options={})
128
+ self.context.extra.merge!(options)
127
129
  end
128
130
 
129
131
  # For cross-language compat
@@ -10,7 +10,7 @@ module Raven
10
10
 
11
11
  class Client
12
12
 
13
- PROTOCOL_VERSION = '3.0'
13
+ PROTOCOL_VERSION = '3'
14
14
  USER_AGENT = "raven-ruby/#{Raven::VERSION}"
15
15
  CONTENT_TYPE = 'application/json'
16
16
 
@@ -51,6 +51,9 @@ module Raven
51
51
 
52
52
  attr_reader :current_environment
53
53
 
54
+ # The Faraday adapter to be used. Will default to Net::HTTP when not set.
55
+ attr_accessor :http_adapter
56
+
54
57
  IGNORE_DEFAULT = ['ActiveRecord::RecordNotFound',
55
58
  'ActionController::RoutingError',
56
59
  'ActionController::InvalidAuthenticityToken',
@@ -0,0 +1,19 @@
1
+ module Raven
2
+ class Context
3
+ def current
4
+ Thread.current[:sentry_context] ||= new
5
+ end
6
+
7
+ def clear!
8
+ Thread.current[:sentry_context] = nil
9
+ end
10
+
11
+ attr_reader :extra, :tags, :user
12
+
13
+ def initialize
14
+ @extra = {}
15
+ @tags = {}
16
+ @user = {}
17
+ end
18
+ end
19
+ end
@@ -23,27 +23,22 @@ module Raven
23
23
  PLATFORM = "ruby"
24
24
 
25
25
  attr_reader :id
26
- attr_accessor :project, :message, :timestamp, :level, :context
26
+ attr_accessor :project, :message, :timestamp, :level
27
27
  attr_accessor :logger, :culprit, :server_name, :modules, :extra, :tags
28
28
 
29
29
  def initialize(options={}, &block)
30
30
  @configuration = options[:configuration] || Raven.configuration
31
31
  @interfaces = {}
32
32
 
33
- @context = Thread.current[:sentry_context] || {}
33
+ context = options[:context] || Raven.context
34
34
 
35
35
  @id = options[:id] || UUIDTools::UUID.random_create.hexdigest
36
36
  @message = options[:message]
37
37
  @timestamp = options[:timestamp] || Time.now.utc
38
38
 
39
- @level = options[:level]
40
- @logger = options[:logger]
39
+ @level = options[:level] || :error
40
+ @logger = options[:logger] || 'root'
41
41
  @culprit = options[:culprit]
42
-
43
- @extra = options[:extra] || {}
44
- @tags = options[:tags] || {}
45
-
46
- # Try to resolve the hostname to an FQDN, but fall back to whatever the load name is
47
42
  @server_name = options[:server_name] || get_hostname
48
43
 
49
44
  if @configuration.send_modules
@@ -51,15 +46,16 @@ module Raven
51
46
  end
52
47
  @modules = options[:modules]
53
48
 
54
- block.call(self) if block
49
+ @user = options[:user] || {}
50
+ @user.merge!(context.user)
55
51
 
56
- # Merge in context
57
- @level ||= @context[:level] || :error
58
- @logger ||= @context[:logger] || 'root'
59
- @culprit ||= @context[:culprit]
52
+ @extra = options[:extra] || {}
53
+ @extra.merge!(context.extra)
60
54
 
61
- @tags.merge!(@context[:tags]) if @context[:tags]
62
- @extra.merge!(@context[:extra]) if @context[:extra]
55
+ @tags = options[:tags] || {}
56
+ @tags.merge!(context.tags)
57
+
58
+ block.call(self) if block
63
59
 
64
60
  # Some type coercion
65
61
  @timestamp = @timestamp.strftime('%Y-%m-%dT%H:%M:%S') if @timestamp.is_a?(Time)
@@ -67,6 +63,7 @@ module Raven
67
63
  end
68
64
 
69
65
  def get_hostname
66
+ # Try to resolve the hostname to an FQDN, but fall back to whatever the load name is
70
67
  hostname = Socket.gethostname
71
68
  hostname = Socket.gethostbyname(hostname).first rescue hostname
72
69
  end
@@ -93,19 +90,20 @@ module Raven
93
90
 
94
91
  def to_hash
95
92
  data = {
96
- 'event_id' => self.id,
97
- 'message' => self.message,
98
- 'timestamp' => self.timestamp,
99
- 'level' => self.level,
100
- 'project' => self.project,
101
- 'logger' => self.logger,
93
+ 'event_id' => @id,
94
+ 'message' => @message,
95
+ 'timestamp' => @timestamp,
96
+ 'level' => @level,
97
+ 'project' => @project,
98
+ 'logger' => @logger,
102
99
  'platform' => PLATFORM,
103
100
  }
104
- data['culprit'] = self.culprit if self.culprit
105
- data['server_name'] = self.server_name if self.server_name
106
- data['modules'] = self.modules if self.modules
107
- data['extra'] = self.extra if self.extra
108
- data['tags'] = self.tags if self.tags
101
+ data['culprit'] = @culprit if @culprit
102
+ data['server_name'] = @server_name if @server_name
103
+ data['modules'] = @modules if @modules
104
+ data['extra'] = @extra if @extra
105
+ data['tags'] = @tags if @tags
106
+ data['sentry.interfaces.User'] = @user if @user
109
107
  @interfaces.each_pair do |name, int_data|
110
108
  data[name] = int_data.to_hash
111
109
  end
@@ -30,13 +30,17 @@ module Raven
30
30
  :url => self.configuration[:server],
31
31
  :ssl => {:verify => self.configuration.ssl_verification}
32
32
  ) do |builder|
33
- builder.adapter Faraday.default_adapter
33
+ builder.adapter(*adapter)
34
34
  builder.options[:timeout] = self.configuration.timeout if self.configuration.timeout
35
35
  builder.options[:open_timeout] = self.configuration.open_timeout if self.configuration.open_timeout
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
+ def adapter
41
+ configuration.http_adapter || Faraday.default_adapter
42
+ end
43
+
40
44
  end
41
45
 
42
46
  end
@@ -1,3 +1,3 @@
1
1
  module Raven
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
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.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-30 00:00:00.000000000 Z
13
+ date: 2013-02-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -88,6 +88,7 @@ files:
88
88
  - lib/raven/backtrace.rb
89
89
  - lib/raven/client.rb
90
90
  - lib/raven/configuration.rb
91
+ - lib/raven/context.rb
91
92
  - lib/raven/error.rb
92
93
  - lib/raven/event.rb
93
94
  - lib/raven/interfaces/exception.rb