raygun4ruby 3.2.3 → 3.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +18 -18
  3. data/.rspec +1 -1
  4. data/.travis.yml +20 -20
  5. data/CHANGELOG.md +127 -124
  6. data/Gemfile +4 -4
  7. data/LICENSE.txt +22 -22
  8. data/README.md +420 -420
  9. data/Rakefile +27 -27
  10. data/examples/sinatras_raygun.rb +17 -17
  11. data/lib/generators/raygun/install_generator.rb +26 -26
  12. data/lib/raygun.rb +179 -179
  13. data/lib/raygun/affected_user.rb +59 -59
  14. data/lib/raygun/breadcrumbs.rb +34 -34
  15. data/lib/raygun/breadcrumbs/breadcrumb.rb +34 -34
  16. data/lib/raygun/breadcrumbs/store.rb +86 -86
  17. data/lib/raygun/client.rb +305 -305
  18. data/lib/raygun/configuration.rb +194 -194
  19. data/lib/raygun/error.rb +10 -10
  20. data/lib/raygun/javascript_tracker.rb +42 -42
  21. data/lib/raygun/middleware/breadcrumbs_store_initializer.rb +19 -19
  22. data/lib/raygun/middleware/javascript_exception_tracking.rb +32 -32
  23. data/lib/raygun/middleware/rack_exception_interceptor.rb +18 -18
  24. data/lib/raygun/middleware/rails_insert_affected_user.rb +26 -26
  25. data/lib/raygun/railtie.rb +39 -39
  26. data/lib/raygun/services/apply_whitelist_filter_to_payload.rb +27 -27
  27. data/lib/raygun/sidekiq.rb +71 -70
  28. data/lib/raygun/testable.rb +22 -22
  29. data/lib/raygun/version.rb +3 -3
  30. data/lib/raygun4ruby.rb +1 -1
  31. data/lib/resque/failure/raygun.rb +25 -25
  32. data/lib/tasks/raygun.tasks +7 -7
  33. data/raygun4ruby.gemspec +45 -45
  34. data/spec/dummy/.gitignore +17 -17
  35. data/spec/dummy/Gemfile +47 -47
  36. data/spec/dummy/README.rdoc +28 -28
  37. data/spec/dummy/Rakefile +6 -6
  38. data/spec/dummy/app/assets/config/manifest.js +2 -2
  39. data/spec/dummy/app/assets/javascripts/application.js +13 -13
  40. data/spec/dummy/app/assets/stylesheets/application.css +15 -15
  41. data/spec/dummy/app/controllers/application_controller.rb +5 -5
  42. data/spec/dummy/app/controllers/home_controller.rb +4 -4
  43. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  44. data/spec/dummy/app/views/home/index.html.erb +3 -3
  45. data/spec/dummy/app/views/home/index.json.erb +1 -1
  46. data/spec/dummy/app/views/layouts/application.html.erb +14 -14
  47. data/spec/dummy/bin/bundle +3 -3
  48. data/spec/dummy/bin/rails +9 -9
  49. data/spec/dummy/bin/rake +9 -9
  50. data/spec/dummy/bin/setup +29 -29
  51. data/spec/dummy/bin/spring +17 -17
  52. data/spec/dummy/config.ru +4 -4
  53. data/spec/dummy/config/application.rb +26 -26
  54. data/spec/dummy/config/boot.rb +3 -3
  55. data/spec/dummy/config/database.yml +25 -25
  56. data/spec/dummy/config/environment.rb +5 -5
  57. data/spec/dummy/config/environments/development.rb +41 -41
  58. data/spec/dummy/config/environments/production.rb +79 -79
  59. data/spec/dummy/config/environments/test.rb +42 -42
  60. data/spec/dummy/config/initializers/assets.rb +11 -11
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  62. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -3
  63. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
  64. data/spec/dummy/config/initializers/inflections.rb +16 -16
  65. data/spec/dummy/config/initializers/mime_types.rb +4 -4
  66. data/spec/dummy/config/initializers/session_store.rb +3 -3
  67. data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +10 -10
  68. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  69. data/spec/dummy/config/locales/en.yml +23 -23
  70. data/spec/dummy/config/routes.rb +58 -58
  71. data/spec/dummy/config/secrets.yml +22 -22
  72. data/spec/dummy/db/seeds.rb +7 -7
  73. data/spec/dummy/public/404.html +67 -67
  74. data/spec/dummy/public/422.html +67 -67
  75. data/spec/dummy/public/500.html +66 -66
  76. data/spec/dummy/public/robots.txt +5 -5
  77. data/spec/dummy/test/test_helper.rb +10 -10
  78. data/spec/features/javascript_spec.rb +48 -48
  79. data/spec/rails_helper.rb +4 -4
  80. data/spec/raygun/breadcrumbs/breadcrumb_spec.rb +171 -171
  81. data/spec/raygun/breadcrumbs/store_spec.rb +170 -170
  82. data/spec/raygun/raygun_spec.rb +47 -47
  83. data/spec/services/apply_whitelist_filter_to_payload_spec.rb +251 -251
  84. data/spec/spec_helper.rb +24 -24
  85. data/spec/support/fake_logger.rb +17 -17
  86. data/test/integration/client_test.rb +19 -19
  87. data/test/test_helper.rb +72 -72
  88. data/test/unit/affected_user_test.rb +136 -136
  89. data/test/unit/client_test.rb +792 -792
  90. data/test/unit/configuration_test.rb +206 -206
  91. data/test/unit/raygun_test.rb +25 -25
  92. data/test/unit/resque_failure_test.rb +24 -24
  93. data/test/unit/sidekiq_failure_test.rb +32 -32
  94. metadata +7 -7
@@ -1,194 +1,194 @@
1
- module Raygun
2
- class Configuration
3
-
4
- def self.config_option(name)
5
- define_method(name) do
6
- read_value(name)
7
- end
8
-
9
- define_method("#{name}=") do |value|
10
- set_value(name, value)
11
- end
12
- end
13
-
14
- def self.proc_config_option(name)
15
- define_method(name) do |&block|
16
- set_value(name, block) unless block == nil
17
- read_value(name)
18
- end
19
-
20
- define_method("#{name}=") do |value|
21
- set_value(name, value)
22
- end
23
- end
24
-
25
- # Your Raygun API Key - this can be found on your dashboard at Raygun.io
26
- config_option :api_key
27
-
28
- # Your JS Raygun API Key - Should be different to your api_key, it's best practice to separate your errors between front end and back end.
29
- config_option :js_api_key
30
-
31
- # Your JS Raygun API Version, defaults to latest as found on https://raygun.com/raygun-providers/javascript
32
- config_option :js_api_version
33
-
34
- # Array of exception classes to ignore
35
- config_option :ignore
36
-
37
- # Version to use
38
- config_option :version
39
-
40
- # Custom Data to send with each exception
41
- proc_config_option :custom_data
42
-
43
- # Tags to send with each exception
44
- proc_config_option :tags
45
-
46
- # Logger to use when we find an exception :)
47
- config_option :logger
48
-
49
- # Should we actually report exceptions to Raygun? (Usually disabled in Development mode, for instance)
50
- config_option :enable_reporting
51
-
52
- # Failsafe logger (for exceptions that happen when we're attempting to report exceptions)
53
- config_option :failsafe_logger
54
-
55
- # Which controller method should we call to find out the affected user?
56
- config_option :affected_user_method
57
-
58
- # Mapping of methods for the affected user object - which methods should we call for user information
59
- config_option :affected_user_mapping
60
-
61
- # Which parameter keys should we filter out by default?
62
- proc_config_option :filter_parameters
63
-
64
- # Should we switch to a white listing mode for keys instead of the default blacklist?
65
- config_option :filter_payload_with_whitelist
66
-
67
- # If :filter_payload_with_whitelist is true, which keys should we whitelist?
68
- proc_config_option :whitelist_payload_shape
69
-
70
- # Hash of proxy settings - :address, :port (defaults to 80), :username and :password (both default to nil)
71
- config_option :proxy_settings
72
-
73
- # Set this to true to have raygun4ruby log the reason why it skips reporting an exception
74
- config_option :debug
75
-
76
- # Override this if you wish to connect to a different Raygun API than the standard one
77
- config_option :api_url
78
-
79
- # Should Raygun include the raw request body in the payload? This will not include
80
- # form submissions and will not be filtered by the blacklist
81
- config_option :record_raw_data
82
-
83
- # Should the exceptions to Raygun be sent asynchronously?
84
- config_option :send_in_background
85
-
86
- # How long to wait for the POST request to the API server before timing out
87
- config_option :error_report_send_timeout
88
-
89
- # Exception classes to ignore by default
90
- IGNORE_DEFAULT = ['ActiveRecord::RecordNotFound',
91
- 'ActionController::RoutingError',
92
- 'ActionController::InvalidAuthenticityToken',
93
- 'ActionDispatch::ParamsParser::ParseError',
94
- 'CGI::Session::CookieStore::TamperedWithCookie',
95
- 'ActionController::UnknownAction',
96
- 'AbstractController::ActionNotFound',
97
- 'Mongoid::Errors::DocumentNotFound']
98
-
99
- DEFAULT_FILTER_PARAMETERS = [ :password, :card_number, :cvv ]
100
-
101
- DEFAULT_WHITELIST_PAYLOAD_SHAPE_REQUEST = {
102
- hostName: true,
103
- url: true,
104
- httpMethod: true,
105
- iPAddress: true,
106
- queryString: true,
107
- headers: true,
108
- form: {}, # Set to empty hash so that it doesn't just filter out the whole thing, but instead filters out each individual param
109
- rawData: true
110
- }.freeze
111
- DEFAULT_WHITELIST_PAYLOAD_SHAPE = {
112
- machineName: true,
113
- version: true,
114
- error: true,
115
- userCustomData: true,
116
- tags: true,
117
- request: DEFAULT_WHITELIST_PAYLOAD_SHAPE_REQUEST
118
- }.freeze
119
-
120
- attr_reader :defaults
121
-
122
- def initialize
123
- @config_values = {}
124
-
125
- # set default attribute values
126
- @defaults = OpenStruct.new(
127
- ignore: IGNORE_DEFAULT,
128
- custom_data: {},
129
- tags: [],
130
- enable_reporting: true,
131
- affected_user_method: :current_user,
132
- affected_user_mapping: AffectedUser::DEFAULT_MAPPING,
133
- filter_parameters: DEFAULT_FILTER_PARAMETERS,
134
- filter_payload_with_whitelist: false,
135
- whitelist_payload_shape: DEFAULT_WHITELIST_PAYLOAD_SHAPE,
136
- proxy_settings: {},
137
- debug: false,
138
- api_url: 'https://api.raygun.io/',
139
- breadcrumb_level: :info,
140
- record_raw_data: false,
141
- send_in_background: false,
142
- error_report_send_timeout: 10
143
- )
144
- end
145
-
146
- def [](key)
147
- read_value(key)
148
- end
149
-
150
- def []=(key, value)
151
- set_value(key, value)
152
- end
153
-
154
- def silence_reporting
155
- !enable_reporting
156
- end
157
-
158
- def silence_reporting=(value)
159
- self.enable_reporting = !value
160
- end
161
-
162
- def breadcrumb_level
163
- read_value(:breadcrumb_level)
164
- end
165
-
166
- def breadcrumb_level=(value)
167
- if Raygun::Breadcrumbs::BREADCRUMB_LEVELS.include?(value)
168
- set_value(:breadcrumb_level, value)
169
- elsif read_value(:debug)
170
- Raygun.log("[Raygun.configuration] unknown breadcrumb level: #{value} not setting")
171
- end
172
- end
173
-
174
- def affected_user_identifier_methods
175
- Raygun.deprecation_warning("Please note: You should now user config.affected_user_method_mapping.Identifier instead of config.affected_user_identifier_methods")
176
- read_value(:affected_user_mapping)[:identifier]
177
- end
178
-
179
- private
180
-
181
- def read_value(name)
182
- if @config_values.has_key?(name)
183
- @config_values[name]
184
- else
185
- @defaults.send(name)
186
- end
187
- end
188
-
189
- def set_value(name, value)
190
- @config_values[name] = value
191
- end
192
-
193
- end
194
- end
1
+ module Raygun
2
+ class Configuration
3
+
4
+ def self.config_option(name)
5
+ define_method(name) do
6
+ read_value(name)
7
+ end
8
+
9
+ define_method("#{name}=") do |value|
10
+ set_value(name, value)
11
+ end
12
+ end
13
+
14
+ def self.proc_config_option(name)
15
+ define_method(name) do |&block|
16
+ set_value(name, block) unless block == nil
17
+ read_value(name)
18
+ end
19
+
20
+ define_method("#{name}=") do |value|
21
+ set_value(name, value)
22
+ end
23
+ end
24
+
25
+ # Your Raygun API Key - this can be found on your dashboard at https://app.raygun.com
26
+ config_option :api_key
27
+
28
+ # Your JS Raygun API Key - Should be different to your api_key, it's best practice to separate your errors between front end and back end.
29
+ config_option :js_api_key
30
+
31
+ # Your JS Raygun API Version, defaults to latest as found on https://raygun.com/documentation/language-guides/javascript/crash-reporting/installation/
32
+ config_option :js_api_version
33
+
34
+ # Array of exception classes to ignore
35
+ config_option :ignore
36
+
37
+ # Version to use
38
+ config_option :version
39
+
40
+ # Custom Data to send with each exception
41
+ proc_config_option :custom_data
42
+
43
+ # Tags to send with each exception
44
+ proc_config_option :tags
45
+
46
+ # Logger to use when we find an exception :)
47
+ config_option :logger
48
+
49
+ # Should we actually report exceptions to Raygun? (Usually disabled in Development mode, for instance)
50
+ config_option :enable_reporting
51
+
52
+ # Failsafe logger (for exceptions that happen when we're attempting to report exceptions)
53
+ config_option :failsafe_logger
54
+
55
+ # Which controller method should we call to find out the affected user?
56
+ config_option :affected_user_method
57
+
58
+ # Mapping of methods for the affected user object - which methods should we call for user information
59
+ config_option :affected_user_mapping
60
+
61
+ # Which parameter keys should we filter out by default?
62
+ proc_config_option :filter_parameters
63
+
64
+ # Should we switch to a white listing mode for keys instead of the default blacklist?
65
+ config_option :filter_payload_with_whitelist
66
+
67
+ # If :filter_payload_with_whitelist is true, which keys should we whitelist?
68
+ proc_config_option :whitelist_payload_shape
69
+
70
+ # Hash of proxy settings - :address, :port (defaults to 80), :username and :password (both default to nil)
71
+ config_option :proxy_settings
72
+
73
+ # Set this to true to have raygun4ruby log the reason why it skips reporting an exception
74
+ config_option :debug
75
+
76
+ # Override this if you wish to connect to a different Raygun API than the standard one
77
+ config_option :api_url
78
+
79
+ # Should Raygun include the raw request body in the payload? This will not include
80
+ # form submissions and will not be filtered by the blacklist
81
+ config_option :record_raw_data
82
+
83
+ # Should the exceptions to Raygun be sent asynchronously?
84
+ config_option :send_in_background
85
+
86
+ # How long to wait for the POST request to the API server before timing out
87
+ config_option :error_report_send_timeout
88
+
89
+ # Exception classes to ignore by default
90
+ IGNORE_DEFAULT = ['ActiveRecord::RecordNotFound',
91
+ 'ActionController::RoutingError',
92
+ 'ActionController::InvalidAuthenticityToken',
93
+ 'ActionDispatch::ParamsParser::ParseError',
94
+ 'CGI::Session::CookieStore::TamperedWithCookie',
95
+ 'ActionController::UnknownAction',
96
+ 'AbstractController::ActionNotFound',
97
+ 'Mongoid::Errors::DocumentNotFound']
98
+
99
+ DEFAULT_FILTER_PARAMETERS = [ :password, :card_number, :cvv ]
100
+
101
+ DEFAULT_WHITELIST_PAYLOAD_SHAPE_REQUEST = {
102
+ hostName: true,
103
+ url: true,
104
+ httpMethod: true,
105
+ iPAddress: true,
106
+ queryString: true,
107
+ headers: true,
108
+ form: {}, # Set to empty hash so that it doesn't just filter out the whole thing, but instead filters out each individual param
109
+ rawData: true
110
+ }.freeze
111
+ DEFAULT_WHITELIST_PAYLOAD_SHAPE = {
112
+ machineName: true,
113
+ version: true,
114
+ error: true,
115
+ userCustomData: true,
116
+ tags: true,
117
+ request: DEFAULT_WHITELIST_PAYLOAD_SHAPE_REQUEST
118
+ }.freeze
119
+
120
+ attr_reader :defaults
121
+
122
+ def initialize
123
+ @config_values = {}
124
+
125
+ # set default attribute values
126
+ @defaults = OpenStruct.new(
127
+ ignore: IGNORE_DEFAULT,
128
+ custom_data: {},
129
+ tags: [],
130
+ enable_reporting: true,
131
+ affected_user_method: :current_user,
132
+ affected_user_mapping: AffectedUser::DEFAULT_MAPPING,
133
+ filter_parameters: DEFAULT_FILTER_PARAMETERS,
134
+ filter_payload_with_whitelist: false,
135
+ whitelist_payload_shape: DEFAULT_WHITELIST_PAYLOAD_SHAPE,
136
+ proxy_settings: {},
137
+ debug: false,
138
+ api_url: 'https://api.raygun.com/',
139
+ breadcrumb_level: :info,
140
+ record_raw_data: false,
141
+ send_in_background: false,
142
+ error_report_send_timeout: 10
143
+ )
144
+ end
145
+
146
+ def [](key)
147
+ read_value(key)
148
+ end
149
+
150
+ def []=(key, value)
151
+ set_value(key, value)
152
+ end
153
+
154
+ def silence_reporting
155
+ !enable_reporting
156
+ end
157
+
158
+ def silence_reporting=(value)
159
+ self.enable_reporting = !value
160
+ end
161
+
162
+ def breadcrumb_level
163
+ read_value(:breadcrumb_level)
164
+ end
165
+
166
+ def breadcrumb_level=(value)
167
+ if Raygun::Breadcrumbs::BREADCRUMB_LEVELS.include?(value)
168
+ set_value(:breadcrumb_level, value)
169
+ elsif read_value(:debug)
170
+ Raygun.log("[Raygun.configuration] unknown breadcrumb level: #{value} not setting")
171
+ end
172
+ end
173
+
174
+ def affected_user_identifier_methods
175
+ Raygun.deprecation_warning("Please note: You should now user config.affected_user_method_mapping.Identifier instead of config.affected_user_identifier_methods")
176
+ read_value(:affected_user_mapping)[:identifier]
177
+ end
178
+
179
+ private
180
+
181
+ def read_value(name)
182
+ if @config_values.has_key?(name)
183
+ @config_values[name]
184
+ else
185
+ @defaults.send(name)
186
+ end
187
+ end
188
+
189
+ def set_value(name, value)
190
+ @config_values[name] = value
191
+ end
192
+
193
+ end
194
+ end
data/lib/raygun/error.rb CHANGED
@@ -1,10 +1,10 @@
1
- module Raygun
2
- class Error < StandardError
3
- attr_reader :raygun_custom_data
4
-
5
- def initialize(message, raygun_custom_data = {})
6
- super(message)
7
- @raygun_custom_data = raygun_custom_data
8
- end
9
- end
10
- end
1
+ module Raygun
2
+ class Error < StandardError
3
+ attr_reader :raygun_custom_data
4
+
5
+ def initialize(message, raygun_custom_data = {})
6
+ super(message)
7
+ @raygun_custom_data = raygun_custom_data
8
+ end
9
+ end
10
+ end
@@ -1,42 +1,42 @@
1
- # Client for injecting JavaScript code for tracking front end exceptions
2
- # https://raygun.com/docs/languages/javascript
3
- module Raygun
4
- class JavaScriptTracker
5
- def head_html
6
- return unless js_api_key?
7
- [
8
- '<script type="text/javascript">',
9
- '!function(a,b,c,d,e,f,g,h){a.RaygunObject=e,a[e]=a[e]||function(){',
10
- '(a[e].o=a[e].o||[]).push(arguments)},f=b.createElement(c),g=b.getElementsByTagName(c)[0],',
11
- 'f.async=1,f.src=d,g.parentNode.insertBefore(f,g),h=a.onerror,a.onerror=function(b,c,d,f,g){',
12
- 'h&&h(b,c,d,f,g),g||(g=new Error(b)),a[e].q=a[e].q||[],a[e].q.push({',
13
- 'e:g})}}(window,document,"script","//cdn.raygun.io/raygun4js/' + js_api_version + 'raygun.min.js","rg4js");',
14
- '</script>'
15
- ].join('').html_safe
16
- end
17
-
18
- def body_html
19
- return unless js_api_key?
20
- [
21
- '<script type="text/javascript">',
22
- "rg4js('apiKey', '#{js_api_key}');",
23
- "rg4js('enableCrashReporting', true);",
24
- '</script>'
25
- ].join('').html_safe
26
- end
27
-
28
- private
29
-
30
- def js_api_key
31
- @js_api_key ||= Raygun.configuration.js_api_key
32
- end
33
-
34
- def js_api_version
35
- @js_api_version ||= Raygun.configuration.js_api_version ? "#{Raygun.configuration.js_api_version}/" : ''
36
- end
37
-
38
- def js_api_key?
39
- js_api_key.present?
40
- end
41
- end
42
- end
1
+ # Client for injecting JavaScript code for tracking front end exceptions
2
+ # https://raygun.com/docs/languages/javascript
3
+ module Raygun
4
+ class JavaScriptTracker
5
+ def head_html
6
+ return unless js_api_key?
7
+ [
8
+ '<script type="text/javascript">',
9
+ '!function(a,b,c,d,e,f,g,h){a.RaygunObject=e,a[e]=a[e]||function(){',
10
+ '(a[e].o=a[e].o||[]).push(arguments)},f=b.createElement(c),g=b.getElementsByTagName(c)[0],',
11
+ 'f.async=1,f.src=d,g.parentNode.insertBefore(f,g),h=a.onerror,a.onerror=function(b,c,d,f,g){',
12
+ 'h&&h(b,c,d,f,g),g||(g=new Error(b)),a[e].q=a[e].q||[],a[e].q.push({',
13
+ 'e:g})}}(window,document,"script","//cdn.raygun.io/raygun4js/' + js_api_version + 'raygun.min.js","rg4js");',
14
+ '</script>'
15
+ ].join('').html_safe
16
+ end
17
+
18
+ def body_html
19
+ return unless js_api_key?
20
+ [
21
+ '<script type="text/javascript">',
22
+ "rg4js('apiKey', '#{js_api_key}');",
23
+ "rg4js('enableCrashReporting', true);",
24
+ '</script>'
25
+ ].join('').html_safe
26
+ end
27
+
28
+ private
29
+
30
+ def js_api_key
31
+ @js_api_key ||= Raygun.configuration.js_api_key
32
+ end
33
+
34
+ def js_api_version
35
+ @js_api_version ||= Raygun.configuration.js_api_version ? "#{Raygun.configuration.js_api_version}/" : ''
36
+ end
37
+
38
+ def js_api_key?
39
+ js_api_key.present?
40
+ end
41
+ end
42
+ end