sapience 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -3
- data/README.md +51 -15
- data/config/default.yml +3 -0
- data/lib/sapience/configuration.rb +15 -13
- data/lib/sapience/log.rb +18 -1
- data/lib/sapience/sapience.rb +7 -6
- data/lib/sapience/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35f1a2a161ecc2efb23decddb30df46b01b372ed
|
4
|
+
data.tar.gz: f112df7cbf9149371fed662c5451c553c58ccecc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40fb5ccbf8c3deedb4ab1b51d87ef97138f18511c0df18709341342f4acb30c6b7138d3c334fcba41d92da4e644b029faeee3b2a768697c2bda0b9b232770d47
|
7
|
+
data.tar.gz: 745ade15fbe6afbdab30967ecd09f8ce48de280e6c9f69541b7aef93533f9ec7957df6ec6673567fa9042338c4cc03540e7ba8e615aecb05f572b5b104799e58
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
- Added `filter_parameters` configuration to obfuscate sensitive information such as passwords for rack-like applications
|
2
|
+
|
3
|
+
## v1.0.8
|
4
|
+
|
5
|
+
- Delayed configuration of Sentry until the configuration is valid
|
6
|
+
|
1
7
|
## v1.0.3
|
2
8
|
|
3
9
|
- Rename `SAPIENCE_APP_NAME` to `APP_NAME`
|
@@ -30,11 +36,11 @@
|
|
30
36
|
|
31
37
|
## v0.2.13
|
32
38
|
|
33
|
-
- Set Rails.logger even some gems disables logging on initialisation.
|
39
|
+
- Set Rails.logger even some gems disables logging on initialisation.
|
34
40
|
|
35
41
|
## v0.2.12
|
36
42
|
|
37
|
-
- Adds support for Rails apps with disabled ActiveRecord
|
43
|
+
- Adds support for Rails apps with disabled ActiveRecord
|
38
44
|
|
39
45
|
## v0.2.11
|
40
46
|
|
@@ -73,7 +79,7 @@
|
|
73
79
|
|
74
80
|
## v0.2.0
|
75
81
|
|
76
|
-
- Rename Appender::File to Appender::Stream. Accept option stream instead of file in `sapience.yml`
|
82
|
+
- Rename Appender::File to Appender::Stream. Accept option stream instead of file in `sapience.yml`
|
77
83
|
|
78
84
|
## v0.1.12
|
79
85
|
|
data/README.md
CHANGED
@@ -16,13 +16,13 @@ We have taken a great deal of inspiration from the amazing [Semantic Logger](htt
|
|
16
16
|
|
17
17
|
First of all we need to require the right file for the project. There are currently two frameworks supported (rails and grape).
|
18
18
|
|
19
|
-
### Rails
|
19
|
+
### Rails
|
20
20
|
|
21
21
|
```ruby
|
22
22
|
gem "sapience", require: "sapience/rails"
|
23
23
|
```
|
24
24
|
|
25
|
-
### Grape
|
25
|
+
### Grape
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
gem "sapience", require: "sapience/grape"
|
@@ -37,11 +37,11 @@ module Aslan
|
|
37
37
|
module API
|
38
38
|
class Base < Grape::API
|
39
39
|
use Sapience::Extensions::Grape::Middleware::Logging, logger: Sapience[self]
|
40
|
-
|
40
|
+
|
41
41
|
# To log all requests even when no route was found try the following:
|
42
42
|
route :any, "*path" do
|
43
43
|
error!({ error: "No route found" }, 404)
|
44
|
-
end
|
44
|
+
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -54,7 +54,7 @@ The sapience configuration can be controlled by a `config/sapience.yml` file or
|
|
54
54
|
|
55
55
|
The `app_name` is required to be configured. Sapience will fail on startup if app_name isn't configured properly.
|
56
56
|
|
57
|
-
```ruby
|
57
|
+
```ruby
|
58
58
|
Sapience.configure do |config|
|
59
59
|
config.default_level = :info
|
60
60
|
config.backtrace_level = :error
|
@@ -67,11 +67,14 @@ Sapience.configure do |config|
|
|
67
67
|
end
|
68
68
|
```
|
69
69
|
|
70
|
-
Sapience provides a default configuration that will be used unless another file or configuration is specified. You can provide a custom
|
70
|
+
Sapience provides a default configuration that will be used unless another file or configuration is specified. You can provide a custom
|
71
71
|
|
72
72
|
```yaml
|
73
73
|
---
|
74
74
|
default:
|
75
|
+
filter_parameters:
|
76
|
+
- password
|
77
|
+
- password_confirmation
|
75
78
|
log_executor: single_thread_executor
|
76
79
|
log_level: info
|
77
80
|
appenders:
|
@@ -145,6 +148,39 @@ Sapience.configure do |config|
|
|
145
148
|
end
|
146
149
|
```
|
147
150
|
|
151
|
+
#### Filtering out sensitive data
|
152
|
+
|
153
|
+
**NOTE: This is intended for (and will currently only work with) Rack-like applications, which include a `params` key in their `payload` hash**
|
154
|
+
|
155
|
+
You may not want to log certain parameters which have sensitive information to be in the logs, e.g. `password`. This can be set using the `filter_parameters` option when using `configure`:
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
Sapience.configure do |config|
|
159
|
+
# Filter the value of "foo" from rack's parameter hash
|
160
|
+
config.filter_parameters << 'foo'
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
164
|
+
Note that by default this is set to `['password', 'password_confirmation']`, so be careful when explicitly setting, as you may lose this filtering:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
Sapience.configure do |config|
|
168
|
+
# NOTE: password and password_confirmation will no longer be filtered
|
169
|
+
config.filter_parameters = ['foo']
|
170
|
+
end
|
171
|
+
```
|
172
|
+
|
173
|
+
Similarly, *be particularly careful* when setting as `yaml` because this will no longer filter `password` and `password_confirmation`:
|
174
|
+
|
175
|
+
```yaml
|
176
|
+
some_environment:
|
177
|
+
# NOTE: password and password_confirmation will no longer be filtered if they're not included in this list
|
178
|
+
filter_parameters:
|
179
|
+
- foo
|
180
|
+
```
|
181
|
+
|
182
|
+
Any filtered parameter will still show in the `params` field, but it's value will be `[FILTERED]`.
|
183
|
+
|
148
184
|
## Appenders
|
149
185
|
|
150
186
|
One of the things that did not suit us so well with the Semantic Logger approach was that they made a distinction between metrics and appenders. In our view anything that could potentially log something somewhere should be treated as an appender.
|
@@ -154,7 +190,7 @@ There are a number of appenders that each listen to different events and act on
|
|
154
190
|
|
155
191
|
### Stream
|
156
192
|
|
157
|
-
Stream appenders are basically a log stream. You can add as many stream appenders as you like logging to different locations.
|
193
|
+
Stream appenders are basically a log stream. You can add as many stream appenders as you like logging to different locations.
|
158
194
|
|
159
195
|
```ruby
|
160
196
|
Sapience.add_appender(:stream, file: "log/sapience.log", formatter: :json)
|
@@ -167,16 +203,16 @@ The sentry appender handles sending errors to [sentry](https://sentry.io). It's
|
|
167
203
|
|
168
204
|
```ruby
|
169
205
|
Sapience.add_appender(
|
170
|
-
:sentry,
|
171
|
-
dsn: "https://username:password@app.getsentry.com/00000",
|
172
|
-
level: :error,
|
206
|
+
:sentry,
|
207
|
+
dsn: "https://username:password@app.getsentry.com/00000",
|
208
|
+
level: :error,
|
173
209
|
backtrace_level: :error
|
174
210
|
)
|
175
211
|
```
|
176
212
|
|
177
213
|
#### Test exceptions
|
178
214
|
|
179
|
-
If you want to quickly verify that your appenders are handling exceptions properly. You can use the following method to
|
215
|
+
If you want to quickly verify that your appenders are handling exceptions properly. You can use the following method to
|
180
216
|
generate and log an exception at any given level.
|
181
217
|
|
182
218
|
```ruby
|
@@ -203,7 +239,7 @@ metrics.decrement("company/project/metric-name", 5)
|
|
203
239
|
metrics.histogram("company/project/metric-name", 2_500)
|
204
240
|
metrics.gauge("company/project/metric-name", 1_000, {})
|
205
241
|
metrics.event("company/project/metric-name", "description about event", {})
|
206
|
-
metrics.batch do
|
242
|
+
metrics.batch do
|
207
243
|
metrics.event("company/project/metric-name", "description about event", {})
|
208
244
|
metrics.increment("company/project/another-metric-name", 2)
|
209
245
|
end
|
@@ -226,15 +262,15 @@ Formatters can be specified by using the key `formatter: :camelized_formatter_na
|
|
226
262
|
|
227
263
|
`formatter: :color` - gives colorized output. Useful for `test` and `development` environments.
|
228
264
|
|
229
|
-
### Default
|
265
|
+
### Default
|
230
266
|
|
231
267
|
`formatter: :default` - logs a string. Inspired by how access logs for Nginx are logged.
|
232
268
|
|
233
|
-
### JSON
|
269
|
+
### JSON
|
234
270
|
|
235
271
|
`formatter: :json` - logs are saved as a single line json. Useful for production like environments.
|
236
272
|
|
237
|
-
### RAW
|
273
|
+
### RAW
|
238
274
|
|
239
275
|
`formatter: :raw` - logs are saved as a single line ruby hash. Useful for production like environments and is used internally for the Sentry appender.
|
240
276
|
|
data/config/default.yml
CHANGED
@@ -8,15 +8,16 @@ module Sapience
|
|
8
8
|
class Configuration
|
9
9
|
attr_reader :default_level, :backtrace_level, :backtrace_level_index
|
10
10
|
attr_writer :host
|
11
|
-
attr_accessor :app_name, :ap_options, :appenders, :log_executor
|
11
|
+
attr_accessor :app_name, :ap_options, :appenders, :log_executor, :filter_parameters
|
12
12
|
|
13
13
|
SUPPORTED_EXECUTORS = %i(single_thread_executor immediate_executor).freeze
|
14
14
|
DEFAULT = {
|
15
|
-
log_level:
|
16
|
-
host:
|
17
|
-
ap_options:
|
18
|
-
appenders:
|
19
|
-
log_executor:
|
15
|
+
log_level: :info,
|
16
|
+
host: nil,
|
17
|
+
ap_options: { multiline: false },
|
18
|
+
appenders: [{ stream: { io: STDOUT, formatter: :color } }],
|
19
|
+
log_executor: :single_thread_executor,
|
20
|
+
filter_parameters: %w(password password_confirmation),
|
20
21
|
}.freeze
|
21
22
|
|
22
23
|
# Initial default Level for all new instances of Sapience::Logger
|
@@ -25,13 +26,14 @@ module Sapience
|
|
25
26
|
@options = DEFAULT.merge(options.dup.deep_symbolize_keyz!)
|
26
27
|
@options[:log_executor] &&= @options[:log_executor].to_sym
|
27
28
|
validate_log_executor!(@options[:log_executor])
|
28
|
-
self.default_level
|
29
|
-
self.backtrace_level
|
30
|
-
self.host
|
31
|
-
self.app_name
|
32
|
-
self.ap_options
|
33
|
-
self.appenders
|
34
|
-
self.log_executor
|
29
|
+
self.default_level = @options[:log_level].to_sym
|
30
|
+
self.backtrace_level = @options[:log_level].to_sym
|
31
|
+
self.host = @options[:host]
|
32
|
+
self.app_name = @options[:app_name]
|
33
|
+
self.ap_options = @options[:ap_options]
|
34
|
+
self.appenders = @options[:appenders]
|
35
|
+
self.log_executor = @options[:log_executor]
|
36
|
+
self.filter_parameters = @options[:filter_parameters]
|
35
37
|
end
|
36
38
|
|
37
39
|
# Sets the global default log level
|
data/lib/sapience/log.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Sapience
|
2
2
|
# Log Struct
|
3
3
|
#
|
4
|
-
# Structure for holding all log entries
|
4
|
+
# Structure for holding all log entries. We're using a struct because we want it to be fast and lightweight.
|
5
5
|
#
|
6
6
|
# level
|
7
7
|
# Log level of the supplied log call
|
@@ -140,6 +140,23 @@ module Sapience
|
|
140
140
|
payload.inspect if payload?
|
141
141
|
end
|
142
142
|
|
143
|
+
# This filtering is specifically designed for Rack-based payloads which may
|
144
|
+
# have sensitive information such as "password" or "credit_card" in
|
145
|
+
# its hash. We need to obfuscate these fields.
|
146
|
+
def payload # rubocop:disable AbcSize
|
147
|
+
return self[:payload] unless self[:payload].is_a?(Hash) && self[:payload][:params].is_a?(Hash)
|
148
|
+
return @payload unless @payload.nil?
|
149
|
+
|
150
|
+
# We don't want to mutate the existing object so dup
|
151
|
+
@payload = self[:payload].dup
|
152
|
+
|
153
|
+
Sapience.config.filter_parameters.each do |filter|
|
154
|
+
@payload[:params][filter] = "[FILTERED]" if @payload[:params].key?(filter)
|
155
|
+
end
|
156
|
+
|
157
|
+
@payload
|
158
|
+
end
|
159
|
+
|
143
160
|
# Returns [true|false] whether the log entry has a payload
|
144
161
|
def payload?
|
145
162
|
!(payload.nil? || (payload.respond_to?(:empty?) && payload.empty?))
|
data/lib/sapience/sapience.rb
CHANGED
@@ -6,12 +6,13 @@ require "English"
|
|
6
6
|
# Example:
|
7
7
|
#
|
8
8
|
# Sapience.configure do |config|
|
9
|
-
# config.default_level
|
10
|
-
# config.backtrace_level
|
11
|
-
# config.app_name
|
12
|
-
# config.host
|
13
|
-
# config.ap_options
|
14
|
-
# config.
|
9
|
+
# config.default_level = ENV.fetch('SAPIENCE_DEFAULT_LEVEL') { :info }.to_sym
|
10
|
+
# config.backtrace_level = ENV.fetch('SAPIENCE_BACKTRACE_LEVEL') { :info }.to_sym
|
11
|
+
# config.app_name = 'TestApplication'
|
12
|
+
# config.host = ENV.fetch('SAPIENCE_HOST', nil)
|
13
|
+
# config.ap_options = { multiline: false }
|
14
|
+
# config.filter_parameters << "credit_card"
|
15
|
+
# config.appenders = [
|
15
16
|
# { stream: { io: STDOUT, formatter: :color } },
|
16
17
|
# { statsd: { url: 'udp://localhost:2222' } },
|
17
18
|
# { sentry: { dsn: 'https://foobar:443' } },
|
data/lib/sapience/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sapience
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Henriksson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-10-
|
12
|
+
date: 2016-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|