infinum_graylog 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49569ea1e932e8f9252b96592f7e934932311273f799e320be8caea2e25936cf
4
- data.tar.gz: 5dac3718045d2ae7542a7285ae226e69cddf04b28e345e40e07dff3505029ee1
3
+ metadata.gz: 3c45c6c7d40d3f7b1e94bf35cb63e0f351ed1f05bf8f0ba637124747da3a78da
4
+ data.tar.gz: d05fb525dc2a5366283b5b6b283afc16fbaf21056bd26d727370b2a0797eea2a
5
5
  SHA512:
6
- metadata.gz: fd5bad3f451ab0dafb635dfd58c0750197803b940360ce12db68b1517d761b0273fbdff351da8c196cb3da293f75bdaf116f92083656ef2e72e8de7a954fd78e
7
- data.tar.gz: 14f9c4bf3f901aea6f492adc656cd07e13a3b5bd678c442cdec87375088874574d7a0149e8bbc0c89d60692bb98503d1c41eb34128f94eec1104a6fe2c3e86ff
6
+ metadata.gz: 7b1706a9b905d35ee7434920dfa64d9b0fc438bd7228d88a3ff37d95505ec2ae74c44610c3ad6e28f8bf65a5b847033337225276c04097b3a57102cd16242fcc
7
+ data.tar.gz: 2e04061f26cf94800db497ae3f769c1651601217d1b616e5e7a51daebd77d519c9dbee7de6eeb5839ee6ee757f3eb5b69637abaad3a0b31983266a4eebaa4992
data/Gemfile.lock CHANGED
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- infinum_graylog (0.1.0)
4
+ infinum_graylog (0.5.0)
5
5
  gelf
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  diff-lcs (1.3)
11
- gelf (3.0.0)
11
+ gelf (3.1.0)
12
12
  json
13
- json (2.1.0)
13
+ json (2.2.0)
14
14
  rake (10.5.0)
15
15
  rspec (3.8.0)
16
16
  rspec-core (~> 3.8.0)
@@ -1,5 +1,4 @@
1
-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'infinum_graylog/version'
5
4
 
@@ -23,7 +22,7 @@ Gem::Specification.new do |spec|
23
22
  'public gem pushes.'
24
23
  end
25
24
 
26
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
26
  f.match(%r{^(test|spec|features)/})
28
27
  end
29
28
  spec.bindir = 'exe'
@@ -0,0 +1,13 @@
1
+ module InfinumGraylog
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ request = ActionDispatch::Request.new(env)
9
+ InfinumGraylog::Notifier.request_id = request.request_id
10
+ @app.call(env)
11
+ end
12
+ end
13
+ end
@@ -8,26 +8,39 @@ module InfinumGraylog
8
8
  end
9
9
 
10
10
  def notify(payload)
11
- @notifier.notify!(payload)
11
+ payload = payload.merge(request_id: request_id)
12
+ Thread.new { @notifier.notify!(payload) }.join
13
+ end
14
+
15
+ def thread_key
16
+ @thread_key ||= "infinum_graylog_notifier:#{object_id}"
12
17
  end
13
18
 
14
19
  def self.notify(payload)
15
- return unless payload.present?
20
+ return if payload.blank?
21
+
16
22
  instance.notify(payload)
17
23
  end
18
24
 
25
+ def self.request_id=(request_id)
26
+ Thread.current[instance.thread_key] = request_id
27
+ end
28
+
19
29
  private
20
30
 
21
31
  def options
22
32
  {
23
33
  protocol: configuration.protocol,
24
- level: configuration.level,
34
+ level: configuration.level
25
35
  }.merge(configuration.options)
26
36
  end
27
37
 
28
38
  def configuration
29
- InfinumGraylog.configuration
39
+ @configuration ||= InfinumGraylog.configuration
40
+ end
41
+
42
+ def request_id
43
+ Thread.current[thread_key] || SecureRandom.hex
30
44
  end
31
45
  end
32
46
  end
