sapience 2.9.1 → 2.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +2 -24
- data/CHANGELOG.md +19 -1
- data/README.md +48 -0
- data/docker-compose.yml +10 -5
- data/lib/sapience/base.rb +6 -2
- data/lib/sapience/configuration.rb +6 -1
- data/lib/sapience/grape.rb +2 -1
- data/lib/sapience/rails/engine.rb +6 -4
- data/lib/sapience/version.rb +1 -1
- data/sapience.gemspec +3 -3
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ef38812e94717d5c17cbc973d7aef79deb1905a
|
4
|
+
data.tar.gz: c95f1ae7e46b15e7e9bbbac99ed2bad8705cfc9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d4106483c8d8f01f3b8e869b4930f0a7a702702060d84052513a0b3ea8d481ce7df9d4eb4a352c9b9389e5306234726e2ad4ddbac5593cd19f385f9c696c993
|
7
|
+
data.tar.gz: ff0ad620ddb060381b8ce51f0579b9dcb8230920fe3bd27b594a83507584f0a74938119f1b344dbbfcd0eeb452f6399ac8ec1c8f0d54ea92be7a9004627ef107
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.4.
|
1
|
+
2.4.10
|
data/.travis.yml
CHANGED
@@ -1,27 +1,15 @@
|
|
1
1
|
sudo: required
|
2
2
|
dist: trusty
|
3
|
-
language:
|
3
|
+
language: minimal
|
4
4
|
cache:
|
5
|
-
bundler: true
|
6
5
|
directories:
|
7
6
|
- $HOME/docker
|
8
|
-
- $BUNDLE_PATH
|
9
|
-
- ./vendor/bundle
|
10
7
|
|
11
8
|
services:
|
12
9
|
- docker
|
13
10
|
|
14
|
-
before_install:
|
15
|
-
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
16
|
-
- gem install bundler -v '< 2'
|
17
|
-
|
18
|
-
install: bundle install --jobs 8 --retry 5
|
19
|
-
|
20
|
-
before_script:
|
21
|
-
- mkdir -p coverage/rails coverage/grape coverage/sapience
|
22
|
-
|
23
11
|
script:
|
24
|
-
-
|
12
|
+
- docker-compose run reevoocop
|
25
13
|
- docker-compose run rspec
|
26
14
|
- docker-compose run rails32
|
27
15
|
- docker-compose run rails42
|
@@ -29,13 +17,3 @@ script:
|
|
29
17
|
- docker-compose run grape
|
30
18
|
- docker-compose run sinatra
|
31
19
|
|
32
|
-
after_success:
|
33
|
-
- chown -R $(whoami) coverage
|
34
|
-
- bundle exec rake coverage:merge coverage:send
|
35
|
-
|
36
|
-
notifications:
|
37
|
-
slack:
|
38
|
-
on_success: change
|
39
|
-
on_failure: change
|
40
|
-
on_pull_requests: false
|
41
|
-
secure: apFwkfBQ+3NDJgcLNCHQori9qtr6ePaN3Xx7Sy7NVWwYm9BHNxoX/FN8/hxR63JjXrf1C0hK0FLQ0TiA0BN9PgEEIecg78BvWUwMClDDiwhyYN3H0Bbg35PUFtgDIrOGpu/TYlxNmdHEDYEAxaWsl9wSds8pAJsN6m7VTjGfBwJUDcOiM4L1eRpbp7smPqOjmuQFuOJnO8YkPb+6nUfz53cJrMRUdha89Vgmvnw6cP4/Ms1TsL3vKmMSVbGGh/6WNKPjU6IbuUjwlsh6a9xWxQOk6Wnis/Z+kA+T0XbLMuTLLmzRDuql1tjJeMPi+wukmK1a7GjpPkpkzAgwLQ/CkjTBfIRbMyaBYSuAciuOY8PDtCcT4WLwEvdZbkFmhAdSr1RYxIBpONVfZ/5DT3bpk71+O74OIBqxG6NmkiZ0B6u9/KxbnIINLVAcVaqsN8sdSqWlWKzPm45BfGPXGjmGGgIVFU31rs+W5Zs7IYMNUjZxabYKIv9TsBONbogfbcoGZA+rWWUnQdjypNWJS9wyQDvJ4btxqy8YhDfaV6gF30Un5JcAggMutzKJiYi+qAeh0uN3/9XoXV2N6XBnh58h8ny1NY+0vklWhtFGR1wfFAqkDskvCIZabSeJ5bFM6FtNbNKq9tYciS+eAO1vEYQVDFt9eY2uZF2mFDKRnEegHMU=
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## v2.13
|
2
|
+
- Add config option to enable/disable metrics from grape
|
3
|
+
|
4
|
+
## v2.12
|
5
|
+
- feature: 'log hooks', a mechanism for modifying the log event just before it is added to the appender
|
6
|
+
|
7
|
+
## v2.11
|
8
|
+
- Add config option to enable/disable metrics from ActionController
|
9
|
+
|
10
|
+
## v2.10
|
11
|
+
- Fix spec for Ruby 2.4.1
|
12
|
+
- Bump version to 2.10 in order to properly highlight more significant change
|
13
|
+
- Add missing Changelog entry
|
14
|
+
|
15
|
+
## v2.9.1
|
16
|
+
- Add support for sinatra applications by including `Sapience::Extensions::Sinatra::Middleware::Logging` middleware
|
17
|
+
- Bump Ruby version to 2.4.1
|
18
|
+
|
1
19
|
## v2.9.0
|
2
20
|
- Sapience will return more parameters in logs created by Rails::Rack::Logger
|
3
21
|
|
@@ -14,7 +32,7 @@
|
|
14
32
|
- Include current environment in log entries
|
15
33
|
|
16
34
|
## v2.6.2
|
17
|
-
- Bugfix: clear tags after pushing log to processing queue
|
35
|
+
- Bugfix: clear tags after pushing log to processing queue
|
18
36
|
|
19
37
|
## v2.6.1
|
20
38
|
- Bugfix: Fix sentry logging when payload is nil
|
data/README.md
CHANGED
@@ -22,6 +22,15 @@ Add the gem:
|
|
22
22
|
gem "sapience", require: "sapience/rails"
|
23
23
|
```
|
24
24
|
|
25
|
+
The rails integration has the following configuration options:
|
26
|
+
|
27
|
+
| Option | Description | Values | Default |
|
28
|
+
| --------------------- | ---------- | ------ | ----- |
|
29
|
+
| silent_rails | less noisy rails logs | `boolean` | `true` |
|
30
|
+
| silent_rack | suppress "Request Started..." log message from rack | `boolean` | `true` |
|
31
|
+
| silent_active_record | emit metrics from ActiveRecord | `boolean` | `true` |
|
32
|
+
| rails_ac_metrics | emit metrics from ActionController | `boolean` | `true` |
|
33
|
+
|
25
34
|
### Sinatra
|
26
35
|
Add the gem:
|
27
36
|
|
@@ -119,6 +128,13 @@ API.logger = Sapience.logger
|
|
119
128
|
**Note**: If you're using the rackup command to run your server in development, pass the -q flag to silence the default
|
120
129
|
rack logger so you don't get double logging.
|
121
130
|
|
131
|
+
|
132
|
+
The grape integration has the following configuration options:
|
133
|
+
|
134
|
+
| Option | Description | Values | Default |
|
135
|
+
| --------------------- | ---------- | ------ | ----- |
|
136
|
+
| grape_metrics | emit metrics from grape | `boolean` | `true` |
|
137
|
+
|
122
138
|
### Standalone
|
123
139
|
Add the gem:
|
124
140
|
|
@@ -156,6 +172,10 @@ Or if you, like us, have many projects that use the same configuration you can c
|
|
156
172
|
default:
|
157
173
|
app_name: My Application
|
158
174
|
log_level: debug
|
175
|
+
silent_active_record: true
|
176
|
+
silent_rails: true
|
177
|
+
silent_rack: true
|
178
|
+
rails_ac_metrics: true
|
159
179
|
appenders:
|
160
180
|
- stream:
|
161
181
|
io: STDOUT
|
@@ -236,6 +256,34 @@ For further details about "app_name", "filter_parameters", "appenders", "metrics
|
|
236
256
|
- [logger](docs/logger.md)
|
237
257
|
|
238
258
|
|
259
|
+
### Log hooks
|
260
|
+
*Log hooks* allow us to modify the log object **Sapience::Log** just before it is added to the appender. A 'log hook' can be an object that responds to #call. Multiple hooks can be used.
|
261
|
+
The following examples show how to use hooks to:
|
262
|
+
|
263
|
+
* inject Datadog APM tracing data in every log event.
|
264
|
+
* modify the logs event's **message** field.
|
265
|
+
|
266
|
+
```ruby
|
267
|
+
my_logger = Sapience.logger
|
268
|
+
|
269
|
+
# inject Datadog tracing info in payload hash
|
270
|
+
my_logger.log_hooks << ->(log) do
|
271
|
+
trace_data = {
|
272
|
+
dd: {
|
273
|
+
span_id: ::Datadog.tracer.active_correlation.span_id.to_s,
|
274
|
+
trace_id: ::Datadog.tracer.active_correlation.trace_id.to_s
|
275
|
+
}
|
276
|
+
}
|
277
|
+
log.payload? ? log.payload.merge!(trace_data) : log.payload = trace_data
|
278
|
+
end
|
279
|
+
|
280
|
+
# append number of times a GC occurred since process started in field 'message'
|
281
|
+
my_logger.log_hooks << ->(log) do
|
282
|
+
log.message = "#{log.message} = GC count: #{GC.count}"
|
283
|
+
end
|
284
|
+
```
|
285
|
+
|
286
|
+
|
239
287
|
## Running the tests
|
240
288
|
|
241
289
|
You need to create the test postgres db, by running the command below:
|
data/docker-compose.yml
CHANGED
@@ -8,13 +8,13 @@ services:
|
|
8
8
|
RABBITMQ_DEFAULT_PASS: tests
|
9
9
|
|
10
10
|
postgres:
|
11
|
-
image: postgres:
|
11
|
+
image: postgres:9
|
12
12
|
environment:
|
13
13
|
POSTGRES_USER: sapience
|
14
14
|
POSTGRES_PASSWORD: tests
|
15
15
|
|
16
16
|
base:
|
17
|
-
image: ruby:2.
|
17
|
+
image: ruby:2.4
|
18
18
|
cpu_shares: 4
|
19
19
|
# Specify the directory from where all commands sent to the container will be
|
20
20
|
# issued to where the code is mounted:
|
@@ -32,7 +32,13 @@ services:
|
|
32
32
|
# "/usr/src/app" folder:
|
33
33
|
- .:/usr/src/app
|
34
34
|
|
35
|
-
|
35
|
+
reevoocop:
|
36
|
+
extends:
|
37
|
+
service: base
|
38
|
+
entrypoint: /usr/src/app/dev-entrypoint.sh
|
39
|
+
command: bundle exec rake reevoocop
|
40
|
+
environment:
|
41
|
+
PATH: /usr/src/app/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
36
42
|
|
37
43
|
rspec:
|
38
44
|
extends:
|
@@ -46,11 +52,10 @@ services:
|
|
46
52
|
PATH: /usr/src/app/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
47
53
|
|
48
54
|
|
49
|
-
|
50
55
|
rails32:
|
51
56
|
extends:
|
52
57
|
service: base
|
53
|
-
image: ruby:2.
|
58
|
+
image: ruby:2.3
|
54
59
|
working_dir: /usr/src/app/test_apps/rails_3_2
|
55
60
|
entrypoint: /usr/src/app/dev-entrypoint.sh
|
56
61
|
command: bundle exec rspec
|
data/lib/sapience/base.rb
CHANGED
@@ -3,7 +3,7 @@ module Sapience
|
|
3
3
|
# rubocop:disable ClassLength
|
4
4
|
class Base
|
5
5
|
# Class name to be logged
|
6
|
-
attr_accessor :name, :filter
|
6
|
+
attr_accessor :name, :filter, :log_hooks
|
7
7
|
include Sapience::LogMethods
|
8
8
|
|
9
9
|
# Set the logging level for this logger
|
@@ -174,7 +174,7 @@ module Sapience
|
|
174
174
|
# Proc: Only include log messages where the supplied Proc returns true
|
175
175
|
# The Proc must return true or false
|
176
176
|
# rubocop:disable AbcSize, PerceivedComplexity, CyclomaticComplexity, LineLength
|
177
|
-
def initialize(klass, level = nil, filter = nil)
|
177
|
+
def initialize(klass, level = nil, filter = nil, log_hooks = [])
|
178
178
|
# Support filtering all messages to this logger using a Regular Expression
|
179
179
|
# or Proc
|
180
180
|
fail ArgumentError, ":filter must be a Regexp or Proc" unless filter.nil? || filter.is_a?(Regexp) || filter.is_a?(Proc)
|
@@ -183,6 +183,7 @@ module Sapience
|
|
183
183
|
@name = klass if klass.is_a?(String)
|
184
184
|
@name ||= klass.name if klass.respond_to?(:name)
|
185
185
|
@name ||= klass.class.name
|
186
|
+
@log_hooks = log_hooks
|
186
187
|
|
187
188
|
if level.nil?
|
188
189
|
# Allow the global default level to determine this loggers log level
|
@@ -271,6 +272,9 @@ module Sapience
|
|
271
272
|
end
|
272
273
|
log.payload = payload unless payload.empty?
|
273
274
|
end
|
275
|
+
|
276
|
+
log_hooks.each { |h| h.call(log) }
|
277
|
+
|
274
278
|
self.log(log) if include_message?(log)
|
275
279
|
end
|
276
280
|
# rubocop:enable AbcSize, PerceivedComplexity, CyclomaticComplexity, LineLength
|
@@ -8,7 +8,8 @@ module Sapience
|
|
8
8
|
attr_reader :default_level, :backtrace_level, :backtrace_level_index
|
9
9
|
attr_writer :host
|
10
10
|
attr_accessor :app_name, :ap_options, :appenders, :log_executor, :filter_parameters,
|
11
|
-
:metrics, :error_handler, :silent_active_record, :silent_rails, :silent_rack
|
11
|
+
:metrics, :error_handler, :silent_active_record, :silent_rails, :silent_rack,
|
12
|
+
:rails_ac_metrics, :grape_metrics
|
12
13
|
|
13
14
|
SUPPORTED_EXECUTORS = %i(single_thread_executor immediate_executor).freeze
|
14
15
|
DEFAULT = {
|
@@ -23,6 +24,8 @@ module Sapience
|
|
23
24
|
silent_active_record: false,
|
24
25
|
silent_rails: false,
|
25
26
|
silent_rack: false,
|
27
|
+
rails_ac_metrics: true,
|
28
|
+
grape_metrics: true,
|
26
29
|
}.freeze
|
27
30
|
|
28
31
|
# Initial default Level for all new instances of Sapience::Logger
|
@@ -44,6 +47,8 @@ module Sapience
|
|
44
47
|
self.silent_active_record = @options[:silent_active_record]
|
45
48
|
self.silent_rails = @options[:silent_rails]
|
46
49
|
self.silent_rack = @options[:silent_rack]
|
50
|
+
self.rails_ac_metrics = @options[:rails_ac_metrics]
|
51
|
+
self.grape_metrics = @options[:grape_metrics]
|
47
52
|
end
|
48
53
|
|
49
54
|
# Sets the global default log level
|
data/lib/sapience/grape.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "sapience"
|
3
3
|
require "sapience/extensions/grape/timings"
|
4
|
+
require "grape"
|
4
5
|
require "sapience/extensions/grape/middleware/logging"
|
5
6
|
require "sapience/extensions/grape/notifications"
|
6
7
|
|
@@ -18,6 +19,6 @@ module Sapience
|
|
18
19
|
end
|
19
20
|
Sapience.configure
|
20
21
|
::Grape::API.send(:include, Sapience::Loggable)
|
21
|
-
Sapience::Extensions::Grape::Notifications.use
|
22
|
+
Sapience::Extensions::Grape::Notifications.use if Sapience.config.grape_metrics
|
22
23
|
end
|
23
24
|
end
|
@@ -42,12 +42,14 @@ module Sapience
|
|
42
42
|
# Replace the Sidekiq logger
|
43
43
|
Sidekiq::Logging.logger = Sapience[Sidekiq] if defined?(Sidekiq)
|
44
44
|
|
45
|
-
# Replace the Sequel logger
|
46
|
-
Sequel::Database.logger = Sapience[Sequel] if defined?(Sequel::Database)
|
47
|
-
|
48
45
|
# Replace the Sidetiq logger
|
49
46
|
Sidetiq.logger = Sapience[Sidetiq] if defined?(Sidetiq)
|
50
47
|
|
48
|
+
# Replace the Sequel logger
|
49
|
+
if defined?(Sequel::Database) && Sequel::Database.respond_to?(:logger=)
|
50
|
+
Sequel::Database.logger = Sapience[Sequel]
|
51
|
+
end
|
52
|
+
|
51
53
|
# Replace the Raven logger
|
52
54
|
# Raven::Configuration.logger = Sapience[Raven::Configuration] if defined?(Raven::Configuration)
|
53
55
|
Raven.send(:include, Sapience::Loggable)
|
@@ -83,7 +85,7 @@ module Sapience
|
|
83
85
|
end
|
84
86
|
Sapience::Extensions::ActionView::LogSubscriber.attach_to :action_view
|
85
87
|
# Sapience::Extensions::ActiveJob::LogSubscriber.attach_to :active_job
|
86
|
-
Sapience::Extensions::ActionController::Notifications.use
|
88
|
+
Sapience::Extensions::ActionController::Notifications.use if Sapience.config.rails_ac_metrics
|
87
89
|
Sapience::Extensions::ActiveJob::Notifications.use if defined?(ActiveJob)
|
88
90
|
end
|
89
91
|
end
|
data/lib/sapience/version.rb
CHANGED
data/sapience.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_dependency "concurrent-ruby", "~> 1.0"
|
29
29
|
spec.add_development_dependency "active_model_serializers", "~> 0.10.0"
|
30
30
|
spec.add_development_dependency "appraisal"
|
31
|
-
spec.add_development_dependency "bundler"
|
31
|
+
spec.add_development_dependency "bundler"
|
32
32
|
spec.add_development_dependency "codeclimate-test-reporter"
|
33
33
|
spec.add_development_dependency "dogstatsd-ruby", "~> 2.0"
|
34
34
|
spec.add_development_dependency "fuubar"
|
@@ -36,8 +36,8 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_development_dependency "grape"
|
37
37
|
spec.add_development_dependency "memory_profiler"
|
38
38
|
spec.add_development_dependency "pry-nav"
|
39
|
-
spec.add_development_dependency "rails", "~> 5.0
|
40
|
-
spec.add_development_dependency "rake"
|
39
|
+
spec.add_development_dependency "rails", "~> 5.0"
|
40
|
+
spec.add_development_dependency "rake"
|
41
41
|
spec.add_development_dependency "reevoocop"
|
42
42
|
spec.add_development_dependency "rspec", "~> 3.0"
|
43
43
|
spec.add_development_dependency "rspec-its"
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sapience
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: '2.14'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Henriksson
|
8
8
|
- Alex Malkov
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-03-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -57,16 +57,16 @@ dependencies:
|
|
57
57
|
name: bundler
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: codeclimate-test-reporter
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,28 +171,28 @@ dependencies:
|
|
171
171
|
requirements:
|
172
172
|
- - "~>"
|
173
173
|
- !ruby/object:Gem::Version
|
174
|
-
version: 5.0
|
174
|
+
version: '5.0'
|
175
175
|
type: :development
|
176
176
|
prerelease: false
|
177
177
|
version_requirements: !ruby/object:Gem::Requirement
|
178
178
|
requirements:
|
179
179
|
- - "~>"
|
180
180
|
- !ruby/object:Gem::Version
|
181
|
-
version: 5.0
|
181
|
+
version: '5.0'
|
182
182
|
- !ruby/object:Gem::Dependency
|
183
183
|
name: rake
|
184
184
|
requirement: !ruby/object:Gem::Requirement
|
185
185
|
requirements:
|
186
|
-
- - "
|
186
|
+
- - ">="
|
187
187
|
- !ruby/object:Gem::Version
|
188
|
-
version: '
|
188
|
+
version: '0'
|
189
189
|
type: :development
|
190
190
|
prerelease: false
|
191
191
|
version_requirements: !ruby/object:Gem::Requirement
|
192
192
|
requirements:
|
193
|
-
- - "
|
193
|
+
- - ">="
|
194
194
|
- !ruby/object:Gem::Version
|
195
|
-
version: '
|
195
|
+
version: '0'
|
196
196
|
- !ruby/object:Gem::Dependency
|
197
197
|
name: reevoocop
|
198
198
|
requirement: !ruby/object:Gem::Requirement
|
@@ -389,7 +389,7 @@ licenses:
|
|
389
389
|
- MIT
|
390
390
|
metadata:
|
391
391
|
allowed_push_host: https://rubygems.org
|
392
|
-
post_install_message:
|
392
|
+
post_install_message:
|
393
393
|
rdoc_options: []
|
394
394
|
require_paths:
|
395
395
|
- lib
|
@@ -404,9 +404,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
404
404
|
- !ruby/object:Gem::Version
|
405
405
|
version: '0'
|
406
406
|
requirements: []
|
407
|
-
rubyforge_project:
|
408
|
-
rubygems_version: 2.6.
|
409
|
-
signing_key:
|
407
|
+
rubyforge_project:
|
408
|
+
rubygems_version: 2.6.14.4
|
409
|
+
signing_key:
|
410
410
|
specification_version: 4
|
411
411
|
summary: Hasslefree autoconfiguration for logging, metrics and exception collection.
|
412
412
|
test_files: []
|