opbeat 3.0.6 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9afe9302e23fe8be3f93793b4771a7513be7f14
4
- data.tar.gz: a5f25103891b82047f3d60ea0d8a87fdbd6ccccf
3
+ metadata.gz: bf5b5eeb0ede28475a3290ad8fc105b5fbf62db3
4
+ data.tar.gz: c06e9dabae76fe0a072ebdb5c042339d451eab6f
5
5
  SHA512:
6
- metadata.gz: 0437ced62e7871333af7bc166c67103750ffe6a7715a9b8543f249f2a0cac78e5715230243ed0ea6155a5f77db9f07e32b476ae9f9f7879b9dffb9401bdcd6a4
7
- data.tar.gz: def822d870fcd98952b5890bea29c85dbd50f66d3f515f6a14259a24ce257e5d57799d0f5cf081e08e1b98c25160b0816b2726e48b6f632e9e23be647611ab51
6
+ metadata.gz: 9d77abf28473b178c296f39ba161514b0d90106801546dafe75a3edef8e3b4dbd7c94ccdbf2797248fea18139b4f4e42d26f733cf2353bf5a22f0e40fef28052
7
+ data.tar.gz: 3735cf0fc7fb86d5bcab6b590daf82b91a36a9f5f5214b4c913b6f4cb7ff5b5aaab4e8f5338a3f45da85d812fa2355bf3408f562908ecb18a03d8439071d719a
data/HISTORY.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 3.0.7
2
+
3
+ **Features**
4
+
5
+ - Add `config.worker_quit_timeout` (default is 5 secs) ([@jensnockert](https://github.com/jensnockert))
6
+ - Add `Opbeat.with_context` for block-specific contexts ([@jensnockert](https://github.com/jensnockert))
7
+
1
8
  # 3.0.6
2
9
 
3
10
  **Fixes**
data/README.md CHANGED
@@ -103,6 +103,14 @@ class DashboardController < ApplicationController
103
103
  end
104
104
  ```
105
105
 
106
+ or by specifying it as a block using `Opbeat.context` eg:
107
+
108
+ ```ruby
109
+ Opbeat.with_context(user_id: @user.id) do
110
+ UserMailer.welcome_email(@user).deliver_now
111
+ end
112
+ ```
113
+
106
114
  ## Background processing
107
115
 
108
116
  Opbeat automatically catches exceptions in [delayed_job](https://github.com/collectiveidea/delayed_job) or [sidekiq](http://sidekiq.org/).
@@ -86,6 +86,19 @@ module Opbeat
86
86
  client.set_context context
87
87
  end
88
88
 
89
+ # Updates context for errors within the block
90
+ #
91
+ # @param context [Hash]
92
+ # @yield [Trace] Block in which the context is used
93
+ def self.with_context context, &block
94
+ unless client
95
+ return yield if block_given?
96
+ return nil
97
+ end
98
+
99
+ client.context context, &block
100
+ end
101
+
89
102
  # Send an exception to Opbeat
90
103
  #
91
104
  # @param exception [Exception]
@@ -173,6 +173,16 @@ module Opbeat
173
173
  @context = context
174
174
  end
175
175
 
176
+ def with_context context, &block
177
+ current = @context
178
+
179
+ set_context((current || {}).merge(context))
180
+
181
+ yield if block_given?
182
+ ensure
183
+ set_context(current)
184
+ end
185
+
176
186
  def report exception, opts = {}
177
187
  return if config.disable_errors
178
188
  return unless exception
@@ -260,7 +270,7 @@ module Opbeat
260
270
  def kill_worker
261
271
  return unless worker_running?
262
272
  @queue << Worker::StopMessage.new
263
- unless @worker_thread.join 5
273
+ unless @worker_thread.join(config.worker_quit_timeout)
264
274
  error "Failed to wait for worker, not all messages sent"
265
275
  end
266
276
  @worker_thread = nil
@@ -16,6 +16,7 @@ module Opbeat
16
16
  current_user_method: :current_user,
17
17
  environment: ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'default',
18
18
  transaction_post_interval: 60,
19
+ worker_quit_timeout: 5,
19
20
 
20
21
  disable_performance: false,
21
22
  disable_errors: false,
@@ -43,6 +44,7 @@ module Opbeat
43
44
  attr_accessor :current_user_method
44
45
  attr_accessor :environment
45
46
  attr_accessor :transaction_post_interval
47
+ attr_accessor :worker_quit_timeout
46
48
 
47
49
  attr_accessor :disable_performance
48
50
  attr_accessor :disable_errors
@@ -1,3 +1,3 @@
1
1
  module Opbeat
2
- VERSION = "3.0.6"
2
+ VERSION = "3.0.7"
3
3
  end
@@ -114,6 +114,51 @@ module Opbeat
114
114
  end
115
115
  end
116
116
 
117
+ describe "#with_context" do
118
+ it "sets context for future errors" do
119
+ subject.with_context(additional_information: 'remember me') do
120
+ exception = Exception.new('BOOM')
121
+ subject.report exception
122
+ end
123
+
124
+ expect(subject.queue.length).to be 1
125
+ expect(subject.queue.pop.data[:extra]).to eq(additional_information: 'remember me')
126
+ end
127
+
128
+ it "supports nested contexts" do
129
+ subject.with_context(info: 'a') do
130
+ subject.with_context(more_info: 'b') do
131
+ exception = Exception.new('BOOM')
132
+ subject.report exception
133
+ end
134
+ end
135
+
136
+ expect(subject.queue.length).to be 1
137
+ expect(subject.queue.pop.data[:extra]).to eq(info: 'a', more_info: 'b')
138
+ end
139
+
140
+ it "restores context for future errors" do
141
+ subject.set_context(info: 'hello')
142
+
143
+ subject.with_context(additional_information: 'remember me') do
144
+ end
145
+
146
+ exception = Exception.new('BOOM')
147
+ subject.report exception
148
+
149
+ expect(subject.queue.length).to be 1
150
+ expect(subject.queue.pop.data[:extra]).to eq(info: 'hello')
151
+ end
152
+
153
+ it "returns what is yielded" do
154
+ result = subject.with_context(additional_information: 'remember me') do
155
+ 42
156
+ end
157
+
158
+ expect(result).to be 42
159
+ end
160
+ end
161
+
117
162
  describe "#report" do
118
163
  it "builds and posts an exception" do
119
164
  exception = Exception.new('BOOM')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opbeat
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.6
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Malmberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-20 00:00:00.000000000 Z
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport