dry-monitor 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +90 -23
- data/LICENSE +1 -1
- data/README.md +17 -13
- data/dry-monitor.gemspec +37 -24
- data/lib/dry/monitor/constants.rb +9 -0
- data/lib/dry/monitor/logger.rb +8 -4
- data/lib/dry/monitor/notifications.rb +8 -9
- data/lib/dry/monitor/rack/logger.rb +43 -53
- data/lib/dry/monitor/rack/middleware.rb +5 -5
- data/lib/dry/monitor/sql/colorizers/default.rb +3 -2
- data/lib/dry/monitor/sql/colorizers/rouge.rb +12 -11
- data/lib/dry/monitor/sql/logger.rb +24 -18
- data/lib/dry/monitor/version.rb +3 -1
- data/lib/dry/monitor.rb +8 -6
- data/lib/dry-monitor.rb +3 -1
- metadata +44 -62
- data/.gitignore +0 -9
- data/.rspec +0 -3
- data/.rubocop.yml +0 -16
- data/.rubocop_todo.yml +0 -7
- data/.travis.yml +0 -30
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -14
- data/Rakefile +0 -15
- data/rakelib/rubocop.rake +0 -18
- data/spec/integration/instrumentation_spec.rb +0 -37
- data/spec/integration/logger_spec.rb +0 -11
- data/spec/integration/rack_middleware_spec.rb +0 -98
- data/spec/integration/sql_logger_spec.rb +0 -58
- data/spec/spec_helper.rb +0 -22
- data/spec/test_logs/.gitkeep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 973eacb62c325645cdf9f3b01b5c39512e4b8f461b99ffcd7993edbd0d6e813f
|
4
|
+
data.tar.gz: 3b7687f24f0a6498516a7fe5e9a36c4c1b4bb988a64e708a9bf5b4f2c52a17ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8feea8bd4a5b2a38ab32b1565620b8e4c6696c5960e2abbcf4c4b9875a183a9fbef76361e794aeb17a18e41781669988f41367b6cdf3eb49d5ad8761ea71da17
|
7
|
+
data.tar.gz: 80bf24f9be77459e782a417c9e8ca4a106ab4e07e0ef1b89174bab41205d13658723736064bcdc0cdbe60b3a50277b20b38bd037632a37845a147bda3bb14e98
|
data/CHANGELOG.md
CHANGED
@@ -1,62 +1,129 @@
|
|
1
|
-
|
1
|
+
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
|
+
|
3
|
+
## 0.5.0 2021-09-12
|
4
|
+
|
5
|
+
|
6
|
+
### Changed
|
7
|
+
|
8
|
+
- [internal] Upgraded to new `setting` API provided in dry-configurable 0.13.0 (@timriley in #43)
|
9
|
+
|
10
|
+
[Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-monitor/compare/v0.4.0...v0.5.0)
|
11
|
+
|
12
|
+
## 0.4.0 2021-04-09
|
13
|
+
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
|
17
|
+
- Compatibility with MRI 3.0 (@alex-damian-negru)
|
18
|
+
|
19
|
+
|
20
|
+
[Compare v0.3.2...v0.4.0](https://github.com/dry-rb/dry-monitor/compare/v0.3.2...v0.4.0)
|
21
|
+
|
22
|
+
## 0.3.2 2020-04-09
|
23
|
+
|
24
|
+
|
25
|
+
### Fixed
|
26
|
+
|
27
|
+
- Ensure `Dry::Monitor::Rack::Middleware` is compatible with `Rack::Builder#use` (@jodosha)
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
|
31
|
+
- Performance improvements (@davydovanton)
|
32
|
+
|
33
|
+
[Compare v0.3.1...v0.3.2](https://github.com/dry-rb/dry-monitor/compare/v0.3.1...v0.3.2)
|
34
|
+
|
35
|
+
## 0.3.1 2019-06-18
|
36
|
+
|
37
|
+
|
38
|
+
### Fixed
|
39
|
+
|
40
|
+
- Uninitialized constant `Dry::Monitor::Notifications::EMPTY_HASH` when no payload given (@mensfeld)
|
41
|
+
|
42
|
+
|
43
|
+
[Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-monitor/compare/v0.3.0...v0.3.1)
|
44
|
+
|
45
|
+
## 0.3.0 2019-01-29
|
46
|
+
|
2
47
|
|
3
48
|
### Fixed
|
4
49
|
|
5
|
-
|
50
|
+
- cannot load such file -- rack/utils (mensfeld)
|
6
51
|
|
7
52
|
### Changed
|
8
53
|
|
9
|
-
|
10
|
-
|
54
|
+
- Make `rack` logger into a plugin (mensfeld)
|
55
|
+
- Make `sql` logger into a plugin (mensfeld)
|
56
|
+
|
57
|
+
[Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-monitor/compare/v0.2.0...v0.3.0)
|
58
|
+
|
59
|
+
## 0.2.0 2018-01-21
|
11
60
|
|
12
|
-
# v0.2.0 2018-01-21
|
13
61
|
|
14
62
|
### Changed
|
15
63
|
|
16
|
-
|
64
|
+
- Make `rouge` an optional dependency (davydovanton & mensfeld)
|
65
|
+
|
66
|
+
[Compare v0.1.2...v0.2.0](https://github.com/dry-rb/dry-monitor/compare/v0.1.2...v0.2.0)
|
67
|
+
|
68
|
+
## 0.1.2 2018-01-04
|
17
69
|
|
18
|
-
# v0.1.2 2018-01-04
|
19
70
|
|
20
71
|
### Fixed
|
21
72
|
|
22
|
-
|
73
|
+
- Rack logger no longer prevents arbitrary payload in `:error` events (solnic)
|
74
|
+
|
75
|
+
|
76
|
+
[Compare v0.1.1...v0.1.2](https://github.com/dry-rb/dry-monitor/compare/v0.1.1...v0.1.2)
|
77
|
+
|
78
|
+
## 0.1.1 2018-01-03
|
23
79
|
|
24
|
-
# v0.1.1 2018-01-03
|
25
80
|
|
26
81
|
### Fixed
|
27
82
|
|
28
|
-
|
83
|
+
- Query params containing arrays of primitives (e.g. `?ids[]=1&ids[]=2`) no longer crash the logger (timriley)
|
84
|
+
|
85
|
+
|
86
|
+
[Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-monitor/compare/v0.1.0...v0.1.1)
|
87
|
+
|
88
|
+
## 0.1.0 2018-01-02
|
29
89
|
|
30
|
-
# v0.1.0 2018-01-02
|
31
90
|
|
32
91
|
### Fixed
|
33
92
|
|
34
|
-
|
93
|
+
- Query params are logged correctly via rack middleware (solnic)
|
35
94
|
|
36
95
|
### Changed
|
37
96
|
|
38
|
-
|
97
|
+
- Uses `dry-events` for notifications (solnic)
|
98
|
+
|
99
|
+
[Compare v0.0.3...v0.1.0](https://github.com/dry-rb/dry-monitor/compare/v0.0.3...v0.1.0)
|
100
|
+
|
101
|
+
## 0.0.3 2017-08-28
|
39
102
|
|
40
|
-
# v0.0.3 2017-08-28
|
41
103
|
|
42
104
|
### Changed
|
43
105
|
|
44
|
-
|
45
|
-
|
106
|
+
- Update default theme setting for compatibility with latest version of rouge (alexandru-calinoiu)
|
107
|
+
- Require latest version of rouge gem (timriley)
|
108
|
+
|
109
|
+
[Compare v0.0.2...v0.0.3](https://github.com/dry-rb/dry-monitor/compare/v0.0.2...v0.0.3)
|
110
|
+
|
111
|
+
## 0.0.2 2017-02-02
|
46
112
|
|
47
|
-
# v0.0.2 2017-02-02
|
48
113
|
|
49
114
|
### Added
|
50
115
|
|
51
|
-
|
52
|
-
|
53
|
-
|
116
|
+
- `Dry::Monitor::Rack::Middleware#on` shortcut (solnic)
|
117
|
+
- `Dry::Monitor::Rack::Middleware#instrument` shortcut (solnic)
|
118
|
+
- `Dry::Monitor::SQL::Logger` can be configured with a custom message template (solnic)
|
54
119
|
|
55
120
|
### Changed
|
56
121
|
|
57
|
-
|
58
|
-
|
122
|
+
- `Dry::Monitor::Rack::Logger#{subscribe=>attach}` and now it accepts a rack middleware instance (solnic)
|
123
|
+
- `Dry::Monitor::Rack::Logger` appends new lines when logging `:rack.request.stop` events (solnic)
|
124
|
+
|
125
|
+
[Compare v0.0.1...v0.0.2](https://github.com/dry-rb/dry-monitor/compare/v0.0.1...v0.0.2)
|
59
126
|
|
60
|
-
|
127
|
+
## 0.0.1 2017-02-01
|
61
128
|
|
62
129
|
First public release
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,25 +1,29 @@
|
|
1
|
+
<!--- this file is synced from dry-rb/template-gem project -->
|
1
2
|
[gem]: https://rubygems.org/gems/dry-monitor
|
2
|
-
[
|
3
|
-
[
|
4
|
-
[
|
5
|
-
[coveralls]: https://coveralls.io/r/dry-rb/dry-monitor
|
3
|
+
[actions]: https://github.com/dry-rb/dry-monitor/actions
|
4
|
+
[codacy]: https://www.codacy.com/gh/dry-rb/dry-monitor
|
5
|
+
[chat]: https://dry-rb.zulipchat.com
|
6
6
|
[inchpages]: http://inch-ci.org/github/dry-rb/dry-monitor
|
7
7
|
|
8
|
-
# dry-monitor [![Join the chat at https://
|
8
|
+
# dry-monitor [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
|
9
9
|
|
10
10
|
[![Gem Version](https://badge.fury.io/rb/dry-monitor.svg)][gem]
|
11
|
-
[![
|
12
|
-
[![
|
13
|
-
[![
|
14
|
-
[![Test Coverage](https://codeclimate.com/github/dry-rb/dry-monitor/badges/coverage.svg)][codeclimate]
|
11
|
+
[![CI Status](https://github.com/dry-rb/dry-monitor/workflows/CI/badge.svg)][actions]
|
12
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/984c4274e56d423a818e7a1bf5e963d0)][codacy]
|
13
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/984c4274e56d423a818e7a1bf5e963d0)][codacy]
|
15
14
|
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-monitor.svg?branch=master)][inchpages]
|
16
15
|
|
17
|
-
|
16
|
+
## Links
|
18
17
|
|
19
|
-
|
18
|
+
* [User documentation](https://dry-rb.org/gems/dry-monitor)
|
19
|
+
* [API documentation](http://rubydoc.info/gems/dry-monitor)
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
## Supported Ruby versions
|
22
|
+
|
23
|
+
This library officially supports the following Ruby versions:
|
24
|
+
|
25
|
+
* MRI `>= 2.6.0`
|
26
|
+
* ~~jruby~~ `>= 9.3` (we are waiting for [2.6 support](https://github.com/jruby/jruby/issues/6161))
|
23
27
|
|
24
28
|
## License
|
25
29
|
|
data/dry-monitor.gemspec
CHANGED
@@ -1,27 +1,40 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# this file is synced from dry-rb/template-gem project
|
4
|
+
|
5
|
+
lib = File.expand_path("lib", __dir__)
|
6
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
7
|
+
require "dry/monitor/version"
|
3
8
|
|
4
9
|
Gem::Specification.new do |spec|
|
5
|
-
spec.name =
|
6
|
-
spec.
|
7
|
-
spec.
|
8
|
-
spec.
|
9
|
-
spec.
|
10
|
-
|
11
|
-
spec.
|
12
|
-
|
13
|
-
spec.
|
14
|
-
spec.
|
15
|
-
spec.
|
16
|
-
spec.
|
17
|
-
|
18
|
-
|
19
|
-
spec.
|
20
|
-
spec.
|
21
|
-
spec.
|
22
|
-
|
23
|
-
|
24
|
-
spec.
|
25
|
-
|
26
|
-
|
10
|
+
spec.name = "dry-monitor"
|
11
|
+
spec.authors = ["Piotr Solnica"]
|
12
|
+
spec.email = ["piotr.solnica@gmail.com"]
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.version = Dry::Monitor::VERSION.dup
|
15
|
+
|
16
|
+
spec.summary = "Monitoring and instrumentation APIs"
|
17
|
+
spec.description = spec.summary
|
18
|
+
spec.homepage = "https://dry-rb.org/gems/dry-monitor"
|
19
|
+
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-monitor.gemspec", "lib/**/*"]
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = []
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-monitor/blob/master/CHANGELOG.md"
|
26
|
+
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-monitor"
|
27
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-monitor/issues"
|
28
|
+
|
29
|
+
spec.required_ruby_version = ">= 2.6.0"
|
30
|
+
|
31
|
+
# to update dependencies edit project.yml
|
32
|
+
spec.add_runtime_dependency "dry-configurable", "~> 0.13", ">= 0.13.0"
|
33
|
+
spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
|
34
|
+
spec.add_runtime_dependency "dry-events", "~> 0.2"
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler"
|
37
|
+
spec.add_development_dependency "rake"
|
38
|
+
spec.add_development_dependency "rouge", "~> 2.0", ">= 2.2.1"
|
39
|
+
spec.add_development_dependency "rspec"
|
27
40
|
end
|
data/lib/dry/monitor/logger.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
2
4
|
|
3
5
|
module Dry
|
4
6
|
module Monitor
|
5
7
|
class Logger < ::Logger
|
8
|
+
DEFAULT_FORMATTER = proc do |_severity, _datetime, _progname, msg|
|
9
|
+
"#{msg}\n"
|
10
|
+
end
|
11
|
+
|
6
12
|
def initialize(*args)
|
7
13
|
super
|
8
|
-
self.formatter =
|
9
|
-
"#{msg}\n"
|
10
|
-
end
|
14
|
+
self.formatter = DEFAULT_FORMATTER
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/events/publisher"
|
4
|
+
require "dry/monitor/constants"
|
2
5
|
|
3
6
|
module Dry
|
4
7
|
module Monitor
|
@@ -17,11 +20,9 @@ module Dry
|
|
17
20
|
CLOCK = Clock.new
|
18
21
|
|
19
22
|
class Notifications
|
20
|
-
include Events::Publisher[
|
21
|
-
|
22
|
-
attr_reader :id
|
23
|
+
include Events::Publisher["Dry::Monitor::Notifications"]
|
23
24
|
|
24
|
-
attr_reader :clock
|
25
|
+
attr_reader :id, :clock
|
25
26
|
|
26
27
|
def initialize(id)
|
27
28
|
@id = id
|
@@ -36,10 +37,8 @@ module Dry
|
|
36
37
|
instrument(event_id, payload)
|
37
38
|
end
|
38
39
|
|
39
|
-
def instrument(event_id, payload = EMPTY_HASH)
|
40
|
-
if block_given?
|
41
|
-
result, time = @clock.measure { yield }
|
42
|
-
end
|
40
|
+
def instrument(event_id, payload = EMPTY_HASH, &block)
|
41
|
+
result, time = @clock.measure(&block) if block_given?
|
43
42
|
|
44
43
|
process(event_id, payload) do |event, listener|
|
45
44
|
if time
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/configurable"
|
4
|
+
require "dry/monitor/rack/middleware"
|
3
5
|
|
4
6
|
module Dry
|
5
7
|
module Monitor
|
@@ -7,21 +9,19 @@ module Dry
|
|
7
9
|
class Logger
|
8
10
|
extend Dry::Configurable
|
9
11
|
|
10
|
-
setting :filtered_params, %w[_csrf password]
|
11
|
-
|
12
|
-
REQUEST_METHOD = 'REQUEST_METHOD'.freeze
|
13
|
-
PATH_INFO = 'PATH_INFO'.freeze
|
14
|
-
REMOTE_ADDR = 'REMOTE_ADDR'.freeze
|
15
|
-
QUERY_STRING = 'QUERY_STRING'.freeze
|
12
|
+
setting :filtered_params, default: %w[_csrf password]
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
REQUEST_METHOD = "REQUEST_METHOD"
|
15
|
+
PATH_INFO = "PATH_INFO"
|
16
|
+
REMOTE_ADDR = "REMOTE_ADDR"
|
17
|
+
QUERY_STRING = "QUERY_STRING"
|
21
18
|
|
22
|
-
|
19
|
+
START_MSG = %(Started %s "%s" for %s at %s)
|
20
|
+
STOP_MSG = %(Finished %s "%s" for %s in %sms [Status: %s]\n)
|
21
|
+
QUERY_MSG = %( Query parameters )
|
22
|
+
FILTERED = "[FILTERED]"
|
23
23
|
|
24
|
-
attr_reader :config
|
24
|
+
attr_reader :logger, :config
|
25
25
|
|
26
26
|
def initialize(logger, config = self.class.config)
|
27
27
|
@logger = logger
|
@@ -29,47 +29,39 @@ module Dry
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def attach(rack_monitor)
|
32
|
-
rack_monitor.on(:start)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
rack_monitor.on(:stop) do |env:, status:, time:|
|
37
|
-
log_stop_request(env, status, time)
|
38
|
-
end
|
39
|
-
|
40
|
-
rack_monitor.on(:error) do |event|
|
41
|
-
log_exception(event[:exception])
|
42
|
-
end
|
32
|
+
rack_monitor.on(:start) { |params| log_start_request(params[:env]) }
|
33
|
+
rack_monitor.on(:stop) { |params| log_stop_request(**params) }
|
34
|
+
rack_monitor.on(:error) { |event| log_exception(event[:exception]) }
|
43
35
|
end
|
44
36
|
|
45
|
-
def log_exception(
|
46
|
-
logger.error
|
47
|
-
logger.error filter_backtrace(
|
37
|
+
def log_exception(err)
|
38
|
+
logger.error err.message
|
39
|
+
logger.error filter_backtrace(err.backtrace).join("\n")
|
48
40
|
end
|
49
41
|
|
50
42
|
def log_start_request(request)
|
51
|
-
info START_MSG % [
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
43
|
+
logger.info START_MSG % [
|
44
|
+
request[REQUEST_METHOD],
|
45
|
+
request[PATH_INFO],
|
46
|
+
request[REMOTE_ADDR],
|
47
|
+
Time.now
|
48
|
+
]
|
57
49
|
log_request_params(request)
|
58
50
|
end
|
59
51
|
|
60
|
-
def log_stop_request(
|
61
|
-
info STOP_MSG % [
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
52
|
+
def log_stop_request(env:, status:, time:)
|
53
|
+
logger.info STOP_MSG % [
|
54
|
+
env[REQUEST_METHOD],
|
55
|
+
env[PATH_INFO],
|
56
|
+
env[REMOTE_ADDR],
|
57
|
+
time,
|
58
|
+
status
|
59
|
+
]
|
68
60
|
end
|
69
61
|
|
70
62
|
def log_request_params(request)
|
71
63
|
with_http_params(request[QUERY_STRING]) do |params|
|
72
|
-
info QUERY_MSG
|
64
|
+
logger.info QUERY_MSG + params.inspect
|
73
65
|
end
|
74
66
|
end
|
75
67
|
|
@@ -80,28 +72,26 @@ module Dry
|
|
80
72
|
def with_http_params(params)
|
81
73
|
params = ::Rack::Utils.parse_nested_query(params)
|
82
74
|
|
83
|
-
|
84
|
-
yield(filter_params(params))
|
85
|
-
end
|
75
|
+
yield(filter_params(params)) unless params.empty?
|
86
76
|
end
|
87
77
|
|
88
78
|
def filter_backtrace(backtrace)
|
89
79
|
# TODO: what do we want to do with this?
|
90
|
-
backtrace.reject { |l| l.include?(
|
80
|
+
backtrace.reject { |l| l.include?("gems") }
|
91
81
|
end
|
92
82
|
|
93
83
|
def filter_params(params)
|
94
|
-
params.
|
84
|
+
params.each do |k, v|
|
95
85
|
if config.filtered_params.include?(k)
|
96
|
-
|
86
|
+
params[k] = FILTERED
|
97
87
|
elsif v.is_a?(Hash)
|
98
|
-
|
88
|
+
filter_params(v)
|
99
89
|
elsif v.is_a?(Array)
|
100
|
-
|
101
|
-
else
|
102
|
-
h[k] = v
|
90
|
+
v.map! { |m| m.is_a?(Hash) ? filter_params(m) : m }
|
103
91
|
end
|
104
92
|
end
|
93
|
+
|
94
|
+
params
|
105
95
|
end
|
106
96
|
end
|
107
97
|
end
|