kiev 2.8.0 → 4.3.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
- SHA1:
3
- metadata.gz: c95641b776dbecacfb3c20627bdca29ed253a5a5
4
- data.tar.gz: 04e91ef07a297c90b94011b115e429a188b2df5e
2
+ SHA256:
3
+ metadata.gz: 077b62ba98a1a883bb9cf7596983156864e1011bdb189ee80cc1d0e8e4039c08
4
+ data.tar.gz: beb8bdd2f1d31501d5ef4d501d221c1fabe522b9a106e4f7bb150e46aa168029
5
5
  SHA512:
6
- metadata.gz: 84dd23df61159eac642eb93dfa14d97b4cfb354159dc3afa51626640ecd66106282d0414b508764ff40b2be04ef4d5e71852bd974ab7973d380b78f6bac4ff0a
7
- data.tar.gz: 016ed238aa2aabf377acd7796577d95c13b10ac0d065a5ef02560fef5520ac30b5e24ebfbed3613479ade39cf88eaded5526115683e08de4ac8b69830ae37c8d
6
+ metadata.gz: bb2ff70083d47ac226628cb796f34f607454c6db6b458a63cca06fdbf014a75f28d02ddc29a7b9caf8e4c309148b0adfbfc0a4cdbafcf1030d4e7996a65cf4f5
7
+ data.tar.gz: 3fb4a342b5d0b475da14cd99f553ee3b5ee02a1f299f11e2d1afb0ab11353672a14373850b657ca9cc755d6d4474439d32d95b09bc94177c749f9b04eda71a3e
@@ -3,8 +3,8 @@ inherit_from:
3
3
 
4
4
  Lint/HandleExceptions:
5
5
  Exclude:
6
- - test/rails_integration_test.rb
7
- - test/sinatra_integration_test.rb
6
+ - test/**/*.rb
7
+ - spec/**/*.rb
8
8
  Lint/RescueException:
9
9
  Exclude:
10
10
  - lib/kiev/request_body_filter/json.rb
data/README.md CHANGED
@@ -107,6 +107,35 @@ end
107
107
  run(app)