33
-
@@ -40,7 +40,7 @@ module InfinumGraylog
40
40
  return nil unless event.payload[:headers]
41
41
  headers = {}
42
42
 
43
- event.payload[:headers].each_pair do |key, value|
43
+ event.payload[:headers].each do |key, value|
44
44
  if key.to_s.start_with?("HTTP_")
45
45
  header_key = key[5..-1]
46
46
  elsif ["CONTENT_TYPE", "CONTENT_LENGTH"].include?(key)
@@ -0,0 +1,7 @@
1
+ module InfinumGraylog
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'infinum_graylog.insert_middleware' do |app|
4
+ app.config.middleware.insert_after ActionDispatch::RequestId, InfinumGraylog::Middleware
5
+ end
6
+ end
7
+ end
@@ -1,17 +1,27 @@
1
1
  module InfinumGraylog
2
2
  class Subscriber
3
3
  def self.subscribe
4
- unless InfinumGraylog.configuration.skip_environments.include?(Rails.env)
5
- ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |*args|
6
- event = ActiveSupport::Notifications::Event.new(*args)
7
- Notifier.notify(ProcessActionController.new(event).format)
8
- end
4
+ return unless tls_and_files_exist?
5
+ return if InfinumGraylog.configuration.skip_environments.include?(Rails.env)
9
6
 
10
- ActiveSupport::Notifications.subscribe 'sql.active_record' do |*args|
11
- event = ActiveSupport::Notifications::Event.new(*args)
12
- Notifier.notify(SqlActiveRecord.new(event).format)
13
- end
7
+ puts '[InfinumGraylog] notifications configured'
8
+
9
+ ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |*args|
10
+ event = ActiveSupport::Notifications::Event.new(*args)
11
+ Notifier.notify(ProcessActionController.new(event).format)
12
+ end
13
+
14
+ ActiveSupport::Notifications.subscribe 'sql.active_record' do |*args|
15
+ event = ActiveSupport::Notifications::Event.new(*args)
16
+ Notifier.notify(SqlActiveRecord.new(event).format)
14
17
  end
15
18
  end
19
+
20
+ def self.tls_and_files_exist?
21
+ tls_configuration = InfinumGraylog.configuration.options[:tls]
22
+
23
+ tls_configuration.present? &&
24
+ File.exist?(tls_configuration[:cert]) && File.exist?(tls_configuration[:key])
25
+ end
16
26
  end
17
27
  end
@@ -1,3 +1,3 @@
1
1
  module InfinumGraylog
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -6,6 +6,8 @@ require 'infinum_graylog/process_action_controller'
6
6
  require 'infinum_graylog/sql_active_record'
7
7
  require 'infinum_graylog/notifier'
8
8
  require 'infinum_graylog/subscriber'
9
+ require 'infinum_graylog/middleware'
10
+ require 'infinum_graylog/railtie' if defined?(Rails::Railtie)
9
11
 
10
12
  module InfinumGraylog
11
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infinum_graylog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stjepan Hadjic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-13 00:00:00.000000000 Z
11
+ date: 2019-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,8 +88,10 @@ files:
88
88
  - lib/infinum_graylog.rb
89
89
  - lib/infinum_graylog/cleaner.rb
90
90
  - lib/infinum_graylog/configuration.rb
91
+ - lib/infinum_graylog/middleware.rb
91
92
  - lib/infinum_graylog/notifier.rb
92
93
  - lib/infinum_graylog/process_action_controller.rb
94
+ - lib/infinum_graylog/railtie.rb
93
95
  - lib/infinum_graylog/sql_active_record.rb
94
96
  - lib/infinum_graylog/subscriber.rb
95
97
  - lib/infinum_graylog/version.rb
@@ -114,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
116
  version: '0'
115
117
  requirements: []
116
118
  rubyforge_project:
117
- rubygems_version: 2.7.3
119
+ rubygems_version: 2.7.6
118
120
  signing_key:
119
121
  specification_version: 4
120
122
  summary: summary