rollday 0.3.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +61 -2
- data/lib/rollday/client_middleware.rb +5 -1
- data/lib/rollday/configuration.rb +29 -58
- 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
- data/rollday.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dcbfc77cb4787f580d9c4b6cde2f8b85949686c33c38cfe8cc5e7f111774785
|
4
|
+
data.tar.gz: b3b50b20c3261233417a8b2e890773a6ed64567a7c06a8d050ed8c367b907faa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '029ad6bf6bf727a915a3db8e6dc3d9c89650eb5603af6f5b1d774df6fd90ab57777a81eb723d9f7aa7cc2498e712cd4dec6bc08e7a38d9e4103909501c9c0f3f'
|
7
|
+
data.tar.gz: 78cf9981e07d0dde0197749416e086e7499d27d459e5edf40d7b99b9ba97a26b08fa4d84a5262e7722878d4c287c70baa04d15d53a5666ffe77d2990642dc934
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rollday (0.
|
4
|
+
rollday (0.5.0)
|
5
|
+
class_composer
|
5
6
|
faraday
|
6
7
|
rollbar
|
7
8
|
|
@@ -9,6 +10,7 @@ GEM
|
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
11
12
|
byebug (11.1.3)
|
13
|
+
class_composer (1.0.0)
|
12
14
|
coderay (1.1.3)
|
13
15
|
concurrent-ruby (1.1.10)
|
14
16
|
diff-lcs (1.5.0)
|
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,10 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "class_composer"
|
4
4
|
require "rollbar"
|
5
|
+
require "rollday/errors"
|
6
|
+
require "rollday/use_middleware"
|
5
7
|
|
6
8
|
module Rollday
|
7
9
|
class Configuration
|
10
|
+
include ClassComposer::Generator
|
11
|
+
|
8
12
|
ROLLBAR_LEVELS = [
|
9
13
|
DEBUG = :debug,
|
10
14
|
INFO = :info,
|
@@ -12,67 +16,30 @@ module Rollday
|
|
12
16
|
ERROR = :error,
|
13
17
|
CRITICAL = :critical
|
14
18
|
]
|
19
|
+
DEFAULT_ROLLBAR_LEVEL = WARNING
|
15
20
|
|
16
21
|
DEFAULT_STATUS_CODE_REGEX = /[45]\d\d$/
|
17
|
-
DEFAULT_MESSAGE_PROC = ->(status, phrase, domain) { "[#{status}]: #{domain}" }
|
18
|
-
DEFAULT_LEVEL_PROC = ->(_status) {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@rollbar_level = DEFAULT_LEVEL_PROC
|
36
|
-
end
|
37
|
-
|
38
|
-
def rollbar_level=(level)
|
39
|
-
raise ConfigError, "level= must be passed a Proc or #{ROLLBAR_LEVELS}. But was passed a #{level} instead"
|
40
|
-
|
41
|
-
@rollbar_level = level
|
42
|
-
end
|
43
|
-
|
44
|
-
def rollbar_level
|
45
|
-
@rollbar_level
|
46
|
-
end
|
47
|
-
|
48
|
-
def message=(message)
|
49
|
-
raise ConfigError, "message= must be passed a Proc but was passed a #{message.class} instead"
|
50
|
-
|
51
|
-
@message = message
|
52
|
-
end
|
53
|
-
|
54
|
-
def message
|
55
|
-
@message
|
56
|
-
end
|
57
|
-
|
58
|
-
def status_code_regex
|
59
|
-
@status_code_regex
|
60
|
-
end
|
61
|
-
|
62
|
-
def status_code_regex=(regex)
|
63
|
-
raise ConfigError, "status_code_regex= must be passed a regex but was passed a #{regex.class} instead"
|
64
|
-
|
65
|
-
@status_code_regex = regex
|
66
|
-
end
|
67
|
-
|
68
|
-
def person_scope=(person_scope)
|
69
|
-
raise ConfigError, "person_scope= must be passed a Proc but was passed a #{person_scope.class} instead"
|
70
|
-
|
71
|
-
@person_scope = person_scope
|
72
|
-
end
|
22
|
+
DEFAULT_MESSAGE_PROC = ->(status, phrase, body, path, domain) { "[#{status}]: #{domain} - #{path}" }
|
23
|
+
DEFAULT_LEVEL_PROC = ->(_status) { DEFAULT_ROLLBAR_LEVEL }
|
24
|
+
ROLLBAR_VALIDATOR = Proc.new do |value|
|
25
|
+
value.is_a?(Proc) || ROLLBAR_LEVELS.include?(value)
|
26
|
+
end
|
27
|
+
|
28
|
+
add_composer :message, allowed: [Proc, String], default: DEFAULT_MESSAGE_PROC
|
29
|
+
add_composer :params_query_sanitizer, allowed: Array, default: []
|
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}" }
|
33
|
+
add_composer :status_code_regex, allowed: Regexp, default: DEFAULT_STATUS_CODE_REGEX
|
34
|
+
add_composer :use_message_exception, allowed: [TrueClass, FalseClass], default: true
|
35
|
+
add_composer :use_params_scope, allowed: [TrueClass, FalseClass], default: true
|
36
|
+
add_composer :use_person_scope, allowed: [TrueClass, FalseClass], default: true
|
37
|
+
add_composer :use_query_scope, allowed: [TrueClass, FalseClass], default: true
|
38
|
+
add_composer :exception_class, allowed: Class, default: Rollday::Faraday
|
39
|
+
add_composer :allow_client_middleware, allowed: [TrueClass, FalseClass], default: true
|
73
40
|
|
74
41
|
def person_scope
|
75
|
-
return -> {} unless
|
42
|
+
return -> {} unless use_person_scope
|
76
43
|
|
77
44
|
@person_scope || Rollbar.scope.scope_object.raw[:person] || -> {}
|
78
45
|
end
|
@@ -84,5 +51,9 @@ module Rollday
|
|
84
51
|
def use_default_client_middleware!
|
85
52
|
Rollday.use_default_client_middleware!
|
86
53
|
end
|
54
|
+
|
55
|
+
def register_middleware!
|
56
|
+
Rollday.register_middleware!
|
57
|
+
end
|
87
58
|
end
|
88
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
|
data/rollday.gemspec
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rollday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
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-
|
11
|
+
date: 2022-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: class_composer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: faraday
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,6 +133,7 @@ files:
|
|
119
133
|
- lib/rollday.rb
|
120
134
|
- lib/rollday/client_middleware.rb
|
121
135
|
- lib/rollday/configuration.rb
|
136
|
+
- lib/rollday/errors.rb
|
122
137
|
- lib/rollday/middleware.rb
|
123
138
|
- lib/rollday/rollbar_helper.rb
|
124
139
|
- lib/rollday/use_middleware.rb
|