ndr_error 2.0.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/app/controllers/ndr_error/application_controller.rb +0 -2
- data/app/models/ndr_error/fingerprint.rb +9 -8
- data/app/models/ndr_error/log.rb +2 -1
- data/lib/ndr_error/callbacks.rb +27 -0
- data/lib/ndr_error/engine.rb +9 -5
- data/lib/ndr_error/logging.rb +4 -2
- data/lib/ndr_error/middleware/public_exceptions.rb +3 -34
- data/lib/ndr_error/recorder.rb +45 -0
- data/lib/ndr_error/version.rb +1 -1
- data/lib/ndr_error.rb +4 -1
- metadata +24 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 905684f0ea130a6c5613e2df87f46d0e098fe6d16ebcc5647594318bc55cf4a1
|
4
|
+
data.tar.gz: cc8defe0ac32639a4b3b86d7756e6bdbd9fac7a8f0c1923ec2f4982cdfe5f076
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee098ccf9dab59e79c533139b754a41306c2cf7d0425098ffeb338dd770d16b53ebb7b818f4976b5c92235831205a8a6e18aa4c39c8c2fc01aab6c05cb120c98
|
7
|
+
data.tar.gz: f8fed40535c7289b0375393518bcca2017dd6f7dea525d4fdc9e22d185cf86f9f23ac5b25a98c60106e8489d2eec1b10399406097ad65586962ff8c49f9504dc
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# NdrError [![Build Status](https://
|
1
|
+
# NdrError [![Build Status](https://github.com/publichealthengland/ndr_error/workflows/Test/badge.svg)](https://github.com/publichealthengland/ndr_error/actions?query=workflow%3Atest) [![Gem Version](https://badge.fury.io/rb/ndr_error.svg)](https://rubygems.org/gems/ndr_error)
|
2
2
|
|
3
3
|
This is the Public Health England (PHE) National Disease Registers (NDR) Error ruby gem. It is a
|
4
4
|
Rails engine that provides error logging, viewing, and grouping capabilities.
|
@@ -38,6 +38,11 @@ a Rack application that can be used as part of the Rails exception-handling midd
|
|
38
38
|
|
39
39
|
In the host application's `application.rb`, the following configuration can be added:
|
40
40
|
|
41
|
+
To log the error, but have the host application's routing respond:
|
42
|
+
```ruby
|
43
|
+
config.exceptions_app = NdrError::Recorder.new(self.routes)
|
44
|
+
```
|
45
|
+
or log the error, then serve error templates from `public/` (legacy):
|
41
46
|
```ruby
|
42
47
|
require 'ndr_error/middleware/public_exceptions'
|
43
48
|
# Configure the ActionDispatch::ShowExceptions middleware to use NdrError's exception logger:
|
@@ -6,22 +6,23 @@ module NdrError
|
|
6
6
|
|
7
7
|
self.primary_key = 'error_fingerprintid'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
belongs_to :causal_error_fingerprint, belongs_to_options
|
9
|
+
belongs_to :causal_error_fingerprint,
|
10
|
+
class_name: 'NdrError::Fingerprint',
|
11
|
+
foreign_key: 'causal_error_fingerprintid',
|
12
|
+
inverse_of: :caused_error_fingerprints,
|
13
|
+
optional: true
|
15
14
|
|
16
15
|
has_many :caused_error_fingerprints,
|
17
16
|
class_name: 'NdrError::Fingerprint',
|
18
|
-
foreign_key: 'causal_error_fingerprintid'
|
17
|
+
foreign_key: 'causal_error_fingerprintid',
|
18
|
+
inverse_of: :causal_error_fingerprint
|
19
19
|
|
20
20
|
has_many :error_logs,
|
21
21
|
-> { latest_first },
|
22
22
|
autosave: true,
|
23
23
|
class_name: 'NdrError::Log',
|
24
|
-
foreign_key: 'error_fingerprintid'
|
24
|
+
foreign_key: 'error_fingerprintid',
|
25
|
+
inverse_of: :error_fingerprint
|
25
26
|
|
26
27
|
validate :ensure_ticket_url_matched_a_supplied_format
|
27
28
|
|
data/app/models/ndr_error/log.rb
CHANGED
@@ -15,7 +15,8 @@ module NdrError
|
|
15
15
|
|
16
16
|
belongs_to :error_fingerprint,
|
17
17
|
class_name: 'NdrError::Fingerprint',
|
18
|
-
foreign_key: 'error_fingerprintid'
|
18
|
+
foreign_key: 'error_fingerprintid',
|
19
|
+
inverse_of: :error_logs
|
19
20
|
|
20
21
|
scope :deleted, -> { where("status like 'deleted%'") }
|
21
22
|
scope :not_deleted, -> { where("(status is null) or (status not like 'deleted%')") }
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module NdrError
|
2
|
+
# contains logic for registering callbacks
|
3
|
+
module Callbacks
|
4
|
+
def self.extended(base)
|
5
|
+
base.mattr_accessor :_after_log_callbacks
|
6
|
+
base._after_log_callbacks = []
|
7
|
+
end
|
8
|
+
|
9
|
+
# Register callbacks that will be called after an exception
|
10
|
+
# has been logged.
|
11
|
+
#
|
12
|
+
# NdrError.after_log do |exception, fingerprint, log|
|
13
|
+
# # ...
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Multiple callbacks can be registered.
|
17
|
+
def after_log(&block)
|
18
|
+
_after_log_callbacks << block
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_after_log_callbacks(*args)
|
22
|
+
_after_log_callbacks.each do |callback|
|
23
|
+
callback.call(*args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/ndr_error/engine.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'active_support/all' # TODO: want duration
|
2
2
|
|
3
|
+
require 'ndr_ui/engine'
|
4
|
+
|
3
5
|
require 'will_paginate'
|
4
6
|
require 'will_paginate/array'
|
5
7
|
|
@@ -12,11 +14,13 @@ module NdrError
|
|
12
14
|
|
13
15
|
# Hook into host app's asset pipeline
|
14
16
|
initializer 'ndr_error.assets.precompile' do |app|
|
15
|
-
app.config.assets
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
if app.config.respond_to?(:assets)
|
18
|
+
app.config.assets.precompile += %w[
|
19
|
+
ndr_error/ndr_error.css
|
20
|
+
ndr_error/ndr_error.js
|
21
|
+
ndr_error/bootstrap/glyphicons-halflings-regular*
|
22
|
+
]
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
# Extract context filtering from the host application
|
data/lib/ndr_error/logging.rb
CHANGED
@@ -16,9 +16,11 @@ module NdrError
|
|
16
16
|
|
17
17
|
print = Fingerprint.find_or_create_by_id(log.md5_digest)
|
18
18
|
print.causal_error_fingerprint = parent_print
|
19
|
-
|
19
|
+
log = print.store_log(log)
|
20
20
|
|
21
|
-
|
21
|
+
NdrError.run_after_log_callbacks(exception, print, log)
|
22
|
+
|
23
|
+
[print, log]
|
22
24
|
end
|
23
25
|
|
24
26
|
def monitor(ancillary_data: {}, request: nil, swallow: false)
|
@@ -1,40 +1,9 @@
|
|
1
1
|
module NdrError
|
2
2
|
module Middleware
|
3
3
|
# Middleware for logging exceptions, can be used as exception_app for Rails.
|
4
|
-
class PublicExceptions < ::
|
5
|
-
def
|
6
|
-
|
7
|
-
request = ActionDispatch::Request.new(env)
|
8
|
-
exception = env['action_dispatch.exception']
|
9
|
-
|
10
|
-
# "falsey" callback return value allows logging to be skipped
|
11
|
-
log_exception(request, exception) if run_exception_callback(request, exception)
|
12
|
-
end
|
13
|
-
|
14
|
-
super # Invoke the PublicExceptions behaviour
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def log_exception(request, exception)
|
20
|
-
parameters = NdrError.log_parameters.call(request)
|
21
|
-
_fingerprint, _log = NdrError.log(exception, parameters, request)
|
22
|
-
end
|
23
|
-
|
24
|
-
def run_exception_callback(request, exception)
|
25
|
-
NdrError.exception_app_callback.call(request, exception)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Unhandled exceptions with logging could terminate the web server!
|
29
|
-
def rescuing_everything
|
30
|
-
yield
|
31
|
-
rescue Exception => exception # rubocop:disable Lint/RescueException
|
32
|
-
# "Log the exception caused by logging an exception..."
|
33
|
-
Rails.logger.warn <<-MSG.strip_heredoc
|
34
|
-
NdrError failed to log an exception!
|
35
|
-
logging error class: #{exception.class}
|
36
|
-
logging error message: #{exception.message}
|
37
|
-
MSG
|
4
|
+
class PublicExceptions < NdrError::Recorder
|
5
|
+
def initialize(public_path)
|
6
|
+
super ::ActionDispatch::PublicExceptions.new(public_path)
|
38
7
|
end
|
39
8
|
end
|
40
9
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module NdrError
|
2
|
+
# Middleware for logging exceptions, can be used as exception_app for Rails.
|
3
|
+
class Recorder
|
4
|
+
# the parent_handler could be the host app's routes, or an instance
|
5
|
+
# of ActionDispatch::PublicExceptions, or any other middleware.
|
6
|
+
def initialize(parent_handler)
|
7
|
+
@parent_handler = parent_handler
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
rescuing_everything do
|
12
|
+
request = ActionDispatch::Request.new(env)
|
13
|
+
exception = env['action_dispatch.exception']
|
14
|
+
|
15
|
+
# "falsey" callback return value allows logging to be skipped
|
16
|
+
log_exception(request, exception) if run_exception_callback(request, exception)
|
17
|
+
end
|
18
|
+
|
19
|
+
@parent_handler.call(env)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def log_exception(request, exception)
|
25
|
+
parameters = NdrError.log_parameters.call(request)
|
26
|
+
_fingerprint, _log = NdrError.log(exception, parameters, request)
|
27
|
+
end
|
28
|
+
|
29
|
+
def run_exception_callback(request, exception)
|
30
|
+
NdrError.exception_app_callback.call(request, exception)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Unhandled exceptions with logging could terminate the web server!
|
34
|
+
def rescuing_everything
|
35
|
+
yield
|
36
|
+
rescue Exception => exception # rubocop:disable Lint/RescueException
|
37
|
+
# "Log the exception caused by logging an exception..."
|
38
|
+
Rails.logger.warn <<-MSG.strip_heredoc
|
39
|
+
NdrError failed to log an exception!
|
40
|
+
logging error class: #{exception.class}
|
41
|
+
logging error message: #{exception.message}
|
42
|
+
MSG
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/ndr_error/version.rb
CHANGED
data/lib/ndr_error.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'ndr_error/engine'
|
2
|
+
require 'ndr_error/recorder'
|
2
3
|
|
3
4
|
require 'ndr_error/backtrace_compression'
|
5
|
+
require 'ndr_error/callbacks'
|
4
6
|
require 'ndr_error/finder'
|
5
7
|
require 'ndr_error/fuzzing'
|
6
8
|
require 'ndr_error/logging'
|
@@ -8,6 +10,7 @@ require 'ndr_error/uuid_builder'
|
|
8
10
|
|
9
11
|
# Configuration for NdrError + convienence methods.
|
10
12
|
module NdrError
|
13
|
+
extend Callbacks
|
11
14
|
extend Finder
|
12
15
|
extend Logging
|
13
16
|
|
@@ -95,6 +98,6 @@ module NdrError
|
|
95
98
|
# 4.2 compatability layer is targetted since all the bundled migrations were written prior to
|
96
99
|
# Rails 5.
|
97
100
|
def self.migration_class
|
98
|
-
|
101
|
+
ActiveRecord::Migration[4.2]
|
99
102
|
end
|
100
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ndr_error
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NCRS Development Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '7'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '7'
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: puma
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: sqlite3
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,22 +146,16 @@ dependencies:
|
|
132
146
|
name: ndr_dev_support
|
133
147
|
requirement: !ruby/object:Gem::Requirement
|
134
148
|
requirements:
|
135
|
-
- - "~>"
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
version: '3.1'
|
138
149
|
- - ">="
|
139
150
|
- !ruby/object:Gem::Version
|
140
|
-
version:
|
151
|
+
version: '5.10'
|
141
152
|
type: :development
|
142
153
|
prerelease: false
|
143
154
|
version_requirements: !ruby/object:Gem::Requirement
|
144
155
|
requirements:
|
145
|
-
- - "~>"
|
146
|
-
- !ruby/object:Gem::Version
|
147
|
-
version: '3.1'
|
148
156
|
- - ">="
|
149
157
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
158
|
+
version: '5.10'
|
151
159
|
- !ruby/object:Gem::Dependency
|
152
160
|
name: simplecov
|
153
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -189,11 +197,13 @@ files:
|
|
189
197
|
- db/migrate/20180203174345_add_cause_to_error_fingerprints.rb
|
190
198
|
- lib/ndr_error.rb
|
191
199
|
- lib/ndr_error/backtrace_compression.rb
|
200
|
+
- lib/ndr_error/callbacks.rb
|
192
201
|
- lib/ndr_error/engine.rb
|
193
202
|
- lib/ndr_error/finder.rb
|
194
203
|
- lib/ndr_error/fuzzing.rb
|
195
204
|
- lib/ndr_error/logging.rb
|
196
205
|
- lib/ndr_error/middleware/public_exceptions.rb
|
206
|
+
- lib/ndr_error/recorder.rb
|
197
207
|
- lib/ndr_error/uuid_builder.rb
|
198
208
|
- lib/ndr_error/version.rb
|
199
209
|
- lib/tasks/ndr_error_tasks.rake
|
@@ -209,14 +219,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
219
|
requirements:
|
210
220
|
- - ">="
|
211
221
|
- !ruby/object:Gem::Version
|
212
|
-
version: '2.
|
222
|
+
version: '2.6'
|
213
223
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
224
|
requirements:
|
215
225
|
- - ">="
|
216
226
|
- !ruby/object:Gem::Version
|
217
227
|
version: '0'
|
218
228
|
requirements: []
|
219
|
-
rubygems_version: 3.
|
229
|
+
rubygems_version: 3.1.6
|
220
230
|
signing_key:
|
221
231
|
specification_version: 4
|
222
232
|
summary: Rails exception logging
|