raygun4ruby 2.0.0 → 2.1.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: 558ace0abc94bf42933ffec0ae4327a8cfba09a2
4
- data.tar.gz: a27eb894bc5e0079d7b10b40463c5e47c82b21ad
3
+ metadata.gz: f4273509fb2b19bd65ee19cb8589607b51938cde
4
+ data.tar.gz: 592cbaa95d8afc226508600af62f53c8086201f1
5
5
  SHA512:
6
- metadata.gz: c390cf858fa96eef0e2a42174c0098cefda944dc9d4e1ea85ce2c06b4e9e0795170fa409ff726ac2d5431aa2a928803a61c5d963a71e472bd0ebfa793f31f62f
7
- data.tar.gz: 6d334a8df11475639df6ad6eebdedc7d7301d61915392179b711ee45030ec2ec8f9e0fc411794e5ea53ce5bac90447af489925298e325a83760aea6bcf1dd21c
6
+ metadata.gz: 5e1fca4593ff9aa4d19de3b174750ec2142f8cfc599b2cc5358b9dcb8e3eb73930e905eb71dd27d546c984d6525b243f249a2b8f4c1d3b5bdedea387555d3adf
7
+ data.tar.gz: 4a7249e4ed86910f9d66a43fbb7937bed5e3b649af2a880c49c7a9663b2ddef63ddcf8c9416b712930e2cac7b4257b28b2dc92e36258f94718b307c6c3915e7b
data/CHANGELOG.md CHANGED
@@ -1,9 +1,15 @@
1
+ ## 2.1.0
2
+
3
+ Features
4
+ - Ability to record breadcrumbs in your code that will be sent to Raygun along with a raised exception ([#113](https://github.com/MindscapeHQ/raygun4ruby/pull/113))
5
+
1
6
  ## 2.0.0 (20/04/2017)
2
7
 
3
8
  Bugfixes:
4
9
  - Fix broken handling of raw request body reading in Rack applications ([#116](https://github.com/MindscapeHQ/raygun4ruby/pull/116))
5
10
  - This is a breaking change to how raw data was being read before so it requires a major version bump
6
11
  - Raw request data reading is now disabled by default and can be enabled via the `record_raw_data` configuration option
12
+
7
13
  ## 1.5.0 (16/03/2017)
8
14
 
9
15
  Features
data/README.md CHANGED
@@ -98,6 +98,49 @@ Raygun.setup do |config|
98
98
  end
99
99
  ```
100
100
 
101
+ ### Recording Breadcrumbs
102
+
103
+ Breadcrumbs let you provide logging points in your code that will be collected and sent along with any exception sent to Raygun. This lets you have a better understanding of the events that happened in the system that lead up to the exception.
104
+
105
+ 1. Include it as a module in your class
106
+ ```ruby
107
+ class SomeClass
108
+ include Raygun::Breadcrumbs
109
+
110
+ def some_method
111
+ record_breadcrumb(
112
+ message: "<log message goes here>",
113
+ category: "some category to group them by, maybe authentication or external-apis for example",
114
+ level: :info, # or debug or warning etc, you can configure what level will get sent
115
+ metadata: {custom_data: 'can go here'},
116
+ )
117
+ end
118
+ end
119
+ ```
120
+ This has the added benefit of recording the class the breadcrumb was recorded from automatically
121
+
122
+ 2. Call the `record_breadcrumb` method manually
123
+ ```ruby
124
+ def some_method
125
+ Raygun.record_breadcrumb(
126
+ message: "<log message goes here>",
127
+ category: "some category to group them by, maybe authentication or external-apis for example",
128
+ level: :info, # or debug or warning etc, you can configure what level will get sent
129
+ metadata: {custom_data: 'can go here'},
130
+
131
+ # You can also set the class the breadcrumb was logged from
132
+ # It will only be set automatically using the included module approach
133
+ # Method and line number will get added automatically
134
+ class_name: self.class.name
135
+ )
136
+ end
137
+ ```
138
+
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
+ `use Raygun::Middleware::BreadcrumbsStoreInitializer`
141
+
142
+ 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
+
101
144
  ### Filtering the payload by whitelist
102
145
 
103
146
  As an alternative to the above, you can also opt-in to the keys/values to be sent to Raygun by providing a specific whitelist of the keys you want to transmit.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ namespace :test do
7
7
 
8
8
  desc "Test the basics of the adapter"
9
9
  Rake::TestTask.new(:units) do |t|
10
- t.test_files = FileList["test/unit/*_test.rb"]
10
+ t.test_files = FileList["test/unit/*_test.rb", "specs/**/*_spec.rb"]
11
11
  t.verbose = true
12
12
  end
13
13
 
data/lib/raygun.rb CHANGED
@@ -14,10 +14,14 @@ require "raygun/version"
14
14
  require "raygun/configuration"
15
15
  require "raygun/client"
16
16
  require "raygun/middleware/rack_exception_interceptor"
17
+ require "raygun/middleware/breadcrumbs_store_initializer"
17
18
  require "raygun/testable"
18
19
  require "raygun/error"
19
20
  require "raygun/affected_user"
20
21
  require "raygun/services/apply_whitelist_filter_to_payload"
22
+ require "raygun/breadcrumbs/breadcrumb"
23
+ require "raygun/breadcrumbs/store"
24
+ require "raygun/breadcrumbs"
21
25
  require "raygun/railtie" if defined?(Rails)
22
26
 
23
27
  module Raygun
@@ -78,6 +82,28 @@ module Raygun
78
82
  track_exception(e)
79
83
  end
80
84
 
85
+ def record_breadcrumb(
86
+ message: nil,
87
+ category: '',
88
+ level: :info,
89
+ timestamp: Time.now.utc,
90
+ metadata: {},
91
+ class_name: nil,
92
+ method_name: nil,
93
+ line_number: nil
94
+ )
95
+ Raygun::Breadcrumbs::Store.record(
96
+ message: message,
97
+ category: category,
98
+ level: level,
99
+ timestamp: timestamp,
100
+ metadata: metadata,
101
+ class_name: class_name,
102
+ method_name: method_name,
103
+ line_number: line_number,
104
+ )
105
+ end
106
+
81
107
  def log(message)
82
108
  configuration.logger.info(message) if configuration.logger
83
109
  end
@@ -0,0 +1,34 @@
1
+ module Raygun
2
+ module Breadcrumbs
3
+ BREADCRUMB_LEVELS = [
4
+ :debug,
5
+ :info,
6
+ :warning,
7
+ :error,
8
+ :fatal
9
+ ]
10
+
11
+ def record_breadcrumb(
12
+ message: nil,
13
+ category: '',
14
+ level: :info,
15
+ timestamp: Time.now.utc.to_i,
16
+ metadata: {},
17
+ class_name: nil,
18
+ method_name: nil,
19
+ line_number: nil
20
+ )
21
+ class_name = class_name || self.class.name
22
+ Raygun::Breadcrumbs::Store.record(
23
+ message: message,
24
+ category: category,
25
+ level: level,
26
+ timestamp: timestamp,
27
+ metadata: metadata,
28
+ class_name: class_name,
29
+ method_name: method_name,
30
+ line_number: line_number,
31
+ )
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ module Raygun
2
+ module Breadcrumbs
3
+ class Breadcrumb
4
+ ATTRIBUTES = [
5
+ :message, :category, :metadata, :class_name,
6
+ :method_name, :line_number, :timestamp, :level,
7
+ :type
8
+ ]
9
+ attr_accessor(*ATTRIBUTES)
10
+
11
+ def build_payload
12
+ payload = {
13
+ message: message,
14
+ category: category,
15
+ level: Breadcrumbs::BREADCRUMB_LEVELS.index(level),
16
+ CustomData: metadata,
17
+ timestamp: timestamp,
18
+ type: type
19
+ }
20
+
21
+ payload[:location] = "#{class_name}:#{method_name}" unless class_name == nil
22
+ payload[:location] += ":#{line_number}" if payload.has_key?(:location) && line_number != nil
23
+
24
+ Hash[payload.select do |k, v|
25
+ v != nil
26
+ end]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,68 @@
1
+ require_relative 'breadcrumb'
2
+
3
+ module Raygun
4
+ module Breadcrumbs
5
+ class Store
6
+ def self.initialize
7
+ Thread.current[:breadcrumbs] ||= []
8
+ end
9
+
10
+ def self.clear
11
+ Thread.current[:breadcrumbs] = nil
12
+ end
13
+
14
+ def self.stored
15
+ Thread.current[:breadcrumbs]
16
+ end
17
+
18
+ def self.record(
19
+ message: nil,
20
+ category: '',
21
+ level: :info,
22
+ timestamp: Time.now.utc.to_i,
23
+ metadata: {},
24
+ class_name: nil,
25
+ method_name: nil,
26
+ line_number: nil
27
+ )
28
+ raise ArgumentError.new('missing keyword: message') if message == nil
29
+ crumb = Breadcrumb.new
30
+
31
+ crumb.message = message
32
+ crumb.category = category
33
+ crumb.level = level
34
+ crumb.metadata = metadata
35
+ crumb.timestamp = timestamp
36
+ crumb.type = 'manual'
37
+
38
+ caller = caller_locations[1]
39
+ crumb.class_name = class_name
40
+ crumb.method_name = method_name || caller.label
41
+ crumb.line_number = line_number || caller.lineno
42
+
43
+ Thread.current[:breadcrumbs] << crumb if should_record?(crumb)
44
+ end
45
+
46
+ def self.any?
47
+ stored != nil && stored.length > 0
48
+ end
49
+
50
+ private
51
+
52
+ def self.should_record?(crumb)
53
+ levels = Raygun::Breadcrumbs::BREADCRUMB_LEVELS
54
+
55
+ active_level = levels.index(Raygun.configuration.breadcrumb_level)
56
+ crumb_level = levels.index(crumb.level) || -1
57
+
58
+ discard = crumb_level < active_level
59
+
60
+ if discard && Raygun.configuration.debug
61
+ Raygun.log("[Raygun.breadcrumbs] discarding breadcrumb because #{crumb.level} is below active breadcrumb level (#{Raygun.configuration.breadcrumb_level})")
62
+ end
63
+
64
+ !discard
65
+ end
66
+ end
67
+ end
68
+ end
data/lib/raygun/client.rb CHANGED
@@ -193,6 +193,8 @@ module Raygun
193
193
  utcOffset: Time.now.utc_offset / 3600
194
194
  }
195
195
  }
196
+ store = ::Raygun::Breadcrumbs::Store
197
+ error_details[:breadcrumbs] = store.stored.map(&:build_payload) if store.any?
196
198
 
197
199
  error_details.merge!(groupingKey: grouping_key) if grouping_key
198
200
 
@@ -112,19 +112,20 @@ module Raygun
112
112
 
113
113
  # set default attribute values
114
114
  @defaults = OpenStruct.new({
115
- ignore: IGNORE_DEFAULT,
116
- custom_data: {},
117
- tags: [],
118
- enable_reporting: true,
119
- affected_user_method: :current_user,
120
- affected_user_mapping: AffectedUser::DEFAULT_MAPPING,
121
- filter_parameters: DEFAULT_FILTER_PARAMETERS,
122
- filter_payload_with_whitelist: false,
123
- whitelist_payload_shape: DEFAULT_WHITELIST_PAYLOAD_SHAPE,
124
- proxy_settings: {},
125
- debug: false,
126
- api_url: 'https://api.raygun.io/',
127
- record_raw_data: false
115
+ ignore: IGNORE_DEFAULT,
116
+ custom_data: {},
117
+ tags: [],
118
+ enable_reporting: true,
119
+ affected_user_method: :current_user,
120
+ affected_user_mapping: AffectedUser::DEFAULT_MAPPING,
121
+ filter_parameters: DEFAULT_FILTER_PARAMETERS,
122
+ filter_payload_with_whitelist: false,
123
+ whitelist_payload_shape: DEFAULT_WHITELIST_PAYLOAD_SHAPE,
124
+ proxy_settings: {},
125
+ debug: false,
126
+ api_url: 'https://api.raygun.io/',
127
+ breadcrumb_level: :info,
128
+ record_raw_data: false
128
129
  })
129
130
  end
130
131
 
@@ -144,6 +145,18 @@ module Raygun
144
145
  self.enable_reporting = !value
145
146
  end
146
147
 
148
+ def breadcrumb_level
149
+ read_value(:breadcrumb_level)
150
+ end
151
+
152
+ def breadcrumb_level=(value)
153
+ if Raygun::Breadcrumbs::BREADCRUMB_LEVELS.include?(value)
154
+ set_value(:breadcrumb_level, value)
155
+ elsif read_value(:debug)
156
+ Raygun.log("[Raygun.configuration] unknown breadcrumb level: #{value} not setting")
157
+ end
158
+ end
159
+
147
160
  def affected_user_identifier_methods
148
161
  Raygun.deprecation_warning("Please note: You should now user config.affected_user_method_mapping.Identifier instead of config.affected_user_identifier_methods")
149
162
  read_value(:affected_user_method_mapping).Identifier
@@ -0,0 +1,19 @@
1
+ module Raygun
2
+ module Middleware
3
+ class BreadcrumbsStoreInitializer
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ Breadcrumbs::Store.initialize
10
+
11
+ begin
12
+ @app.call(env)
13
+ ensure
14
+ Breadcrumbs::Store.clear
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,28 +1,30 @@
1
+ require "raygun/middleware/rails_insert_affected_user"
2
+
1
3
  class Raygun::Railtie < Rails::Railtie
2
4
  initializer "raygun.configure_rails_initialization" do |app|
3
5
 
4
6
  # Thanks Airbrake: See https://github.com/rails/rails/pull/8624
5
7
  middleware = if defined?(ActionDispatch::DebugExceptions)
6
- if Rails::VERSION::STRING >= "5"
7
- ActionDispatch::DebugExceptions
8
- else
9
- # Rails >= 3.2.0
10
- "ActionDispatch::DebugExceptions"
11
- end
12
- else
13
- # Rails < 3.2.0
14
- "ActionDispatch::ShowExceptions"
15
- end
8
+ if Rails::VERSION::STRING >= "5"
9
+ ActionDispatch::DebugExceptions
10
+ else
11
+ # Rails >= 3.2.0
12
+ "ActionDispatch::DebugExceptions"
13
+ end
14
+ else
15
+ # Rails < 3.2.0
16
+ "ActionDispatch::ShowExceptions"
17
+ end
16
18
 
17
- raygun_middleware = Raygun::Middleware::RackExceptionInterceptor
18
- raygun_middleware = raygun_middleware.to_s unless Rails::VERSION::STRING >= "5"
19
- app.config.middleware.insert_after middleware, raygun_middleware
20
-
21
- # Affected User tracking
22
- require "raygun/middleware/rails_insert_affected_user"
23
- affected_user_middleware = Raygun::Middleware::RailsInsertAffectedUser
24
- affected_user_middleware = affected_user_middleware.to_s unless Rails::VERSION::STRING >= "5"
25
- app.config.middleware.insert_after Raygun::Middleware::RackExceptionInterceptor, affected_user_middleware
19
+ raygun_middleware = [
20
+ Raygun::Middleware::RailsInsertAffectedUser,
21
+ Raygun::Middleware::RackExceptionInterceptor,
22
+ Raygun::Middleware::BreadcrumbsStoreInitializer
23
+ ]
24
+ raygun_middleware = raygun_middleware.map(&:to_s) unless Rails::VERSION::STRING >= "5"
25
+ raygun_middleware.each do |m|
26
+ app.config.middleware.insert_after(middleware, m)
27
+ end
26
28
  end
27
29
 
28
30
  config.to_prepare do
@@ -1,3 +1,3 @@
1
1
  module Raygun
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -0,0 +1,134 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ module Raygun
4
+ module Breadcrumbs
5
+ describe Breadcrumb do
6
+ let(:subject) { Breadcrumb.new }
7
+ context 'fields' do
8
+ it 'has a message' do
9
+ message = 'foo'
10
+
11
+ subject.message = message
12
+
13
+ subject.message.must_equal(message)
14
+ end
15
+
16
+ it 'has a category' do
17
+ category = 'foo'
18
+
19
+ subject.category = category
20
+
21
+ subject.category.must_equal(category)
22
+ end
23
+
24
+ it 'has a level' do
25
+ level = 'foo'
26
+
27
+ subject.level = level
28
+
29
+ subject.level.must_equal(level)
30
+ end
31
+
32
+ it 'has a timestamp' do
33
+ timestamp = Time.now
34
+
35
+ subject.timestamp = timestamp
36
+
37
+ subject.timestamp.must_equal(timestamp)
38
+ end
39
+
40
+ it 'has metadata' do
41
+ metadata = {foo: '1'}
42
+
43
+ subject.metadata = metadata
44
+
45
+ subject.metadata.must_equal(metadata)
46
+ end
47
+
48
+ it 'has a class_name' do
49
+ class_name = 'foo'
50
+
51
+ subject.class_name = class_name
52
+
53
+ subject.class_name.must_equal(class_name)
54
+ end
55
+
56
+ it 'has a method_name' do
57
+ method_name = 'foo'
58
+
59
+ subject.method_name = method_name
60
+
61
+ subject.method_name.must_equal(method_name)
62
+ end
63
+
64
+ it 'has a line_number' do
65
+ line_number = 17
66
+
67
+ subject.line_number = line_number
68
+
69
+ subject.line_number.must_equal(line_number)
70
+ end
71
+ end
72
+
73
+ describe "#build_payload" do
74
+ before do
75
+ Timecop.freeze
76
+ Store.initialize
77
+ end
78
+ after do
79
+ Timecop.return
80
+ Store.clear
81
+ end
82
+
83
+ let(:breadcrumb) do
84
+ Store.record(
85
+ message: "test",
86
+ category: "test",
87
+ level: :info,
88
+ class_name: "HomeController",
89
+ method_name: "index",
90
+ line_number: 17,
91
+ metadata: {
92
+ foo: 'bar'
93
+ }
94
+ )
95
+
96
+ Store.stored[0]
97
+ end
98
+ let(:payload) { breadcrumb.build_payload }
99
+
100
+ it "joins the class name, method name and line number together" do
101
+ payload[:location].must_equal("HomeController:index:17")
102
+ end
103
+
104
+ it "does not include the method name and line number if the class name is missing" do
105
+ breadcrumb.class_name = nil
106
+
107
+ payload.has_key?(:location).must_equal(false)
108
+ end
109
+
110
+ it "does not inlcude the line number if is it missing" do
111
+ breadcrumb.line_number = nil
112
+
113
+ payload[:location].must_equal("HomeController:index")
114
+ end
115
+
116
+ it "does not include keys in payload with nil values" do
117
+ breadcrumb.metadata = nil
118
+ breadcrumb.category = nil
119
+
120
+ payload.key?(:CustomData).must_equal(false)
121
+ payload.key?(:category).must_equal(false)
122
+ end
123
+
124
+ it 'includes the rest of the fields' do
125
+ payload[:message].must_equal('test')
126
+ payload[:category].must_equal('test')
127
+ payload[:level].must_equal(1)
128
+ payload[:timestamp].wont_be_nil
129
+ payload[:CustomData].must_equal(foo: 'bar')
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,148 @@
1
+ require "minitest/autorun"
2
+ require "minitest/pride"
3
+ require_relative "../../spec_helper"
4
+
5
+ module Raygun
6
+ module Breadcrumbs
7
+ describe Store do
8
+ let(:subject) { Store }
9
+ after { subject.clear }
10
+
11
+ describe "#initialize" do
12
+ before do
13
+ subject.stored.must_equal(nil)
14
+
15
+ subject.initialize
16
+ end
17
+
18
+ it "creates the store on the current Thread" do
19
+ subject.stored.must_equal([])
20
+ end
21
+
22
+ it "does not effect other threads" do
23
+ Thread.new do
24
+ subject.stored.must_equal(nil)
25
+ end.join
26
+ end
27
+ end
28
+
29
+ describe "any?" do
30
+ it "returns true if any breadcrumbs have been logged" do
31
+ subject.initialize
32
+
33
+ subject.record(message: "test")
34
+
35
+ subject.any?.must_equal(true)
36
+ end
37
+
38
+ it "returns false if none have been logged" do
39
+ subject.initialize
40
+
41
+ subject.any?.must_equal(false)
42
+ end
43
+
44
+ it "returns false if the store is uninitialized" do
45
+ subject.any?.must_equal(false)
46
+ end
47
+ end
48
+
49
+ describe "#clear" do
50
+ before do
51
+ subject.initialize
52
+ end
53
+
54
+ it "resets the store back to nil" do
55
+ subject.clear
56
+
57
+ subject.stored.must_equal(nil)
58
+ end
59
+ end
60
+
61
+ describe "#should_record?" do
62
+ it "returns false when the log level is above the breadcrumbs level" do
63
+ Raygun.configuration.stubs(:breadcrumb_level).returns(:error)
64
+
65
+ crumb = Breadcrumb.new
66
+ crumb.level = :warning
67
+
68
+ assert_equal false, subject.send(:should_record?, crumb)
69
+ end
70
+ end
71
+
72
+ context "adding a breadcrumb" do
73
+ class Foo
74
+ include ::Raygun::Breadcrumbs
75
+
76
+ def bar
77
+ record_breadcrumb(message: "test")
78
+ end
79
+ end
80
+
81
+ before do
82
+ subject.clear
83
+ subject.initialize
84
+ end
85
+
86
+ it "gets stored" do
87
+ subject.record(message: "test")
88
+
89
+ subject.stored.length.must_equal(1)
90
+ subject.stored[0].message.must_equal("test")
91
+ end
92
+
93
+ it "automatically sets the class name" do
94
+ Foo.new.bar
95
+
96
+ bc = subject.stored[0]
97
+ bc.class_name.must_equal("Raygun::Breadcrumbs::Foo")
98
+ end
99
+
100
+ it "automatically sets the method name" do
101
+ Foo.new.bar
102
+
103
+ bc = subject.stored[0]
104
+ bc.method_name.must_equal("bar")
105
+ end
106
+
107
+ it "does not set the method name if it is already set" do
108
+ subject.record(message: 'test', method_name: "foo")
109
+
110
+ subject.stored[0].method_name.must_equal("foo")
111
+ end
112
+
113
+
114
+ it "automatically sets the timestamp" do
115
+ Timecop.freeze do
116
+ Foo.new.bar
117
+
118
+ bc = subject.stored[0]
119
+ bc.timestamp.must_equal(Time.now.utc.to_i)
120
+ end
121
+ end
122
+
123
+ it "does not set the timestamp if it is already set" do
124
+ time = Time.now.utc
125
+
126
+ Timecop.freeze do
127
+ subject.record(message: 'test', timestamp: time)
128
+
129
+ subject.stored[0].timestamp.wont_equal(Time.now.utc)
130
+ end
131
+ end
132
+
133
+ it "sets the log level to :info if one is not supplied" do
134
+ Foo.new.bar
135
+
136
+ subject.stored[0].level.must_equal(:info)
137
+ end
138
+
139
+ it "does not record the breadcrumb if should_record? is false" do
140
+ subject.stubs(:should_record?).returns(false)
141
+ Foo.new.bar
142
+
143
+ subject.stored.length.must_equal(0)
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -1,6 +1,4 @@
1
- require "minitest/autorun"
2
- require "minitest/pride"
3
- require_relative "../../lib/raygun"
1
+ require_relative "../spec_helper"
4
2
 
5
3
  module Raygun
6
4
  module Services
@@ -0,0 +1,9 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+ require_relative "../lib/raygun.rb"
3
+ require "minitest/autorun"
4
+ require "minitest/pride"
5
+ require "fakeweb"
6
+ require "timecop"
7
+ require "mocha/mini_test"
8
+
9
+ alias :context :describe
data/test/test_helper.rb CHANGED
@@ -5,6 +5,25 @@ require "minitest/pride"
5
5
  require "fakeweb"
6
6
  require "timecop"
7
7
  require "mocha/mini_test"
8
+ require 'stringio'
9
+
10
+ class FakeLogger
11
+ def initialize
12
+ @logger = StringIO.new
13
+ end
14
+
15
+ def info(message)
16
+ @logger.write(message)
17
+ end
18
+
19
+ def reset
20
+ @logger.string = ""
21
+ end
22
+
23
+ def get
24
+ @logger.string
25
+ end
26
+ end
8
27
 
9
28
  class NoApiKey < StandardError; end
10
29
 
@@ -46,4 +65,11 @@ class Raygun::UnitTest < MiniTest::Unit::TestCase
46
65
  Raygun.configuration = Raygun::Configuration.new
47
66
  end
48
67
 
68
+ def setup_logging
69
+ logger = FakeLogger.new
70
+ Raygun.configuration.debug = true
71
+ Raygun.configuration.logger = logger
72
+
73
+ logger
74
+ end
49
75
  end
@@ -645,6 +645,17 @@ class ClientTest < Raygun::UnitTest
645
645
  assert_equal expected_details, user_details
646
646
  end
647
647
 
648
+ def test_build_payload_includes_breadcrumbs
649
+ ::Raygun::Breadcrumbs::Store.initialize
650
+ ::Raygun::Breadcrumbs::Store.record(message: "foo")
651
+
652
+ breadcrumbs = @client.send(:build_payload_hash, test_exception, sample_env_hash)[:details][:breadcrumbs]
653
+ ::Raygun::Breadcrumbs::Store.clear
654
+
655
+ assert_equal breadcrumbs.length, 1
656
+ assert breadcrumbs[0].is_a? Hash
657
+ end
658
+
648
659
  private
649
660
 
650
661
  def test_exception
@@ -130,6 +130,32 @@ class ConfigurationTest < Raygun::UnitTest
130
130
  assert_equal "https://api.raygun.io/", Raygun.configuration.api_url
131
131
  end
132
132
 
133
+ def test_setting_breadcrumb_level
134
+ Raygun.setup do |config|
135
+ config.breadcrumb_level = :info
136
+ end
137
+
138
+ assert_equal :info, Raygun.configuration.breadcrumb_level
139
+ end
140
+
141
+ def test_setting_breadcrumb_level_to_bad_value
142
+ logger = setup_logging
143
+
144
+ Raygun.setup do |config|
145
+ config.breadcrumb_level = :invalid
146
+ end
147
+
148
+ assert_equal :info, Raygun.configuration.breadcrumb_level
149
+ assert(
150
+ logger.get.include?("unknown breadcrumb level"),
151
+ "unknown breadcrumb level message was not logged"
152
+ )
153
+ end
154
+
155
+ def test_breadcrumb_level_default
156
+ assert_equal :info, Raygun.configuration.breadcrumb_level
157
+ end
158
+
133
159
  def test_record_raw_data_default
134
160
  assert_equal false, Raygun.configuration.record_raw_data
135
161
  end
@@ -1,24 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require_relative "../test_helper.rb"
3
- require 'stringio'
4
-
5
- class FakeLogger
6
- def initialize
7
- @logger = StringIO.new
8
- end
9
-
10
- def info(message)
11
- @logger.write(message)
12
- end
13
-
14
- def reset
15
- @logger.string = ""
16
- end
17
-
18
- def get
19
- @logger.string
20
- end
21
- end
22
3
 
23
4
  class RaygunTest < Raygun::UnitTest
24
5
  def test_raygun_is_not_configured_with_no_api_key
@@ -41,12 +22,4 @@ class RaygunTest < Raygun::UnitTest
41
22
 
42
23
  assert logger.get =~ /skipping reporting of.*Exception.*/, "ignored exception was not logged"
43
24
  end
44
-
45
- def setup_logging
46
- logger = FakeLogger.new
47
- Raygun.configuration.debug = true
48
- Raygun.configuration.logger = logger
49
-
50
- logger
51
- end
52
25
  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.0.0
4
+ version: 2.1.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-04-19 00:00:00.000000000 Z
12
+ date: 2017-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -217,9 +217,13 @@ files:
217
217
  - lib/generators/raygun/install_generator.rb
218
218
  - lib/raygun.rb
219
219
  - lib/raygun/affected_user.rb
220
+ - lib/raygun/breadcrumbs.rb
221
+ - lib/raygun/breadcrumbs/breadcrumb.rb
222
+ - lib/raygun/breadcrumbs/store.rb
220
223
  - lib/raygun/client.rb
221
224
  - lib/raygun/configuration.rb
222
225
  - lib/raygun/error.rb
226
+ - lib/raygun/middleware/breadcrumbs_store_initializer.rb
223
227
  - lib/raygun/middleware/rack_exception_interceptor.rb
224
228
  - lib/raygun/middleware/rails_insert_affected_user.rb
225
229
  - lib/raygun/railtie.rb
@@ -231,7 +235,10 @@ files:
231
235
  - lib/resque/failure/raygun.rb
232
236
  - lib/tasks/raygun.tasks
233
237
  - raygun4ruby.gemspec
238
+ - specs/raygun/breadcrumbs/breadcrumb_spec.rb
239
+ - specs/raygun/breadcrumbs/store_spec.rb
234
240
  - specs/services/apply_whitelist_filter_to_payload_spec.rb
241
+ - specs/spec_helper.rb
235
242
  - test/integration/client_test.rb
236
243
  - test/test_helper.rb
237
244
  - test/unit/affected_user_test.rb