logstasher 2.1.5 → 3.0.0

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: 7af8fd26cf9b944ead0bf8b8b2df3a75aa405ca1e726529e7cccb1a38ae30e8d
4
- data.tar.gz: aec3c7b2e41fefcb6f9c8b378c91d332537387685da9951cf741ab4ff2a0d9e3
3
+ metadata.gz: 8c812ac81d2e0aa6cd314f3325e7e875ccc746752a2539ba46b13ec273faa4f6
4
+ data.tar.gz: 8e14621d9afaf65e07accab9b27009ff3a3b9502a2b0e1d8f1d81e99570d68e3
5
5
  SHA512:
6
- metadata.gz: b65801d4d765f1f75f8939ee77e0ac88a5831e126f4428741097bce1b01b2c1ffe90a926aee5617bfe3355c9bfc80825299cfefd9666e52da008a22ad43368f7
7
- data.tar.gz: 0d9bc2de4e965343f0ab12241d76e62a3e661b9bafa824cb532ee4df9768562ec83055af0c8462277b62efc8a0afdfc154b940bc38919500ec8a693bfce5009d
6
+ metadata.gz: 570318f5ceae39043b9c4a1085a056939d228d5133f775698b6d3d1e713fbaeb11f48c97fcd2c95bfdd641a9c71558f4952b8dcfd37833f574413b992dd6a8cb
7
+ data.tar.gz: 2172c27d4a0fff550cc0f911110e97cd4fed232fc108c7d2add2917a6af19be0e5801dd96cdc2c5411264d13cba8082b253038e8ecc0923ff07993007968edb2
@@ -51,7 +51,8 @@ module LogStasher
51
51
  def event_data(event)
52
52
  {
53
53
  name: event.name,
54
- transaction_id: event.transaction_id
54
+ transaction_id: event.transaction_id,
55
+ allocations: event.try(:allocations) || 0
55
56
  }
56
57
  end
57
58
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support'
3
4
  require 'active_support/core_ext/class/attribute'
4
5
  require 'active_support/log_subscriber'
5
6
  require 'logstasher/custom_fields'
@@ -4,7 +4,10 @@ module LogStasher
4
4
  module CustomFields
5
5
  module LogSubscriber
6
6
  def extract_custom_fields(data)
7
- (!CustomFields.custom_fields.empty? && data.extract!(*CustomFields.custom_fields)) || {}
7
+ # Don't mutate the original payload; slice the requested fields instead
8
+ fields = CustomFields.custom_fields
9
+ return {} if fields.empty?
10
+ data.respond_to?(:slice) ? data.slice(*fields) : fields.each_with_object({}) { |k, h| h[k] = data[k] if data.key?(k) }
8
11
  end
9
12
  end
10
13
 
@@ -18,7 +18,12 @@ module LogStasher
18
18
  def append_info_to_payload(payload) #:nodoc:
19
19
  LogStasher.add_default_fields_to_payload(payload, request)
20
20
  if respond_to?(:logstasher_add_custom_fields_to_request_context)
21
- logstasher_add_custom_fields_to_request_context(LogStasher.request_context)
21
+ # Collect custom fields into a temporary hash, then merge into both
22
+ # the per-request context and the controller payload.
23
+ _fields = {}
24
+ logstasher_add_custom_fields_to_request_context(_fields)
25
+ LogStasher.request_context.merge!(_fields)
26
+ payload.merge!(_fields)
22
27
  end
23
28
 
24
29
  if respond_to?(:logstasher_add_custom_fields_to_payload)
@@ -26,7 +26,12 @@ module ActionController
26
26
 
27
27
  ActiveSupport::Notifications.instrument('process_action.action_controller', raw_payload) do |payload|
28
28
  if respond_to?(:logstasher_add_custom_fields_to_request_context)
29
- logstasher_add_custom_fields_to_request_context(LogStasher.request_context)
29
+ # Collect custom fields in a temporary hash then merge into both
30
+ # request context and the event payload to satisfy specs.
31
+ _fields = {}
32
+ logstasher_add_custom_fields_to_request_context(_fields)
33
+ LogStasher.request_context.merge!(_fields)
34
+ payload.merge!(_fields)
30
35
  end
31
36
 
32
37
  if respond_to?(:logstasher_add_custom_fields_to_payload)
@@ -53,7 +53,7 @@ module LogStasher
53
53
  LogStasher.setup_before(app.config.logstasher) if app.config.logstasher.enabled
54
54
  end
