raygun4ruby 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8406d25f885f4bff7478ef400ec6b6533beabeb1
4
- data.tar.gz: 0cff5631608f72c7fe29e42b043f0e45a05c0f33
3
+ metadata.gz: 1b5dc6fa5ba97eb5e725e33957adb0938d497c04
4
+ data.tar.gz: d8251293800014da04f65d59a7de524310bf0575
5
5
  SHA512:
6
- metadata.gz: 81aaeb31a3c51c0aab19614aedc0be72ff9bc3b047e54534f665ef296449617e536dcf0f9eae3776609790bed94b776bd3820a28bd7e773a844fce7204b44816
7
- data.tar.gz: 33b0cbebc15be4473bbec8db356ccc09138b6fa8d33538bf1394518d96c527e902c442a5fa332678631d66e4d0ef995713b3f091e92431360764b446a9dfe907
6
+ metadata.gz: a7e838b56806115af7f151908b8323c106677de99764b4fe0a30939cc15e9a529f34193643c3173d02ccd65c60b8492cd96b934f317f3b44f46827463d86a8b1
7
+ data.tar.gz: 362c3b34876de277572b93e7c4017adee6222839a3e1c711c7cf20181438501d302446d95735c4d8f61b719ae2dbfdc93428ef4ce61276158a6505e0d062854a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 2.5.0 (04/10/2017)
2
+
3
+ Features
4
+ - Teach tags configuration how to handle a proc to allow dynamically settings tags ([#127](https://github.com/MindscapeHQ/raygun4ruby/pull/127))
5
+
6
+ Bugfixes
7
+ - Fix crash when recording breadcrumb with uninitialized store ([#126](https://github.com/MindscapeHQ/raygun4ruby/pull/126))
8
+ - Make raw data handling more robus and fix in unicorn ([#125](https://github.com/MindscapeHQ/raygun4ruby/pull/125))
9
+ - Backwards compatible affected_user_identifier_methods ([#120](https://github.com/MindscapeHQ/raygun4ruby/pull/120))
10
+
1
11
  ## 2.4.1 (29/08/2017)
2
12
 
3
13
  Bugfixes
data/README.md CHANGED
@@ -138,6 +138,7 @@ end
138
138
 
139
139
  If you are using Sinatra or another rack framework you will need to include the Breadcrumbs middleware, this is used for storing the breadcrumbs during a request
140
140
  `use Raygun::Middleware::BreadcrumbsStoreInitializer`
141
+ (this must be before you `use` the `Raygun::Middleware::RackExceptionInterceptor`)
141
142
 
142
143
  If you are using a non web based Ruby application you will have to call `Raygun::Breadcrumbs::Store.initialize` during your applications boot process. The store is per thread, but I have not tested it in a multi threaded application.
143
144
 
@@ -192,13 +193,11 @@ end
192
193
  Custom data can be added to `track_exception` by passing a custom_data key in the second parameter hash.
193
194
 
194
195
  ```ruby
195
-
196
196
  begin
197
197
  # more lovely code
198
198
  rescue Exception => e
199
199
  Raygun.track_exception(e, custom_data: {my: 'custom data', goes: 'here'})
200
200
  end
201
-
202
201
  ```
203
202
 
204
203
  Custom data can also be specified globally either by setting `config.custom_data` to a hash
@@ -320,8 +319,17 @@ end
320
319
 
321
320
  ### Tags
322
321
 
323
- Raygun allows you to tag error reports with any number of tags. In your Raygun.setup block, set `tags` to an array of strings to have those
324
- set on any error reports sent by the gem.
322
+ Tags can be added to `track_exception` by passing a tags key in the second parameter hash.
323
+
324
+ ```ruby
325
+ begin
326
+ # more lovely code
327
+ rescue Exception => e
328
+ Raygun.track_exception(e, tags: ['my', 'tags', 'go here')
329
+ end
330
+ ```
331
+
332
+ Tags can also be specified globally either by setting `config.custom_data` to an array
325
333
 
326
334
  ```ruby
327
335
  Raygun.setup do |config|
@@ -329,6 +337,17 @@ Raygun.setup do |config|
329
337
  end
330
338
  ```
331
339
 
340
+ or to a proc, which gets passed the exception and environment hash. This proc _must_ return an array of strings
341
+
342
+ ```ruby
343
+ Raygun.setup do |config|
344
+ config.api_key = "YOUR_RAYGUN_API_KEY"
345
+ config.tags do |e, env|
346
+ [env["SERVER_NAME"]]
347
+ end
348
+ end
349
+ ```
350
+
332
351
  ### Resque Error Tracking
333
352
 
334
353
  Raygun4Ruby also includes a Resque failure backend. You should include it inside your Resque initializer (usually something like `config/initializers/load_resque.rb`)
@@ -50,6 +50,14 @@ module Raygun
50
50
  private
51
51
 
52
52
  def self.should_record?(crumb)
53
+ if stored.nil?
54
+ if Raygun.configuration.debug
55
+ Raygun.log('[Raygun.breadcrumbs] store is uninitialized while breadcrumb is being recorded, discarding breadcrumb')
56
+ end
57
+
58
+ return false
59
+ end
60
+
53
61
  levels = Raygun::Breadcrumbs::BREADCRUMB_LEVELS
54
62
 
55
63
  active_level = levels.index(Raygun.configuration.breadcrumb_level)
data/lib/raygun/client.rb CHANGED
@@ -132,20 +132,18 @@ module Raygun
132
132
  end
133
133
 
134
134
  def raw_data(rack_env)
135
+ request = Rack::Request.new(rack_env)
136
+
135
137
  return unless Raygun.configuration.record_raw_data
138
+ return if request.get?
136
139
 
137
- request = Rack::Request.new(rack_env)
138
140
  input = rack_env['rack.input']
139
- return if request.get?
140
141
 
141
- # If size is 0 the buffer is at best empty and at worst
142
- # something like the Puma::NullIO buffer which is missing methods
143
- if input && input.size && input.respond_to?(:pos) && !request.form_data?
144
- current_position = input.pos
142
+ if input && !request.form_data?
145
143
  input.rewind
146
144
 
147
- body = (input.read || '').slice(0, 4096)
148
- input.seek(current_position)
145
+ body = input.read(4096) || ''
146
+ input.rewind
149
147
 
150
148
  body
151
149
  else
@@ -175,6 +173,13 @@ module Raygun
175
173
  tags << rack_env
176
174
  end
177
175
 
176
+ configuration_tags = []
177
+ if Raygun.configuration.tags.is_a?(Proc)
178
+ configuration_tags = Raygun.configuration.tags.call(exception_instance, env)
179
+ else
180
+ configuration_tags = Raygun.configuration.tags
181
+ end
182
+
178
183
  grouping_key = env.delete(:grouping_key)
179
184
 
180
185
  configuration_custom_data = Raygun.configuration.custom_data
@@ -190,7 +195,7 @@ module Raygun
190
195
  client: client_details,
191
196
  error: error_details(exception_instance),
192
197
  userCustomData: exception_custom_data.merge(custom_data).merge(configured_custom_data),
193
- tags: Raygun.configuration.tags.concat(tags).compact.uniq,
198
+ tags: configuration_tags.concat(tags).compact.uniq,
194
199
  request: request_information(env),
195
200
  environment: {
196
201
  utcOffset: Time.now.utc_offset / 3600
@@ -35,7 +35,7 @@ module Raygun
35
35
  proc_config_option :custom_data
36
36
 
37
37
  # Tags to send with each exception
38
- config_option :tags
38
+ proc_config_option :tags
39
39
 
40
40
  # Logger to use when we find an exception :)
41
41
  config_option :logger
@@ -163,7 +163,7 @@ module Raygun
163
163
 
164
164
  def affected_user_identifier_methods
165
165
  Raygun.deprecation_warning("Please note: You should now user config.affected_user_method_mapping.Identifier instead of config.affected_user_identifier_methods")
166
- read_value(:affected_user_method_mapping).Identifier
166
+ read_value(:affected_user_mapping)[:identifier]
167
167
  end
168
168
 
169
169
  private
@@ -1,3 +1,3 @@
1
1
  module Raygun
2
- VERSION = "2.4.1"
2
+ VERSION = "2.5.0"
3
3
  end
@@ -36,6 +36,14 @@ class ClientTest < Raygun::UnitTest
36
36
  ENV['TZ'] = 'UTC-13'
37
37
  end
38
38
 
39
+ def test_record_breadcrumb_does_not_crash_without_initialized_store
40
+ Raygun.record_breadcrumb(
41
+ message: 'aliens',
42
+ category: 'exceptions',
43
+ level: :info
44
+ )
45
+ end
46
+
39
47
  def test_api_key_required_message
40
48
  Raygun.configuration.api_key = nil
41
49
 
@@ -139,6 +147,23 @@ class ClientTest < Raygun::UnitTest
139
147
  assert_equal expected_tags, @client.send(:build_payload_hash, test_exception, test_env)[:details][:tags]
140
148
  end
141
149
 
150
+ def test_tags_with_proc
151
+ configuration_tags = %w{bar}
152
+ explicit_env_tags = %w{one two three four}
153
+ rack_env_tag = %w{test}
154
+
155
+ Raygun.setup do |config|
156
+ config.tags = ->(exception, env) {
157
+ [env[:foo]]
158
+ }
159
+ end
160
+
161
+ test_env = { tags: explicit_env_tags, foo: 'bar' }
162
+ expected_tags = configuration_tags + explicit_env_tags + rack_env_tag
163
+
164
+ assert_equal expected_tags, @client.send(:build_payload_hash, test_exception, test_env)[:details][:tags]
165
+ end
166
+
142
167
  def test_hostname
143
168
  assert_equal Socket.gethostname, @client.send(:hostname)
144
169
  end
@@ -656,21 +681,6 @@ class ClientTest < Raygun::UnitTest
656
681
  assert breadcrumbs[0].is_a? Hash
657
682
  end
658
683
 
659
- def test_raw_data_rewinds_and_restores_correctly
660
- buffer = StringIO.new('123456789')
661
- rack_env = {
662
- REQUEST_METHOD: 'POST',
663
- 'rack.input' => buffer
664
- }
665
-
666
- buffer.seek(2)
667
-
668
- raw_data = @client.send(:raw_data, rack_env)
669
-
670
- assert_equal '123456789', raw_data
671
- assert_equal buffer.pos, 2
672
- end
673
-
674
684
  def test_raw_data_does_not_crash_on_buffer_without_pos
675
685
  buffer = StringIO.new('123456789')
676
686
  rack_env = {
@@ -682,7 +692,7 @@ class ClientTest < Raygun::UnitTest
682
692
 
683
693
  raw_data = @client.send(:raw_data, rack_env)
684
694
 
685
- assert_equal({}, raw_data)
695
+ assert_equal('123456789', raw_data)
686
696
  end
687
697
 
688
698
  private
@@ -126,6 +126,22 @@ class ConfigurationTest < Raygun::UnitTest
126
126
  Raygun.configuration.custom_data = nil
127
127
  end
128
128
 
129
+ def test_setting_tags_to_array
130
+ Raygun.setup do |c|
131
+ c.tags = ['test']
132
+ end
133
+
134
+ assert_equal Raygun.configuration.tags, ['test']
135
+ end
136
+
137
+ def test_setting_tags_to_proc
138
+ Raygun.setup do |c|
139
+ c.tags = ->(exception, env) {}
140
+ end
141
+
142
+ assert Raygun.configuration.tags.is_a?(Proc)
143
+ end
144
+
129
145
  def test_api_url_default
130
146
  assert_equal "https://api.raygun.io/", Raygun.configuration.api_url
131
147
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raygun4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mindscape
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-28 00:00:00.000000000 Z
12
+ date: 2017-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty