md-logstasher 1.3.0 → 1.4.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: 91f47cc71b8a9c6f01e3f12661c11922040c2c0acf6be1882eee182fffca6aba
4
- data.tar.gz: dd9494bd0f46ef6b01a9c5df6166794db82a0fdc563e06df0555efb2acba7472
3
+ metadata.gz: 5f6a2e729c225c8fb2cf06174d9fc5282ae0b2ee660fd89d675a30e7fcd19eb3
4
+ data.tar.gz: 9a8dea2258d1ed2c0fb1c01227bf7ea6b78421ca342ba122a32cc8f1351b7440
5
5
  SHA512:
6
- metadata.gz: e486d0d8eef5bd325d700fcf1685bf1d26f8a1764dc32c8e054f35cca64d5a9a2a8aed18bc75441ceeb536902cae59ffd7ea76013aea959dd89e0453d8907f66
7
- data.tar.gz: 1d836f746425a75131f82db774c25a6ec5a9fb0ad34680884b88bb4946c4b7413be9a76b231cbc2810f1477e484e655ad596af871dcb9fb2689d66ce20a75e59
6
+ metadata.gz: d23d146376ea21233a2b1189366586cbecc46f4a5694ffb1b7cae480881098828f7e9e79f171cf7f1c52372b793f53aff40d86dd444a4aee4e8a12e9334e2e7a
7
+ data.tar.gz: f6a8c91e937935dac803868c098e8b6826cb0b27f72fe5718bf8fcebad2685acdeb899e8055d6ee6cc2a4420bcf3465a7e3557e99875b8b2fbf8fbccd5c90618
@@ -21,7 +21,6 @@ module LogStasher
21
21
  payload = event.payload
22
22
  tags = extract_tags(payload)
23
23
  fields = extract_request(payload)
24
-
25
24
  fields.merge! extract_status(payload)
26
25
  fields.merge! runtimes(event)
27
26
  fields.merge! location
@@ -52,7 +51,7 @@ module LogStasher
52
51
  end
53
52
 
54
53
  def extract_request(payload)
55
- {
54
+ result = {
56
55
  :action => payload[:action],
57
56
  :controller => payload[:controller],
58
57
  :format => extract_format(payload),
@@ -62,6 +61,9 @@ module LogStasher
62
61
  :path => extract_path(payload),
63
62
  :route => "#{payload[:controller]}##{payload[:action]}"
64
63
  }
64
+ metadata = ::LogStasher.metadata
65
+ result.merge!(:metadata => metadata) unless metadata&.empty?
66
+ result
65
67
  end
66
68
 
67
69
  # Monkey patching to enable exception logging
@@ -87,7 +89,6 @@ module LogStasher
87
89
  def extract_parameters(payload)
88
90
  if LogStasher.include_parameters?
89
91
  external_params = payload[:params].except(*INTERNAL_PARAMS)
90
-
91
92
  if LogStasher.serialize_parameters?
92
93
  { :params => JSON.generate(external_params) }
93
94
  else
@@ -8,6 +8,7 @@ module LogStasher
8
8
  config.logstasher.logger = nil
9
9
  config.logstasher.log_level = ::Logger::INFO
10
10
 
11
+ config.logstasher.metadata = {}
11
12
  config.before_initialize do
12
13
  options = config.logstasher
13
14
 
@@ -17,6 +18,7 @@ module LogStasher
17
18
  ::LogStasher.silence_standard_logging = options.silence_standard_logging
18
19
  ::LogStasher.logger = options.logger || default_logger
19
20
  ::LogStasher.logger.level = options.log_level
21
+ ::LogStasher.metadata = options.metadata
20
22
  end
21
23
 
22
24
  initializer 'logstasher.load' do
@@ -1,3 +1,3 @@
1
1
  module LogStasher
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
data/lib/logstasher.rb CHANGED
@@ -8,6 +8,7 @@ module LogStasher
8
8
  attr_writer :include_parameters
9
9
  attr_writer :serialize_parameters
10
10
  attr_writer :silence_standard_logging
11
+ attr_accessor :metadata
11
12
 
12
13
  def append_fields(&block)
13
14
  @append_fields_callback = block
@@ -10,6 +10,12 @@ class MockController
10
10
  end
11
11
 
12
12
  class MockRequest
13
+ attr_accessor :env
14
+
15
+ def initialize
16
+ @env = { 'action_dispatch.request_id' => 1 }
17
+ end
18
+
13
19
  def remote_ip
14
20
  '127.0.0.1'
15
21
  end
@@ -19,6 +25,7 @@ describe LogStasher::LogSubscriber do
19
25
  subject { described_class.new }
20
26
 
21
27
  let(:logger) { ::Logger.new('/dev/null') }
28
+
22
29
  let(:mock_controller) { MockController.new }
23
30
  let(:mock_request) { MockRequest.new }
24
31
  let(:context) {{ :controller => mock_controller, :request => mock_request }}
@@ -46,10 +53,12 @@ describe LogStasher::LogSubscriber do
46
53
  :path => '/users/1',
47
54
  :status => 200
48
55
  }}
56
+ let(:data) { { "namespace" => "test", "appversion" => "v1" } }
49
57
 
50
58
  let(:event) { double(:payload => payload, :duration => duration) }
51
59
 
52
60
  it 'logs the event in logstash format' do
61
+ ::LogStasher.metadata = data
53
62
  expect(logger).to receive(:<<) do |json|
54
63
  expect(JSON.parse(json)).to eq({
55
64
  '@timestamp' => timestamp,
@@ -64,7 +73,9 @@ describe LogStasher::LogSubscriber do
64
73
  'path' => payload[:path],
65
74
  'route' => "#{payload[:controller]}##{payload[:action]}",
66
75
  'status' => payload[:status],
67
- 'runtime' => { 'total' => duration }
76
+ 'runtime' => { 'total' => duration },
77
+ 'request_id' => 1,
78
+ 'metadata' => data
68
79
  })
69
80
  end
70
81
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md-logstasher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devin Christensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-05 00:00:00.000000000 Z
11
+ date: 2022-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-event