opbeat 3.0.3 → 3.0.4

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: bd866037f5cf5ec4da1eff94c29ea67160e00a85
4
- data.tar.gz: 708b72d84b7b7697d0c8a8d77eeb50f19dae413a
3
+ metadata.gz: 62406440d5386dfb4cab59dcb5db22534d83c8c2
4
+ data.tar.gz: bfc8e55c4b8e34a4cd3093106ce8857f00f1b4b2
5
5
  SHA512:
6
- metadata.gz: 1e7a83cf2c9326970bc635ee1ea941c8f6368448218716fa8a8a67bbbb1eaf252ac5cc0eb16fa8a650c40813dd9a2d6e4bad816010b74f50a8df201d78a3daea
7
- data.tar.gz: e1c271dd9fa6942685b9fa28ab3ad4efcde20987e4942c8383d6907a8d05f9e9a55f370e81bd992c7ecd6cab6f84c63ff5c8e53d6c11dd33ac2b5f3ca330b4cf
6
+ metadata.gz: 702781cb7e485aa2b9539775be5beb0bb0710085d05aa1eedc76b4fe0247ecc21ef47e68ffd736e718f7c53a665a189a7041940d4912696c84196e1108df29c6
7
+ data.tar.gz: 4cfad284c0cfb8d8a9b1a1c1c5d02850efda47e7e5de5da47403af1c9513f87221e957e24e8eecbc526bfd2f6aa65080e8e21107e2ffd101904746c1fc4ec7a7
data/HISTORY.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 3.0.4
2
+
3
+ **Features**
4
+
5
+ - Added `Opbeat.set_context`.
6
+
7
+ **Fixes**
8
+
9
+ - Make the SQL descriptions fall back to just `SQL` ([@jensnockert](https://github.com/jensnockert))
10
+
1
11
  # 3.0.3
2
12
 
3
13
  **Features**
data/README.md CHANGED
@@ -87,10 +87,22 @@ config.opbeat.filter_parameters += [/regex(p)?/, "string", :symbol]
87
87
 
88
88
  Opbeat can automatically add user information to errors. By default it looks for at method called `current_user` on the current controller. To change the method use `current_user_method`.
89
89
 
90
- ```
90
+ ```ruby
91
91
  config.opbeat.current_user_method = :current_employee
92
92
  ```
93
93
 
94
+ ### Error context
95
+
96
+ You may specify extra context for errors ahead of time by using `Opbeat.set_context` eg:
97
+
98
+ ```ruby
99
+ class DashboardController < ApplicationController
100
+ before_filter do
101
+ Opbeat.set_context(timezone: current_user.timezone)
102
+ end
103
+ end
104
+ ```
105
+
94
106
  ## Background processing
95
107
 
96
108
  Opbeat automatically catches exceptions in [delayed_job](https://github.com/collectiveidea/delayed_job) or [sidekiq](http://sidekiq.org/).
@@ -169,6 +169,10 @@ module Opbeat
169
169
 
170
170
  # errors
171
171
 
172
+ def set_context context
173
+ @context = context
174
+ end
175
+
172
176
  def report exception, opts = {}
173
177
  return if config.disable_errors
174
178
  return unless exception
@@ -180,6 +184,7 @@ module Opbeat
180
184
  end
181
185
 
182
186
  error_message = ErrorMessage.from_exception(config, exception, opts)
187
+ error_message.add_extra(@context) if @context
183
188
  data = @data_builders.error_message.build error_message
184
189
  enqueue Worker::PostRequest.new('/errors/', data)
185
190
  end
@@ -188,6 +193,7 @@ module Opbeat
188
193
  return if config.disable_errors
189
194
 
190
195
  error_message = ErrorMessage.new(config, message, opts)
196
+ error_message.add_extra(@context) if @context
191
197
  data = @data_builders.error_message.build error_message
192
198
  enqueue Worker::PostRequest.new('/errors/', data)
193
199
  end
@@ -71,5 +71,10 @@ module Opbeat
71
71
 
72
72
  error_message
73
73
  end
74
+
75
+ def add_extra info
76
+ @extra ||= {}
77
+ @extra.merge! info
78
+ end
74
79
  end
75
80
  end
@@ -17,11 +17,13 @@ module Opbeat
17
17
  def signature_for sql
18
18
  return CACHE[sql] if CACHE[sql]
19
19
 
20
- REGEXES.find do |regex, sig|
20
+ result = REGEXES.find do |regex, sig|
21
21
  if match = sql.match(regex)
22
22
  break sig + match[1]
23
23
  end
24
24
  end
25
+
26
+ result || "SQL"
25
27
  end
26
28
  end
27
29
  end
@@ -1,3 +1,3 @@
1
1
  module Opbeat
2
- VERSION = "3.0.3"
2
+ VERSION = "3.0.4"
3
3
  end
@@ -102,6 +102,18 @@ module Opbeat
102
102
  end
103
103
  end
104
104
 
105
+ describe "#set_context" do
106
+ it "sets context for future errors" do
107
+ subject.set_context(additional_information: 'remember me')
108
+
109
+ exception = Exception.new('BOOM')
110
+ subject.report exception
111
+
112
+ expect(subject.queue.length).to be 1
113
+ expect(subject.queue.pop.data[:extra]).to eq(additional_information: 'remember me')
114
+ end
115
+ end
116
+
105
117
  describe "#report" do
106
118
  it "builds and posts an exception" do
107
119
  exception = Exception.new('BOOM')
@@ -80,5 +80,19 @@ module Opbeat
80
80
  end
81
81
  end
82
82
 
83
+ describe "#add_extra" do
84
+ it "adds extra info from hash" do
85
+ error_message = ErrorMessage.new config, "Message"
86
+ error_message.add_extra(thing: 1)
87
+ expect(error_message.extra).to eq(thing: 1)
88
+ end
89
+ it "merges with current" do
90
+ error_message = ErrorMessage.new config, "Message"
91
+ error_message.extra = { other_thing: 2 }
92
+ error_message.add_extra(thing: 1)
93
+ expect(error_message.extra).to eq(thing: 1, other_thing: 2)
94
+ end
95
+ end
96
+
83
97
  end
84
98
  end
@@ -2,5 +2,32 @@ require 'spec_helper'
2
2
 
3
3
  module Opbeat
4
4
  RSpec.describe SqlSummarizer do
5
+ let(:config) { Configuration.new }
6
+
7
+ subject { SqlSummarizer.new(config) }
8
+
9
+ it 'summarizes selects' do
10
+ expect(subject.signature_for("SELECT CAST(SERVERPROPERTY('ProductVersion') AS varchar)")).to eq('SQL')
11
+ end
12
+
13
+ it 'summarizes selects from table' do
14
+ expect(subject.signature_for("SELECT * FROM table")).to eq('SELECT FROM table')
15
+ end
16
+
17
+ it 'summarizes selects from table with columns' do
18
+ expect(subject.signature_for("SELECT a, b FROM table")).to eq('SELECT FROM table')
19
+ end
20
+
21
+ it 'summarizes inserts' do
22
+ expect(subject.signature_for("INSERT INTO table (a, b) VALUES ('A','B')")).to eq('INSERT INTO table')
23
+ end
24
+
25
+ it 'summarizes updates' do
26
+ expect(subject.signature_for("UPDATE table SET a = 'B' WHERE b = 'B'")).to eq('UPDATE table')
27
+ end
28
+
29
+ it 'summarizes deletes' do
30
+ expect(subject.signature_for("DELETE FROM table WHERE b = 'B'")).to eq('DELETE FROM table')
31
+ end
5
32
  end
6
33
  end
@@ -20,6 +20,7 @@ RSpec.describe Opbeat do
20
20
  it { should delegate :transaction, to: Opbeat::Client.inst, args: ['Test', nil, nil] }
21
21
  it { should delegate :trace, to: Opbeat::Client.inst, args: ['test', nil, {}] }
22
22
  it { should delegate :report, to: Opbeat::Client.inst, args: [Exception.new, nil] }
23
+ it { should delegate :set_context, to: Opbeat::Client.inst, args: [{}] }
23
24
  it { should delegate :report_message, to: Opbeat::Client.inst, args: ["My message", nil] }
24
25
  it { should delegate :release, to: Opbeat::Client.inst, args: [{}, {}] }
25
26
  it { should delegate :capture, to: Opbeat::Client.inst }
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.3
4
+ version: 3.0.4
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-02-24 00:00:00.000000000 Z
11
+ date: 2016-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport