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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5db9324944116f69068168b7762d91c229899f43073008fc06346446e8742fcc
4
- data.tar.gz: 3226c9fae5efac0ec81b6410ee3e7472f680ec875f7d13a2b823df55baccb6ca
3
+ metadata.gz: 253b27b00b94bca86297424080c22fa4d64029b0795127e857573689c64e6bc0
4
+ data.tar.gz: 60a9e18dbd9ab02d0ee6e2024977bdc4fc99db6f5e54cf6a17e46a92be842bf9
5
5
  SHA512:
6
- metadata.gz: 33d67e16f158321cd26560e6b1691845b452c494593b338e7e15f677c5ada99779ff13adb0c832acdcc182010ae380ebc4f7ed331bf23110b3f75459c5d1bf24
7
- data.tar.gz: 9130cd1796969d48363c42bf11cb3a81706942c840dde91b70d2974f7c755c8d9ae985dd365294e00b81b25b190a0e39da0cca2734ae8675c00383c05a864fa4
6
+ metadata.gz: abd6f3d1791e3781b75b90f051cf994696b7aafee5652b4110a4bded2a176bcf1f1aeff4be38c47a86a36c0bc2cc69243a9d79984d8c718981172746125447ad
7
+ data.tar.gz: cd0993781e080dc276def869041a69a430e06603a46cd8110a4a6563dc4f01515fc6b50ee2c40845ef057d132f46527196eab150e89f44fe9bc76c5ecb53c9a8
@@ -35,7 +35,7 @@ module CanonicalLog
35
35
  elsif @sample_rate >= 1.0
36
36
  true
37
37
  else
38
- Sampling.default(event_hash, self)
38
+ Sampling.sample?(event_hash, self)
39
39
  end
40
40
  end
41
41
  end
@@ -52,20 +52,26 @@ module CanonicalLog
52
52
 
53
53
  config = CanonicalLog.configuration
54
54
  if config.user_context
55
- begin
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
- user = env['warden'].user rescue nil
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.default(event_hash, config)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CanonicalLog
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canonical_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Duda