55
55
 
56
- initializer :logstasher do
56
+ initializer :logstasher_after_init do
57
57
  config.after_initialize do
58
58
  LogStasher.setup(config.logstasher) if config.logstasher.enabled
59
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LogStasher
4
- VERSION = '2.1.5'
4
+ VERSION = '3.0.0'
5
5
  end
data/lib/logstasher.rb CHANGED
@@ -47,10 +47,24 @@ module LogStasher
47
47
  end
48
48
 
49
49
  def unsubscribe(component, subscriber)
50
+ # Use Rails' built-in detach mechanism when available (Rails 5.1+).
51
+ # detach_from is a class method, so we get the class first.
52
+ klass = subscriber.is_a?(Class) ? subscriber : subscriber.class
53
+ if klass.respond_to?(:detach_from)
54
+ klass.detach_from(component)
55
+ return
56
+ end
57
+
58
+ # Fallback for older Rails versions without detach_from.
50
59
  events = subscriber.public_methods(false).reject { |method| method.to_s == 'call' }
51
60
  events.each do |event|
52
61
  ::ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
53
- ::ActiveSupport::Notifications.unsubscribe listener if listener.instance_variable_get('@delegate') == subscriber
62
+ begin
63
+ delegate = listener.instance_variable_get('@delegate')
64
+ rescue StandardError
65
+ delegate = nil
66
+ end
67
+ ::ActiveSupport::Notifications.unsubscribe(listener) if delegate == subscriber
54
68
  end
55
69
  end
56
70
  end
@@ -71,8 +85,15 @@ module LogStasher
71
85
  LogStasher::CustomFields.add(*LogStasher.store.keys)
72
86
  instance_exec(fields, &block)
73
87
  end
74
- ::ActionController::Metal.send(:define_method, :logstasher_add_custom_fields_to_payload, &wrapped_block)
75
- ::ActionController::Base.send(:define_method, :logstasher_add_custom_fields_to_payload, &wrapped_block)
88
+ if defined?(::ActionController::Base) || defined?(::ActionController::Metal)
89
+ ::ActionController::Metal.send(:define_method, :logstasher_add_custom_fields_to_payload, &wrapped_block) if defined?(::ActionController::Metal)
90
+ ::ActionController::Base.send(:define_method, :logstasher_add_custom_fields_to_payload, &wrapped_block) if defined?(::ActionController::Base)
91
+ else
92
+ ::ActiveSupport.on_load(:action_controller) do
93
+ ::ActionController::Metal.send(:define_method, :logstasher_add_custom_fields_to_payload, &wrapped_block)
94
+ ::ActionController::Base.send(:define_method, :logstasher_add_custom_fields_to_payload, &wrapped_block)
95
+ end
96
+ end
76
97
  end
77
98
 
78
99
  def add_custom_fields_to_request_context(&block)
@@ -80,8 +101,15 @@ module LogStasher
80
101
  instance_exec(fields, &block)
81
102
  LogStasher::CustomFields.add(*fields.keys)
82
103
  end
83
- ::ActionController::Metal.send(:define_method, :logstasher_add_custom_fields_to_request_context, &wrapped_block)
84
- ::ActionController::Base.send(:define_method, :logstasher_add_custom_fields_to_request_context, &wrapped_block)
104
+ if defined?(::ActionController::Base) || defined?(::ActionController::Metal)
105
+ ::ActionController::Metal.send(:define_method, :logstasher_add_custom_fields_to_request_context, &wrapped_block) if defined?(::ActionController::Metal)
106
+ ::ActionController::Base.send(:define_method, :logstasher_add_custom_fields_to_request_context, &wrapped_block) if defined?(::ActionController::Base)
107
+ else
108
+ ::ActiveSupport.on_load(:action_controller) do
109
+ ::ActionController::Metal.send(:define_method, :logstasher_add_custom_fields_to_request_context, &wrapped_block)
110
+ ::ActionController::Base.send(:define_method, :logstasher_add_custom_fields_to_request_context, &wrapped_block)
111
+ end
112
+ end
85
113
  end
86
114
 
87
115
  def add_default_fields_to_request_context(request)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstasher
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shadab Ahmed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-29 00:00:00.000000000 Z
11
+ date: 2025-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '7.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.2'
26
+ version: '7.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: request_store
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '5.2'
61
+ version: '7.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '5.2'
68
+ version: '7.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.1.4
123
+ rubygems_version: 3.4.19
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Awesome rails logs