kiev 2.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +25 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +27 -0
  7. data/Gemfile +5 -0
  8. data/LICENSE.md +7 -0
  9. data/README.md +461 -0
  10. data/Rakefile +18 -0
  11. data/bin/console +8 -0
  12. data/config.ru +9 -0
  13. data/gemfiles/que_0.12.2.gemfile +14 -0
  14. data/gemfiles/que_0.12.3.gemfile +15 -0
  15. data/gemfiles/rails_4.1.gemfile +13 -0
  16. data/gemfiles/rails_4.2.gemfile +13 -0
  17. data/gemfiles/sidekiq_4.2.gemfile +14 -0
  18. data/gemfiles/sinatra_1.4.gemfile +15 -0
  19. data/gemfiles/sinatra_2.0.gemfile +15 -0
  20. data/kiev.gemspec +28 -0
  21. data/lib/ext/rack/common_logger.rb +12 -0
  22. data/lib/kiev.rb +9 -0
  23. data/lib/kiev/base.rb +51 -0
  24. data/lib/kiev/base52.rb +20 -0
  25. data/lib/kiev/config.rb +164 -0
  26. data/lib/kiev/her_ext/client_request_id.rb +14 -0
  27. data/lib/kiev/httparty.rb +11 -0
  28. data/lib/kiev/json.rb +118 -0
  29. data/lib/kiev/logger.rb +122 -0
  30. data/lib/kiev/param_filter.rb +30 -0
  31. data/lib/kiev/que/job.rb +78 -0
  32. data/lib/kiev/rack.rb +20 -0
  33. data/lib/kiev/rack/request_id.rb +68 -0
  34. data/lib/kiev/rack/request_logger.rb +140 -0
  35. data/lib/kiev/rack/silence_action_dispatch_logger.rb +22 -0
  36. data/lib/kiev/rack/store_request_details.rb +21 -0
  37. data/lib/kiev/railtie.rb +55 -0
  38. data/lib/kiev/request_body_filter.rb +36 -0
  39. data/lib/kiev/request_body_filter/default.rb +11 -0
  40. data/lib/kiev/request_body_filter/form_data.rb +12 -0
  41. data/lib/kiev/request_body_filter/json.rb +14 -0
  42. data/lib/kiev/request_body_filter/xml.rb +18 -0
  43. data/lib/kiev/request_store.rb +32 -0
  44. data/lib/kiev/sidekiq.rb +41 -0
  45. data/lib/kiev/sidekiq/client_request_id.rb +12 -0
  46. data/lib/kiev/sidekiq/request_id.rb +39 -0
  47. data/lib/kiev/sidekiq/request_logger.rb +39 -0
  48. data/lib/kiev/sidekiq/request_store.rb +13 -0
  49. data/lib/kiev/sidekiq/store_request_details.rb +27 -0
  50. data/lib/kiev/subrequest_helper.rb +61 -0
  51. data/lib/kiev/util.rb +14 -0
  52. data/lib/kiev/version.rb +5 -0
  53. metadata +208 -0
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiev
4
+ module Sidekiq
5
+ class RequestLogger
6
+ NEW_LINE = "\n"
7
+ ARGS = "args"
8
+
9
+ def call(_worker, job, _queue)
10
+ began_at = Time.now
11
+ error = nil
12
+
13
+ begin
14
+ return_value = yield
15
+ rescue Exception => exception
16
+ error = exception
17
+ end
18
+
19
+ begin
20
+ data = {
21
+ params: job[ARGS],
22
+ request_duration: ((Time.now - began_at) * 1000).round(3)
23
+ }
24
+
25
+ if error
26
+ data[:error_class] = error.class.name
27
+ data[:error_message] = error.message[0..5000]
28
+ data[:error_backtrace] = Array(error.backtrace).join(NEW_LINE)[0..5000]
29
+ end
30
+
31
+ Kiev.event(:job_finished, data)
32
+ ensure
33
+ raise error if error
34
+ return_value
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiev
4
+ module Sidekiq
5
+ class RequestStore
6
+ include Kiev::RequestStore::Mixin
7
+
8
+ def call(_worker, _job, _queue, &block)
9
+ wrap_request_store(&block)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiev
4
+ module Sidekiq
5
+ class StoreRequestDetails
6
+ JID = "jid"
7
+ WRAPPED = "wrapped"
8
+
9
+ def call(worker, job, _queue)
10
+ Config.instance.jobs_propagated_fields.each do |key|
11
+ Kiev[key] = job[key.to_s]
12
+ end
13
+ request_store = Kiev::RequestStore.store
14
+ request_store[:background_job] = true
15
+ request_store[:job_name] = expand_worker_name(worker, job)
16
+ request_store[:jid] = job[JID]
17
+ yield
18
+ end
19
+
20
+ private
21
+
22
+ def expand_worker_name(worker, job)
23
+ job[WRAPPED] || worker.class.name
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base52"
4
+
5
+ module Kiev
6
+ class SubrequestHelper
7
+ class << self
8
+ def headers(metadata: false)
9
+ Config.instance.all_http_propagated_fields.map do |key, http_key|
10
+ field = field_value(key, true)
11
+ [metadata ? key : http_key, field.to_s] if field
12
+ end.compact.to_h
13
+ end
14
+
15
+ def payload
16
+ Config.instance.all_jobs_propagated_fields.map do |key|
17
+ field = field_value(key, false)
18
+ [key.to_s, field] if field
19
+ end.compact.to_h
20
+ end
21
+
22
+ def root_path(synchronous:)
23
+ encode(0, synchronous)
24
+ end
25
+
26
+ def subrequest_path(synchronous:)
27
+ current_path + encode(counter, synchronous)
28
+ end
29
+
30
+ private
31
+
32
+ def field_value(key, synchronous)
33
+ if key == :tree_path
34
+ subrequest_path(synchronous: synchronous)
35
+ else
36
+ request_store = Kiev::RequestStore.store
37
+ request_store.dig(key) || request_store.dig(:payload, key)
38
+ end
39
+ end
40
+
41
+ def encode(value, synchronous)
42
+ # this scheme can encode up to 26 consequent requests (synchronous or asynchronous)
43
+ Base52.encode(value * 2 + (synchronous ? 0 : 1))
44
+ end
45
+
46
+ def current_path
47
+ RequestStore.store[:tree_path] || ""
48
+ end
49
+
50
+ def counter
51
+ if RequestStore.store[:subrequest_count]
52
+ # generally this is not atomic operation,
53
+ # but because RequestStore.store is tied to current thread this is ok
54
+ RequestStore.store[:subrequest_count] += 1
55
+ else
56
+ RequestStore.store[:subrequest_count] = 0
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiev
4
+ module Util
5
+ def self.sanitize(value)
6
+ return unless value
7
+ value.gsub(/[^\w\-]/, "")[0...255]
8
+ end
9
+
10
+ def self.to_http(value)
11
+ "HTTP_#{value.tr('-', '_').upcase}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiev
4
+ VERSION = "2.7.3"
5
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kiev
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.7.3
5
+ platform: ruby
6
+ authors:
7
+ - Blacklane
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: request_store
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.4'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '1.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.4'
53
+ - !ruby/object:Gem::Dependency
54
+ name: oga
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.2'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '2.2'
67
+ - !ruby/object:Gem::Dependency
68
+ name: ruby_dig
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: 0.0.2
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: 0.0.2
81
+ - !ruby/object:Gem::Dependency
82
+ name: rake
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: rubocop
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '='
114
+ - !ruby/object:Gem::Version
115
+ version: 0.49.1
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '='
121
+ - !ruby/object:Gem::Version
122
+ version: 0.49.1
123
+ description: Kiev is a logging tool aimed at distributed environments. It logs to
124
+ JSON, while providing human-readable output in development mode. It integrates nicely
125
+ with Rails, Sinatra and other Rack-based frameworks, Sidekiq, Que, HTTParty, Her
126
+ and other Faraday-based HTTP clients.
127
+ email:
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - ".ruby-version"
136
+ - ".travis.yml"
137
+ - Gemfile
138
+ - LICENSE.md
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - config.ru
143
+ - gemfiles/que_0.12.2.gemfile
144
+ - gemfiles/que_0.12.3.gemfile
145
+ - gemfiles/rails_4.1.gemfile
146
+ - gemfiles/rails_4.2.gemfile
147
+ - gemfiles/sidekiq_4.2.gemfile
148
+ - gemfiles/sinatra_1.4.gemfile
149
+ - gemfiles/sinatra_2.0.gemfile
150
+ - kiev.gemspec
151
+ - lib/ext/rack/common_logger.rb
152
+ - lib/kiev.rb
153
+ - lib/kiev/base.rb
154
+ - lib/kiev/base52.rb
155
+ - lib/kiev/config.rb
156
+ - lib/kiev/her_ext/client_request_id.rb
157
+ - lib/kiev/httparty.rb
158
+ - lib/kiev/json.rb
159
+ - lib/kiev/logger.rb
160
+ - lib/kiev/param_filter.rb
161
+ - lib/kiev/que/job.rb
162
+ - lib/kiev/rack.rb
163
+ - lib/kiev/rack/request_id.rb
164
+ - lib/kiev/rack/request_logger.rb
165
+ - lib/kiev/rack/silence_action_dispatch_logger.rb
166
+ - lib/kiev/rack/store_request_details.rb
167
+ - lib/kiev/railtie.rb
168
+ - lib/kiev/request_body_filter.rb
169
+ - lib/kiev/request_body_filter/default.rb
170
+ - lib/kiev/request_body_filter/form_data.rb
171
+ - lib/kiev/request_body_filter/json.rb
172
+ - lib/kiev/request_body_filter/xml.rb
173
+ - lib/kiev/request_store.rb
174
+ - lib/kiev/sidekiq.rb
175
+ - lib/kiev/sidekiq/client_request_id.rb
176
+ - lib/kiev/sidekiq/request_id.rb
177
+ - lib/kiev/sidekiq/request_logger.rb
178
+ - lib/kiev/sidekiq/request_store.rb
179
+ - lib/kiev/sidekiq/store_request_details.rb
180
+ - lib/kiev/subrequest_helper.rb
181
+ - lib/kiev/util.rb
182
+ - lib/kiev/version.rb
183
+ homepage: https://github.com/blacklane/kiev
184
+ licenses:
185
+ - MIT
186
+ metadata: {}
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: 2.0.0
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ requirements: []
202
+ rubyforge_project:
203
+ rubygems_version: 2.6.10
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: Distributed logging to JSON integrated with various Ruby frameworks and tools
207
+ test_files: []
208
+ has_rdoc: