rollday 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +61 -2
- data/lib/rollday/client_middleware.rb +5 -1
- data/lib/rollday/configuration.rb +13 -4
- data/lib/rollday/errors.rb +7 -0
- data/lib/rollday/middleware.rb +1 -1
- data/lib/rollday/rollbar_helper.rb +4 -2
- data/lib/rollday/use_middleware.rb +2 -1
- data/lib/rollday/version.rb +1 -1
- data/lib/rollday.rb +14 -11
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02476ca50a8cb131cd458cffe10428026cee831d1c6ec555cc605541ebc20d9c
|
4
|
+
data.tar.gz: e4e0c9c14d3f02ea831fe77efe9a4142291c995d955200dd00085a136e6deba6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fc90d8d766d8687322349b6fae4bf8dc12fa7f0f1b40b81476b90a15c1980737879f92947b431d064c6e24f9da3a0cfae91c08340dbeefff4ceddda0463075a
|
7
|
+
data.tar.gz: 443ca20fde67b2447dc734c9bd3fba8b37f6373b35149cc52d5e824fc4432a59c2964cd0bd8d18e74171be934b875a85aa9a86033843404c14fd1499230508f5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,9 +20,9 @@ gem 'rollday'
|
|
20
20
|
Intialization should happen in `app/initializers/rollday.rb`. All options below are the current defaults unless stated
|
21
21
|
```ruby
|
22
22
|
Rollday.configure do |config|
|
23
|
-
config.use_default_middleware! # [Not default option] set middleware for all Faraday requests (Faraday.get(...))
|
23
|
+
config.use_default_middleware! # [Not default option] set middleware for all Faraday requests (Faraday.get(...)). Caution when used with Default Client Middleware
|
24
24
|
|
25
|
-
config.use_default_client_middleware! # [Not default option] set middleware for all Faraday
|
25
|
+
config.use_default_client_middleware! # [Not default option] set middleware for all Faraday instances. Caution when used with Default Middleware
|
26
26
|
|
27
27
|
config.status_code_regex = /[45]\d\d$/ # If status code matches, will attempt to send a rollbar
|
28
28
|
|
@@ -44,6 +44,65 @@ Rollday.configure do |config|
|
|
44
44
|
end
|
45
45
|
```
|
46
46
|
|
47
|
+
### Ex: Default Faraday Client
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# Rollday initializer
|
51
|
+
Rollday.configure do |config|
|
52
|
+
config.use_default_middleware!
|
53
|
+
config.status_code_regex = /[2345]\d\d$/
|
54
|
+
config.message = -> (s, phrase, b, path, domain) { "[#{domain}] via #{path} returned #{status}" }
|
55
|
+
end
|
56
|
+
|
57
|
+
Farady.get("http://httpstat.us/207") # => 200 status code returned
|
58
|
+
# Will send a rollbar because Status code matches regex
|
59
|
+
```
|
60
|
+
|
61
|
+
### Ex: Default Faraday Instance
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
# Rollday initializer
|
65
|
+
Rollday.configure do |config|
|
66
|
+
config.use_default_client_middleware!
|
67
|
+
config.message = -> (s, phrase, b, path, domain) { "[#{domain}] via #{path} returned #{status} using default client middleware" }
|
68
|
+
end
|
69
|
+
Farady.get("http://httpstat.us/500") # => 500 status code returned
|
70
|
+
# Rollbar will not get sent because `use_default_middleware!` is not set
|
71
|
+
|
72
|
+
client = Faraday.new(url: base_url)
|
73
|
+
client.get("404") # => 404 status code returned
|
74
|
+
# Will send a rollbar because Status code matches regex
|
75
|
+
```
|
76
|
+
|
77
|
+
### Ex: Custom Faraday Instance
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
# Rollday initializer
|
81
|
+
Rollday.configure do |config|
|
82
|
+
config.status_code_regex = /[2]\d\d$/
|
83
|
+
config.message = -> (s, phrase, b, path, domain) { "[#{domain}] via #{path} returned #{status} using custom client middleware" }
|
84
|
+
end
|
85
|
+
Farady.get("http://httpstat.us/500") # => 500 status code returned
|
86
|
+
# Rollbar will not get sent because `use_default_middleware!` is not set
|
87
|
+
|
88
|
+
client = Faraday.new(url: base_url) do |conn|
|
89
|
+
conn.use Rollday::MIDDLEWARE_NAME
|
90
|
+
end
|
91
|
+
client.get("209") # => 209 status code returned
|
92
|
+
# Will send a rollbar because Status code matches regex
|
93
|
+
```
|
94
|
+
|
95
|
+
### Use Caution
|
96
|
+
```ruby
|
97
|
+
# Rollday initializer
|
98
|
+
Rollday.configure do |config|
|
99
|
+
# Do not do this!
|
100
|
+
config.use_default_middleware!
|
101
|
+
config.use_default_client_middleware!
|
102
|
+
end
|
103
|
+
```
|
104
|
+
Adding both the `use_default_middleware!` and the `use_default_client_middleware!` will cause double reporting of all default Faraday builders.
|
105
|
+
|
47
106
|
## Development
|
48
107
|
|
49
108
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
@@ -4,7 +4,11 @@ module Rollday
|
|
4
4
|
module FaradayConnectionOptions
|
5
5
|
def new_builder(block)
|
6
6
|
super.tap do |builder|
|
7
|
-
|
7
|
+
# allow scope to remove usage of middleware for a request
|
8
|
+
# after it has been injected into the Connection
|
9
|
+
if Rollday.config.allow_client_middleware
|
10
|
+
builder.use(Rollday::MIDDLEWARE_NAME)
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "rollday/use_middleware"
|
4
|
-
require "rollbar"
|
5
3
|
require "class_composer"
|
4
|
+
require "rollbar"
|
5
|
+
require "rollday/errors"
|
6
|
+
require "rollday/use_middleware"
|
6
7
|
|
7
8
|
module Rollday
|
8
9
|
class Configuration
|
@@ -15,10 +16,11 @@ module Rollday
|
|
15
16
|
ERROR = :error,
|
16
17
|
CRITICAL = :critical
|
17
18
|
]
|
19
|
+
DEFAULT_ROLLBAR_LEVEL = WARNING
|
18
20
|
|
19
21
|
DEFAULT_STATUS_CODE_REGEX = /[45]\d\d$/
|
20
22
|
DEFAULT_MESSAGE_PROC = ->(status, phrase, body, path, domain) { "[#{status}]: #{domain} - #{path}" }
|
21
|
-
DEFAULT_LEVEL_PROC = ->(_status) {
|
23
|
+
DEFAULT_LEVEL_PROC = ->(_status) { DEFAULT_ROLLBAR_LEVEL }
|
22
24
|
ROLLBAR_VALIDATOR = Proc.new do |value|
|
23
25
|
value.is_a?(Proc) || ROLLBAR_LEVELS.include?(value)
|
24
26
|
end
|
@@ -26,12 +28,15 @@ module Rollday
|
|
26
28
|
add_composer :message, allowed: [Proc, String], default: DEFAULT_MESSAGE_PROC
|
27
29
|
add_composer :params_query_sanitizer, allowed: Array, default: []
|
28
30
|
add_composer :params_scope_sanitizer, allowed: Array, default: []
|
31
|
+
add_composer :person_scope, allowed: Proc
|
32
|
+
add_composer :rollbar_level, allowed: [Proc, Symbol], default: DEFAULT_LEVEL_PROC, validator: ROLLBAR_VALIDATOR, invalid_message: -> (val) { "Value must be a Proc or one of #{ROLLBAR_LEVELS}" }
|
29
33
|
add_composer :status_code_regex, allowed: Regexp, default: DEFAULT_STATUS_CODE_REGEX
|
30
34
|
add_composer :use_message_exception, allowed: [TrueClass, FalseClass], default: true
|
31
35
|
add_composer :use_params_scope, allowed: [TrueClass, FalseClass], default: true
|
32
36
|
add_composer :use_person_scope, allowed: [TrueClass, FalseClass], default: true
|
33
37
|
add_composer :use_query_scope, allowed: [TrueClass, FalseClass], default: true
|
34
|
-
add_composer :
|
38
|
+
add_composer :exception_class, allowed: Class, default: Rollday::Faraday
|
39
|
+
add_composer :allow_client_middleware, allowed: [TrueClass, FalseClass], default: true
|
35
40
|
|
36
41
|
def person_scope
|
37
42
|
return -> {} unless @use_person_scope
|
@@ -46,5 +51,9 @@ module Rollday
|
|
46
51
|
def use_default_client_middleware!
|
47
52
|
Rollday.use_default_client_middleware!
|
48
53
|
end
|
54
|
+
|
55
|
+
def register_middleware!
|
56
|
+
Rollday.register_middleware!
|
57
|
+
end
|
49
58
|
end
|
50
59
|
end
|
data/lib/rollday/middleware.rb
CHANGED
@@ -14,7 +14,7 @@ module Rollday
|
|
14
14
|
message = Rollday.config.message.(result.status, result.reason_phrase, result.body, URI(result.env.url).path, URI(result.env.url).host)
|
15
15
|
return message unless Rollday.config.use_message_exception
|
16
16
|
|
17
|
-
Rollday
|
17
|
+
Rollday.config.exception_class.new(message)
|
18
18
|
end
|
19
19
|
|
20
20
|
def rollbar_scope(result)
|
@@ -36,8 +36,10 @@ module Rollday
|
|
36
36
|
|
37
37
|
def query_scope(result)
|
38
38
|
return {} unless Rollday.config.use_query_scope
|
39
|
+
raw_query = URI(result.env.url).query
|
40
|
+
return if raw_query.nil?
|
39
41
|
|
40
|
-
query_scope = CGI::parse(
|
42
|
+
query_scope = CGI::parse(raw_query)
|
41
43
|
Rollday.config.params_scope_sanitizer.each do |sanitizer|
|
42
44
|
query_scope = sanitizer.(query_params)
|
43
45
|
end
|
@@ -23,6 +23,7 @@ module Rollday
|
|
23
23
|
def self.use_default_client_middleware!
|
24
24
|
return false if @use_default_client_middleware
|
25
25
|
|
26
|
+
register_middleware!
|
26
27
|
require "rollday/client_middleware"
|
27
28
|
::Faraday::ConnectionOptions.prepend(Rollday::FaradayConnectionOptions)
|
28
29
|
|
@@ -32,7 +33,7 @@ module Rollday
|
|
32
33
|
def self.register_middleware!
|
33
34
|
return false if @register_middleware
|
34
35
|
|
35
|
-
::Faraday::Middleware.register_middleware(Rollday::
|
36
|
+
::Faraday::Middleware.register_middleware(Rollday::MIDDLEWARE_NAME => Middleware)
|
36
37
|
@register_middleware = true
|
37
38
|
end
|
38
39
|
end
|
data/lib/rollday/version.rb
CHANGED
data/lib/rollday.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "rollday/version"
|
4
3
|
require "faraday"
|
5
4
|
require "rollday/configuration"
|
5
|
+
require "rollday/errors"
|
6
6
|
require "rollday/middleware"
|
7
|
+
require "rollday/version"
|
7
8
|
|
8
9
|
module Rollday
|
9
|
-
|
10
|
-
class Faraday < Error; end # used to create backtrace for rollbar
|
11
|
-
class ConfigError < Error; end
|
12
|
-
|
13
|
-
FARADAY_NAME = :rollday.freeze
|
10
|
+
MIDDLEWARE_NAME = :rollday.freeze
|
14
11
|
|
15
12
|
def self.configure
|
16
13
|
yield configuration if block_given?
|
@@ -20,18 +17,20 @@ module Rollday
|
|
20
17
|
@configuration ||= Rollday::Configuration.new
|
21
18
|
end
|
22
19
|
|
23
|
-
class << self
|
24
|
-
alias_method :config, :configuration
|
25
|
-
end
|
26
|
-
|
27
20
|
def self.configuration=(object)
|
28
21
|
raise ConfigError, "Expected configuration to be a Rollday::Configuration" unless object.is_a?(Rollday::Configuration)
|
29
22
|
|
30
23
|
@configuration = object
|
31
24
|
end
|
32
25
|
|
33
|
-
def self.
|
26
|
+
def self.reset_configuration!
|
27
|
+
@configuration = Rollday::Configuration.new
|
28
|
+
end
|
34
29
|
|
30
|
+
class << self
|
31
|
+
alias_method :config, :configuration
|
32
|
+
alias_method :config=, :configuration=
|
33
|
+
alias_method :reset_config!, :reset_configuration!
|
35
34
|
end
|
36
35
|
|
37
36
|
def self.use_default_middleware!
|
@@ -42,6 +41,10 @@ module Rollday
|
|
42
41
|
Rollday::UseMiddleware.use_default_client_middleware!
|
43
42
|
end
|
44
43
|
|
44
|
+
def self.register_middleware!
|
45
|
+
Rollday::UseMiddleware.register_middleware!
|
46
|
+
end
|
47
|
+
|
45
48
|
def self.with_scope()
|
46
49
|
end
|
47
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rollday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: class_composer
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- lib/rollday.rb
|
134
134
|
- lib/rollday/client_middleware.rb
|
135
135
|
- lib/rollday/configuration.rb
|
136
|
+
- lib/rollday/errors.rb
|
136
137
|
- lib/rollday/middleware.rb
|
137
138
|
- lib/rollday/rollbar_helper.rb
|
138
139
|
- lib/rollday/use_middleware.rb
|