kiev 4.4.0 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/push.yml +1 -0
- data/README.md +33 -1
- data/gemfiles/ruby_kafka.gemfile +11 -0
- data/kiev.gemspec +2 -2
- data/lib/kiev.rb +2 -0
- data/lib/kiev/aws_sns.rb +16 -0
- data/lib/kiev/aws_sns/context_injector.rb +22 -0
- data/lib/kiev/base.rb +3 -1
- data/lib/kiev/kafka.rb +22 -0
- data/lib/kiev/kafka/context_extractor.rb +26 -0
- data/lib/kiev/kafka/context_injector.rb +20 -0
- data/lib/kiev/kafka/message_context.rb +27 -0
- data/lib/kiev/shoryuken/middleware/message_tracer.rb +4 -7
- data/lib/kiev/version.rb +1 -1
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f160c0e287ac552fab279ebc1974bf2de5704af494766872e1e2abfa11b48766
|
4
|
+
data.tar.gz: f2601c9be33ecc63b3741e76832b2b409250a4b5e7365ede3a40cc6a59c0eb6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9560e9929db4c64e968dc39d2efadb6b9a09cff5ced0a7e5ffacd823c63273bcd05be4e1918b5e4b70586c73f8520e4d62dccc9e83795908f0981d0ed14ca6e1
|
7
|
+
data.tar.gz: 4caa6b83331e522867ec3254ac5a3f0356c3336a452ade39e9c8df022f5409a17cc1a024c10cee80353252bec8da66b36aea5430cc4947c59acc0dab0fa1eccd
|
data/.github/workflows/push.yml
CHANGED
data/README.md
CHANGED
@@ -154,6 +154,36 @@ Kiev::Shoryuken.enable
|
|
154
154
|
|
155
155
|
The name of the worker class is not logged by default. Configure [`persistent_log_fields` option](#persistent_log_fields) to include `"shoryuken_class"` if you want this.
|
156
156
|
|
157
|
+
### AWS SNS
|
158
|
+
|
159
|
+
To enhance messages published to SNS topics you can use the ContextInjector:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
sns_message = { topic_arn: "...", message: "{...}" }
|
163
|
+
Kiev::Kafka.inject_context(sns_message[:message_attributes])
|
164
|
+
|
165
|
+
```
|
166
|
+
|
167
|
+
After this operation the message attributes will also include required context for the Kiev logger.
|
168
|
+
|
169
|
+
### Kafka
|
170
|
+
|
171
|
+
To enhance messages published to Kafka topics you can use the ContextInjector:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
Kiev::Kafka.inject_context(headers)
|
175
|
+
```
|
176
|
+
|
177
|
+
After this operation the headers variable will also include required context for the Kiev logger.
|
178
|
+
|
179
|
+
If you have a consumed `Kafka::FetchedMessage` you can extract logger context with:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
Kiev::Kafka.extract_context(message)
|
183
|
+
```
|
184
|
+
|
185
|
+
This will work regardless if headers are in HTTP format, e.g. `X-Tracking-Id` or plain field names: `tracking_id`. Plus the `message_key` field will contain the key of processed message. In case you want to log some more fields configure `persistent_log_fields` and `jobs_propagated_fields`.
|
186
|
+
|
157
187
|
### Que
|
158
188
|
|
159
189
|
Add the following lines to your initializer code:
|
@@ -219,7 +249,9 @@ For web requests the Kiev middleware will log the following information by defau
|
|
219
249
|
|
220
250
|
* `params` attribute will store both query parameters and request body fields (as long as they are parseable). Sensitive fields will be filtered out - see the `#filtered_params` option.
|
221
251
|
|
222
|
-
* `request_id` is the correlation ID and will be the same across all requests within a chain of requests. It's represented as a UUID (version 4).
|
252
|
+
* `request_id` is the correlation ID and will be the same across all requests within a chain of requests. It's represented as a UUID (version 4). (currently deprecated in favor of a new name: `tracking_id`)
|
253
|
+
|
254
|
+
* `tracking_id` is the correlation ID and will be the same across all requests within a chain of requests. It's represented as a UUID (version 4). If not provided the value is seeded from deprecated `request_id`.
|
223
255
|
|
224
256
|
* `request_depth` represents the position of the current request within a chain of requests. It starts with 0.
|
225
257
|
|
data/kiev.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency "rack", ">= 1", "< 3"
|
25
25
|
spec.add_dependency "request_store", ">= 1.0", "< 1.4"
|
26
26
|
spec.add_dependency "ruby_dig", "~> 0.0.2" # to support ruby 2.2
|
27
|
-
spec.add_development_dependency "rake",
|
28
|
-
spec.add_development_dependency "rspec",
|
27
|
+
spec.add_development_dependency "rake", "~> 0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.10"
|
29
29
|
spec.add_development_dependency "rubocop", "~> 0.54"
|
30
30
|
end
|
data/lib/kiev.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "kiev/base"
|
4
|
+
require_relative "kiev/aws_sns" if defined?(AWS::SNS)
|
5
|
+
require_relative "kiev/kafka" if defined?(Kafka)
|
4
6
|
require_relative "kiev/rack" if defined?(Rack)
|
5
7
|
require_relative "kiev/railtie" if defined?(Rails)
|
6
8
|
require_relative "kiev/sidekiq" if defined?(Sidekiq)
|
data/lib/kiev/aws_sns.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Kiev
|
6
|
+
module AwsSns
|
7
|
+
require_relative "kafka/context_injector"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# @param [Hash] headers
|
11
|
+
def inject_context(headers = {})
|
12
|
+
Kiev::AwsSns::ContextInjector.new.call(headers)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "kiev/config"
|
4
|
+
require "kiev/subrequest_helper"
|
5
|
+
|
6
|
+
module Kiev
|
7
|
+
module AwsSns
|
8
|
+
class ContextInjector
|
9
|
+
# @param [Hash] message_attributes Injects context headers
|
10
|
+
# @return [Hash]
|
11
|
+
def call(message_attributes = {})
|
12
|
+
Kiev::SubrequestHelper.payload.each do |key, value|
|
13
|
+
message_attributes[key] = {
|
14
|
+
data_type: "String",
|
15
|
+
string_value: value.to_s
|
16
|
+
}
|
17
|
+
end
|
18
|
+
message_attributes
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/kiev/base.rb
CHANGED
data/lib/kiev/kafka.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Kiev
|
6
|
+
module Kafka
|
7
|
+
require_relative "kafka/context_extractor"
|
8
|
+
require_relative "kafka/context_injector"
|
9
|
+
|
10
|
+
class << self
|
11
|
+
# @param [Kafka::FetchedMessage] message
|
12
|
+
def extract_context(message)
|
13
|
+
Kiev::Kafka::ContextExtractor.new.call(message)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [Hash] headers
|
17
|
+
def inject_context(headers = {})
|
18
|
+
Kiev::Kafka::ContextInjector.new.call(headers)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "message_context"
|
4
|
+
require "kiev/request_id"
|
5
|
+
require "kiev/context_reader"
|
6
|
+
|
7
|
+
module Kiev
|
8
|
+
module Kafka
|
9
|
+
class ContextExtractor
|
10
|
+
include Kiev::RequestId::Mixin
|
11
|
+
|
12
|
+
# @param [Kafka::FetchedMessage] message
|
13
|
+
def call(message)
|
14
|
+
context = Kiev::Kafka::MessageContext.new(message)
|
15
|
+
context_reader = Kiev::ContextReader.new(context)
|
16
|
+
wrap_request_id(context_reader) {}
|
17
|
+
|
18
|
+
Kiev[:message_key] = message.key
|
19
|
+
|
20
|
+
Config.instance.jobs_propagated_fields.each do |key|
|
21
|
+
Kiev[key] = context_reader[key]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "kiev/config"
|
4
|
+
require "kiev/subrequest_helper"
|
5
|
+
|
6
|
+
module Kiev
|
7
|
+
module Kafka
|
8
|
+
class ContextInjector
|
9
|
+
# @param [Hash] headers Injects context headers
|
10
|
+
# @return [Hash]
|
11
|
+
def call(headers = {})
|
12
|
+
Kiev::SubrequestHelper.payload.each do |key, value|
|
13
|
+
field_key = Kiev::Config::DEFAULT_HTTP_PROPAGATED_FIELDS.fetch(key.to_sym, key)
|
14
|
+
headers[field_key] = value
|
15
|
+
end
|
16
|
+
headers
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kiev
|
4
|
+
module Kafka
|
5
|
+
class MessageContext
|
6
|
+
# @param [Kafka::FetchedMessage] message
|
7
|
+
def initialize(message)
|
8
|
+
@headers = message.headers
|
9
|
+
end
|
10
|
+
|
11
|
+
def value(field)
|
12
|
+
headers[header_key(field)] || headers[field.to_s]
|
13
|
+
end
|
14
|
+
|
15
|
+
alias_method :[], :value
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :headers
|
20
|
+
|
21
|
+
# @param [String] field
|
22
|
+
def header_key(field)
|
23
|
+
"x_#{field}".gsub("_", " ").split.map(&:capitalize).join("-")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,17 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "kiev/aws_sns/context_injector"
|
4
|
+
|
3
5
|
module Kiev
|
4
6
|
module Shoryuken
|
5
7
|
module Middleware
|
6
8
|
class MessageTracer
|
7
9
|
def call(options)
|
8
|
-
|
9
|
-
|
10
|
-
attrbutes[key] = {
|
11
|
-
data_type: "String",
|
12
|
-
string_value: value.to_s
|
13
|
-
}
|
14
|
-
end
|
10
|
+
options[:message_attributes] ||= {}
|
11
|
+
Kiev::AwsSns::ContextInjector.new.call(options[:message_attributes])
|
15
12
|
yield
|
16
13
|
end
|
17
14
|
end
|
data/lib/kiev/version.rb
CHANGED
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: 4.
|
4
|
+
version: 4.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blacklane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oga
|
@@ -98,14 +98,14 @@ dependencies:
|
|
98
98
|
requirements:
|
99
99
|
- - "~>"
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version: '
|
101
|
+
version: '3.10'
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
106
|
- - "~>"
|
107
107
|
- !ruby/object:Gem::Version
|
108
|
-
version: '
|
108
|
+
version: '3.10'
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
110
|
name: rubocop
|
111
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- gemfiles/rails_4.1.gemfile
|
146
146
|
- gemfiles/rails_4.2.gemfile
|
147
147
|
- gemfiles/rails_5.2.gemfile
|
148
|
+
- gemfiles/ruby_kafka.gemfile
|
148
149
|
- gemfiles/shoryuken_4.0.gemfile
|
149
150
|
- gemfiles/sidekiq_4.2.gemfile
|
150
151
|
- gemfiles/sinatra_1.4.gemfile
|
@@ -152,6 +153,8 @@ files:
|
|
152
153
|
- kiev.gemspec
|
153
154
|
- lib/ext/rack/common_logger.rb
|
154
155
|
- lib/kiev.rb
|
156
|
+
- lib/kiev/aws_sns.rb
|
157
|
+
- lib/kiev/aws_sns/context_injector.rb
|
155
158
|
- lib/kiev/base.rb
|
156
159
|
- lib/kiev/base52.rb
|
157
160
|
- lib/kiev/config.rb
|
@@ -160,6 +163,10 @@ files:
|
|
160
163
|
- lib/kiev/her_ext/client_request_id.rb
|
161
164
|
- lib/kiev/httparty.rb
|
162
165
|
- lib/kiev/json.rb
|
166
|
+
- lib/kiev/kafka.rb
|
167
|
+
- lib/kiev/kafka/context_extractor.rb
|
168
|
+
- lib/kiev/kafka/context_injector.rb
|
169
|
+
- lib/kiev/kafka/message_context.rb
|
163
170
|
- lib/kiev/logger.rb
|
164
171
|
- lib/kiev/param_filter.rb
|
165
172
|
- lib/kiev/que/job.rb
|