canonical_log 0.1.1 → 0.1.2
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/lib/canonical_log/configuration.rb +1 -1
- data/lib/canonical_log/middleware.rb +22 -10
- data/lib/canonical_log/sampling.rb +1 -1
- data/lib/canonical_log/version.rb +1 -1
- data/lib/canonical_log.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 253b27b00b94bca86297424080c22fa4d64029b0795127e857573689c64e6bc0
|
|
4
|
+
data.tar.gz: 60a9e18dbd9ab02d0ee6e2024977bdc4fc99db6f5e54cf6a17e46a92be842bf9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: abd6f3d1791e3781b75b90f051cf994696b7aafee5652b4110a4bded2a176bcf1f1aeff4be38c47a86a36c0bc2cc69243a9d79984d8c718981172746125447ad
|
|
7
|
+
data.tar.gz: cd0993781e080dc276def869041a69a430e06603a46cd8110a4a6563dc4f01515fc6b50ee2c40845ef057d132f46527196eab150e89f44fe9bc76c5ecb53c9a8
|
|
@@ -52,20 +52,26 @@ module CanonicalLog
|
|
|
52
52
|
|
|
53
53
|
config = CanonicalLog.configuration
|
|
54
54
|
if config.user_context
|
|
55
|
-
|
|
56
|
-
user_fields = config.user_context.call(env)
|
|
57
|
-
event.add(user_fields) if user_fields.is_a?(Hash)
|
|
58
|
-
rescue StandardError => e
|
|
59
|
-
warn "[CanonicalLog] user_context error: #{e.message}"
|
|
60
|
-
end
|
|
55
|
+
enrich_from_user_context_proc(env, event, config)
|
|
61
56
|
elsif defined?(Warden::Manager) && env['warden']
|
|
62
|
-
|
|
63
|
-
if user
|
|
64
|
-
event.context(:user, id: user.try(:id), email: user.try(:email))
|
|
65
|
-
end
|
|
57
|
+
enrich_from_warden(env, event)
|
|
66
58
|
end
|
|
67
59
|
end
|
|
68
60
|
|
|
61
|
+
def enrich_from_user_context_proc(env, event, config)
|
|
62
|
+
user_fields = config.user_context.call(env)
|
|
63
|
+
event.add(user_fields) if user_fields.is_a?(Hash)
|
|
64
|
+
rescue StandardError => e
|
|
65
|
+
warn "[CanonicalLog] user_context error: #{e.message}"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def enrich_from_warden(env, event)
|
|
69
|
+
user = env['warden'].user
|
|
70
|
+
event.context(:user, id: user.try(:id), email: user.try(:email)) if user
|
|
71
|
+
rescue StandardError
|
|
72
|
+
nil
|
|
73
|
+
end
|
|
74
|
+
|
|
69
75
|
def emit!
|
|
70
76
|
event = Context.current
|
|
71
77
|
return unless event
|
|
@@ -76,6 +82,8 @@ module CanonicalLog
|
|
|
76
82
|
event_hash = event.to_h
|
|
77
83
|
return unless config.should_sample?(event_hash)
|
|
78
84
|
|
|
85
|
+
event_hash[:message] ||= build_message(event_hash)
|
|
86
|
+
|
|
79
87
|
json = event_hash.to_json
|
|
80
88
|
|
|
81
89
|
config.resolved_sinks.each do |sink|
|
|
@@ -87,6 +95,10 @@ module CanonicalLog
|
|
|
87
95
|
warn "[CanonicalLog] Emit error: #{e.message}"
|
|
88
96
|
end
|
|
89
97
|
|
|
98
|
+
def build_message(event_hash)
|
|
99
|
+
[event_hash[:http_method], event_hash[:path], event_hash[:http_status]].compact.join(' ')
|
|
100
|
+
end
|
|
101
|
+
|
|
90
102
|
def ignored_path?(env)
|
|
91
103
|
path = env['PATH_INFO']
|
|
92
104
|
CanonicalLog.configuration.ignored_paths.any? do |pattern|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module CanonicalLog
|
|
4
4
|
module Sampling
|
|
5
5
|
# Default sampling: always keep errors and slow requests, sample the rest.
|
|
6
|
-
def self.
|
|
6
|
+
def self.sample?(event_hash, config)
|
|
7
7
|
status = event_hash[:http_status] || 0
|
|
8
8
|
duration = event_hash[:duration_ms] || 0
|
|
9
9
|
|
data/lib/canonical_log.rb
CHANGED
|
@@ -13,6 +13,8 @@ require_relative 'canonical_log/sinks/stdout'
|
|
|
13
13
|
require_relative 'canonical_log/sinks/rails_logger'
|
|
14
14
|
require_relative 'canonical_log/subscribers/action_controller'
|
|
15
15
|
require_relative 'canonical_log/subscribers/active_record'
|
|
16
|
+
require_relative 'canonical_log/integrations/error_enrichment'
|
|
17
|
+
require_relative 'canonical_log/integrations/sidekiq' if defined?(Sidekiq)
|
|
16
18
|
|
|
17
19
|
require_relative 'canonical_log/railtie' if defined?(Rails::Railtie)
|
|
18
20
|
|