108
108
  ```
109
109
 
110
+ ### Hanami
111
+
112
+ Place your configuration under `config/initializers/kiev.rb`:
113
+
114
+ ```ruby
115
+ require "kiev"
116
+
117
+ Kiev.configure do |config|
118
+ config.app = :my_app
119
+ config.development_mode = Hanami.env?(:development)
120
+ config.log_path = File.join("log", "structured.log")
121
+ end
122
+ ```
123
+
124
+ Within your `MyApp::Application` file, include the `Kiev::Hanami` module, in order to register the middleware stack.
125
+ The `include` should be added before `configure` block.
126
+
127
+ ```ruby
128
+ module MyApp
129
+ class Application < Hanami::Application
130
+ include Kiev::Hanami
131
+
132
+ configure do
133
+ # ...
134
+ end
135
+ end
136
+ end
137
+ ```
138
+
110
139
  ### Sidekiq
111
140
 
112
141
  Add the following lines to your initializer code:
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gem "oj"
4
4
 
5
5
  gem "rails", "4.1.16"
6
- gem "sqlite3"
6
+ gem "sqlite3", "1.3.13"
7
7
 
8
8
  gem "combustion"
9
9
  gem "rspec", require: false
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gem "oj"
4
4
 
5
5
  gem "rails", "4.2.7"
6
- gem "sqlite3"
6
+ gem "sqlite3", "1.3.13"
7
7
 
8
8
  gem "combustion"
9
9
  gem "rspec", require: false
@@ -12,6 +12,7 @@ require_relative "version"
12
12
  require_relative "config"
13
13
  require_relative "util"
14
14
  require_relative "subrequest_helper"
15
+ require_relative "hanami"
15
16
 
16
17
  module Kiev
17
18
  class << self
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "rack/request_logger"
4
+ require_relative "rack/store_request_details"
5
+ require_relative "rack/request_id"
6
+
7
+ module Kiev
8
+ module Hanami
9
+ def self.included(base)
10
+ base.configure do
11
+ # The order is important
12
+ middleware.use(::RequestStore::Middleware)
13
+ middleware.use(Kiev::Rack::RequestLogger)
14
+ middleware.use(Kiev::Rack::StoreRequestDetails)
15
+ middleware.use(Kiev::Rack::RequestId)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -13,6 +13,8 @@ module Kiev
13
13
  def_delegators(*([:@logger] + ::Logger.instance_methods(false)))
14
14
 
15
15
  DEFAULT_EVENT_NAME = "log"
16
+ LOG_ERROR = "ERROR"
17
+ ERROR_STATUS = 500
16
18
 
17
19
  FORMATTER = proc do |severity, time, event_name, data|
18
20
  entry =
@@ -54,8 +56,11 @@ module Kiev
54
56
  entry.merge!(data)
55
57
  elsif !data.nil?
56
58
  entry[:message] = data.to_s
59
+ entry[:status] = ERROR_STATUS if data.to_s.downcase.include?(LOG_ERROR)
57
60
  end
58
61
 
62
+ entry[:level] = LOG_ERROR if entry[:status].to_i.between?(400, 599)
63
+
59
64
  # Save some disk space
60
65
  entry.reject! { |_, value| value.nil? }
61
66
 
@@ -27,6 +27,7 @@ module Kiev
27
27
  private
28
28
 
29
29
  NEW_LINE = "\n"
30
+ LOG_ERROR = "ERROR"
30
31
 
31
32
  def kiev_run
32
33
  args = attrs[:args]
@@ -69,6 +70,7 @@ module Kiev
69
70
  data[:error_class] = error.class.name
70
71
  data[:error_message] = error.message[0..5000]
71
72
  data[:error_backtrace] = Array(error.backtrace).join(NEW_LINE)[0..5000]
73
+ data[:level] = LOG_ERROR
72
74
  end
73
75
 
74
76
  Kiev.event(:job_finished, data)
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "zlib"
4
+
3
5
  module Kiev
4
6
  module Rack
5
7
  class RequestLogger
6
8
  ERROR_STATUS = 500
7
9
  ERROR_HEADERS = [].freeze
8
10
  ERROR_BODY = [""].freeze
11
+ LOG_ERROR = "ERROR"
9
12
 
10
13
  def initialize(app)
11
14
  @app = app
@@ -94,6 +97,8 @@ module Kiev
94
97
  route: extract_route(env)
95
98
  }
96
99
 
100
+ data[:level] = LOG_ERROR if data[:status].to_i.between?(400, 599)
101
+
97
102
  if env[HTTP_X_REQUEST_START]
98
103
  data[:request_latency] = ((began_at - env[HTTP_X_REQUEST_START].to_f) * 1000).round(3)
99
104
  end
@@ -115,6 +120,15 @@ module Kiev
115
120
  full_body << str
116
121
  end
117
122
  data[:body] = full_body.join
123
+ if data[:body] && !data[:body].empty? && response.headers["Content-Encoding"] == "gzip"
124
+ begin
125
+ sio = StringIO.new(data[:body])
126
+ gz = Zlib::GzipReader.new(sio)
127
+ data[:body] = gz.read
128
+ rescue Zlib::GzipFile::Error => err
129
+ data[:gzip_parse_error] = err.message
130
+ end
131
+ end
118
132
  end
119
133
 
120
134
  should_log_errors = config.log_request_error_condition.call(request, response)
@@ -122,8 +136,8 @@ module Kiev
122
136
  data[:error_class] = exception.class.name
123
137
  data[:error_message] = exception.message[0..5000]
124
138
  data[:error_backtrace] = Array(exception.backtrace).join(NEW_LINE)[0..5000]
139
+ data[:level] = LOG_ERROR
125
140
  end
126
-
127
141
  data
128
142
  end
129
143
 
@@ -4,6 +4,7 @@ module Kiev
4
4
  module RequestLogger
5
5
  module Mixin
6
6
  NEW_LINE = "\n"
7
+ LOG_ERROR = "ERROR"
7
8
 
8
9
  def wrap_request_logger(event, **data, &_block)
9
10
  began_at = Time.now
@@ -21,6 +22,7 @@ module Kiev
21
22
  data[:error_class] = error.class.name
22
23
  data[:error_message] = error.message[0..5000]
23
24
  data[:error_backtrace] = Array(error.backtrace).join(NEW_LINE)[0..5000]
25
+ data[:level] = LOG_ERROR
24
26
  end
25
27
 
26
28
  Kiev.event(event, data)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kiev
4
- VERSION = "2.8.0"
4
+ VERSION = "4.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiev
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blacklane
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-26 00:00:00.000000000 Z
11
+ date: 2020-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -124,7 +124,7 @@ description: Kiev is a logging tool aimed at distributed environments. It logs t
124
124
  JSON, while providing human-readable output in development mode. It integrates nicely
125
125
  with Rails, Sinatra and other Rack-based frameworks, Sidekiq, Que, HTTParty, Her
126
126
  and other Faraday-based HTTP clients.
127
- email:
127
+ email:
128
128
  executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
@@ -155,6 +155,7 @@ files:
155
155
  - lib/kiev/base52.rb
156
156
  - lib/kiev/config.rb
157
157
  - lib/kiev/context_reader.rb
158
+ - lib/kiev/hanami.rb
158
159
  - lib/kiev/her_ext/client_request_id.rb
159
160
  - lib/kiev/httparty.rb
160
161
  - lib/kiev/json.rb
@@ -198,7 +199,7 @@ homepage: https://github.com/blacklane/kiev
198
199
  licenses:
199
200
  - MIT
200
201
  metadata: {}
201
- post_install_message:
202
+ post_install_message:
202
203
  rdoc_options: []
203
204
  require_paths:
204
205
  - lib
@@ -213,10 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
214
  - !ruby/object:Gem::Version
214
215
  version: '0'
215
216
  requirements: []
216
- rubyforge_project:
217
- rubygems_version: 2.6.10
218
- signing_key:
217
+ rubygems_version: 3.0.3
218
+ signing_key:
219
219
  specification_version: 4
220
220
  summary: Distributed logging to JSON integrated with various Ruby frameworks and tools
221
221
  test_files: []
222
- has_rdoc: