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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79d679b29fb37de532a1855d9d9225bb1337f9675c93ec509b6ea2f70f2123d7
4
- data.tar.gz: 3308df70e50a3d4bf2c95a772846e3c6229ef764d6ec679e5a3760249f48afb6
3
+ metadata.gz: 973eacb62c325645cdf9f3b01b5c39512e4b8f461b99ffcd7993edbd0d6e813f
4
+ data.tar.gz: 3b7687f24f0a6498516a7fe5e9a36c4c1b4bb988a64e708a9bf5b4f2c52a17ad
5
5
  SHA512:
6
- metadata.gz: 2bb851503a4caa35361e751bb68367d71b04d3c005f08d47090cb5646b7756be257ecc7bbaff5b22aff18e7cf34770af3b39b196886bb35d221002c4b6996d31
7
- data.tar.gz: e2247a4b41a7430b1a609556aab0dbfca7c0bf7fe115ef19a91c772e3f47707d57aa80bb024ad9bfc222d73d50ddba5904ab08c08ef66505208bcaaf20e43316
6
+ metadata.gz: 8feea8bd4a5b2a38ab32b1565620b8e4c6696c5960e2abbcf4c4b9875a183a9fbef76361e794aeb17a18e41781669988f41367b6cdf3eb49d5ad8761ea71da17
7
+ data.tar.gz: 80bf24f9be77459e782a417c9e8ca4a106ab4e07e0ef1b89174bab41205d13658723736064bcdc0cdbe60b3a50277b20b38bd037632a37845a147bda3bb14e98
data/CHANGELOG.md CHANGED
@@ -1,62 +1,129 @@
1
- # v0.3.0 2019-01-29
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
- * cannot load such file -- rack/utils (mensfeld)
50
+ - cannot load such file -- rack/utils (mensfeld)
6
51
 
7
52
  ### Changed
8
53
 
9
- * Make `rack` logger into a plugin (mensfeld)
10
- * Make `sql` logger into a plugin (mensfeld)
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
- * Make `rouge` an optional dependency (davydovanton & mensfeld)
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
- * Rack logger no longer prevents arbitrary payload in `:error` events (solnic)
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
- * Query params containing arrays of primitives (e.g. `?ids[]=1&ids[]=2`) no longer crash the logger (timriley)
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
- * Query params are logged correctly via rack middleware (solnic)
93
+ - Query params are logged correctly via rack middleware (solnic)
35
94
 
36
95
  ### Changed
37
96
 
38
- * Uses `dry-events` for notifications (solnic)
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
- * Update default theme setting for compatibility with latest version of rouge (alexandru-calinoiu)
45
- * Require latest version of rouge gem (timriley)
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
- * `Dry::Monitor::Rack::Middleware#on` shortcut (solnic)
52
- * `Dry::Monitor::Rack::Middleware#instrument` shortcut (solnic)
53
- * `Dry::Monitor::SQL::Logger` can be configured with a custom message template (solnic)
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
- * `Dry::Monitor::Rack::Logger#{subscribe=>attach}` and now it accepts a rack middleware instance (solnic)
58
- * `Dry::Monitor::Rack::Logger` appends new lines when logging `:rack.request.stop` events (solnic)
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
- # v0.0.1 2017-02-01
127
+ ## 0.0.1 2017-02-01
61
128
 
62
129
  First public release
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014 Ruby Object Mapper
3
+ Copyright (c) 2015-2021 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
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
- [travis]: https://travis-ci.org/dry-rb/dry-monitor
3
- [gemnasium]: https://gemnasium.com/dry-rb/dry-monitor
4
- [codeclimate]: https://codeclimate.com/github/dry-rb/dry-monitor
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://gitter.im/dry-rb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dry-rb/chat)
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
- [![Build Status](https://travis-ci.org/dry-rb/dry-monitor.svg?branch=master)][travis]
12
- [![Dependency Status](https://gemnasium.com/dry-rb/dry-monitor.svg)][gemnasium]
13
- [![Code Climate](https://codeclimate.com/github/dry-rb/dry-monitor/badges/gpa.svg)][codeclimate]
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
- Monitoring and instrumentation APIs.
16
+ ## Links
18
17
 
19
- ## Synopsis
18
+ * [User documentation](https://dry-rb.org/gems/dry-monitor)
19
+ * [API documentation](http://rubydoc.info/gems/dry-monitor)
20
20
 
21
- ``` ruby
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
- # coding: utf-8
2
- require File.expand_path('../lib/dry/monitor/version', __FILE__)
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 = 'dry-monitor'
6
- spec.version = Dry::Monitor::VERSION
7
- spec.authors = ['Piotr Solnica']
8
- spec.email = ['piotr.solnica@gmail.com']
9
- spec.summary = 'Monitoring and instrumentation APIs'
10
- spec.homepage = 'https://github.com/dry-rb/dry-monitor'
11
- spec.license = 'MIT'
12
-
13
- spec.files = `git ls-files -z`.split("\x0")
14
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
- spec.require_paths = ['lib']
17
-
18
- spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
19
- spec.add_runtime_dependency 'dry-configurable', '~> 0.5'
20
- spec.add_runtime_dependency 'dry-events', '~> 0.1'
21
- spec.add_runtime_dependency 'dry-core', '~> 0.4'
22
-
23
- spec.add_development_dependency 'rouge', '~> 2.0', '>= 2.2.1'
24
- spec.add_development_dependency 'bundler'
25
- spec.add_development_dependency 'rake'
26
- spec.add_development_dependency 'rspec'
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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/core/constants"
4
+
5
+ module Dry
6
+ module Monitor
7
+ include Dry::Core::Constants
8
+ end
9
+ end
@@ -1,13 +1,17 @@
1
- require 'logger'
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 = proc do |severity, datetime, progname, msg|
9
- "#{msg}\n"
10
- end
14
+ self.formatter = DEFAULT_FORMATTER
11
15
  end
12
16
  end
13
17
  end
@@ -1,4 +1,7 @@
1
- require 'dry/events/publisher'
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['Dry::Monitor::Notifications']
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
- require 'dry/configurable'
2
- require 'dry/monitor/rack/middleware'
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
- START_MSG = %(Started %s "%s" for %s at %s).freeze
18
- STOP_MSG = %(Finished %s "%s" for %s in %sms [Status: %s]\n).freeze
19
- QUERY_MSG = %( Query parameters %s).freeze
20
- FILTERED = '[FILTERED]'.freeze
14
+ REQUEST_METHOD = "REQUEST_METHOD"
15
+ PATH_INFO = "PATH_INFO"
16
+ REMOTE_ADDR = "REMOTE_ADDR"
17
+ QUERY_STRING = "QUERY_STRING"
21
18
 
22
- attr_reader :logger
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) do |env:|
33
- log_start_request(env)
34
- end
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(e)
46
- logger.error e.message
47
- logger.error filter_backtrace(e.backtrace).join("\n")
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
- request[REQUEST_METHOD],
53
- request[PATH_INFO],
54
- request[REMOTE_ADDR],
55
- Time.now
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(request, status, time)
61
- info STOP_MSG % [
62
- request[REQUEST_METHOD],
63
- request[PATH_INFO],
64
- request[REMOTE_ADDR],
65
- time,
66
- status
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 % [params.inspect]
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
- if params.size > 0
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?('gems') }
80
+ backtrace.reject { |l| l.include?("gems") }
91
81
  end
92
82
 
93
83
  def filter_params(params)
94
- params.each_with_object({}) do |(k, v), h|
84
+ params.each do |k, v|
95
85
  if config.filtered_params.include?(k)
96
- h.update(k => FILTERED)
86
+ params[k] = FILTERED
97
87
  elsif v.is_a?(Hash)
98
- h.update(k => filter_params(v))
88
+ filter_params(v)
99
89
  elsif v.is_a?(Array)
100
- h.update(k => v.map { |m| m.is_a?(Hash) ? filter_params(m) : m })
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