event_tracer 0.4.0 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/event_tracer/appsignal_logger.rb +3 -3
- data/lib/event_tracer/base_logger.rb +0 -2
- data/lib/event_tracer/basic_decorator.rb +3 -0
- data/lib/event_tracer/buffered_logger.rb +55 -0
- data/lib/event_tracer/config.rb +16 -2
- data/lib/event_tracer/datadog_logger.rb +3 -3
- data/lib/event_tracer/dynamo_db/client.rb +7 -2
- data/lib/event_tracer/dynamo_db/logger.rb +2 -25
- data/lib/event_tracer/dynamo_db/worker.rb +10 -3
- data/lib/event_tracer/version.rb +1 -1
- data/lib/event_tracer.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1eb75aebdf04e2a3797b9cb77780ab1f1960846b9332899d466ef67e269f599d
|
4
|
+
data.tar.gz: 9ffcabba2a3435bab02a8e6e2929250ee5aa659069b1d006d29c3df084923a45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa666b368a2a7cdb565a850b460e0f763b195550cfdd640d9d7970709370cdc531eda7b48caab30b4687c00002bed32540511f3df4d83606ff1a33f6885b4698
|
7
|
+
data.tar.gz: 94dfdbc766ba5dcc02fac74d81ced3ed516d9a29ad578a8472810955aa66ffe0f92db1507593d2846951ff613e1524cb07fb37e8d8f2f4e7ae43b9db4c05161b
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require_relative '../event_tracer'
|
2
1
|
require_relative './basic_decorator'
|
3
2
|
|
4
3
|
# NOTES
|
@@ -21,9 +20,11 @@ module EventTracer
|
|
21
20
|
DEFAULT_METRIC_TYPE = :increment_counter
|
22
21
|
DEFAULT_COUNTER = 1
|
23
22
|
|
23
|
+
attr_reader :allowed_tags
|
24
|
+
|
24
25
|
def initialize(decoratee, allowed_tags: [])
|
25
26
|
super(decoratee)
|
26
|
-
@allowed_tags = allowed_tags
|
27
|
+
@allowed_tags = allowed_tags.freeze
|
27
28
|
end
|
28
29
|
|
29
30
|
LOG_TYPES.each do |log_type|
|
@@ -53,7 +54,6 @@ module EventTracer
|
|
53
54
|
|
54
55
|
private
|
55
56
|
|
56
|
-
attr_reader :decoratee, :allowed_tags
|
57
57
|
alias_method :appsignal, :decoratee
|
58
58
|
|
59
59
|
def valid_args?(metrics)
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require_relative '../event_tracer'
|
2
1
|
require_relative './basic_decorator'
|
3
2
|
require 'json'
|
4
3
|
|
@@ -15,7 +14,6 @@ module EventTracer
|
|
15
14
|
|
16
15
|
private
|
17
16
|
|
18
|
-
attr_reader :logger, :decoratee
|
19
17
|
alias_method :logger, :decoratee
|
20
18
|
|
21
19
|
# EventTracer ensures action & message is always populated
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module EventTracer
|
6
|
+
class BufferedLogger
|
7
|
+
def initialize(log_processor:, worker:, buffer: Buffer.new(buffer_size: 0))
|
8
|
+
@buffer = buffer
|
9
|
+
@worker = worker
|
10
|
+
@log_processor = log_processor
|
11
|
+
end
|
12
|
+
|
13
|
+
EventTracer::LOG_TYPES.each do |log_type|
|
14
|
+
define_method log_type do |**args|
|
15
|
+
save_message log_type, **args
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :buffer, :log_processor, :worker
|
22
|
+
|
23
|
+
def save_message(log_type, action:, message:, **args)
|
24
|
+
payload = log_processor.call(log_type, action: action, message: message, args: args)
|
25
|
+
|
26
|
+
unless buffer.add(payload)
|
27
|
+
all_payloads = buffer.flush + [payload]
|
28
|
+
execute_payload(all_payloads)
|
29
|
+
end
|
30
|
+
|
31
|
+
LogResult.new(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute_payload(payloads)
|
35
|
+
worker.perform_async(payloads)
|
36
|
+
rescue JSON::GeneratorError => e
|
37
|
+
filtered_payloads = filter_invalid_data(payloads)
|
38
|
+
|
39
|
+
EventTracer.warn(
|
40
|
+
loggers: %i(base),
|
41
|
+
action: self.class.name,
|
42
|
+
app: EventTracer::Config.config.app_name,
|
43
|
+
error: e.class.name,
|
44
|
+
message: e.message,
|
45
|
+
payload: payloads - filtered_payloads
|
46
|
+
)
|
47
|
+
|
48
|
+
worker.perform_async(filtered_payloads) if filtered_payloads.any?
|
49
|
+
end
|
50
|
+
|
51
|
+
def filter_invalid_data(payloads)
|
52
|
+
payloads.select { |payload| payload.to_json rescue false }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/event_tracer/config.rb
CHANGED
@@ -1,10 +1,24 @@
|
|
1
1
|
require 'dry-configurable'
|
2
|
+
require 'dry/configurable/version'
|
2
3
|
|
3
4
|
module EventTracer
|
4
5
|
class Config
|
5
6
|
extend Dry::Configurable
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
if Dry::Configurable::VERSION >= "0.13"
|
9
|
+
setting :app_name, default: 'app_name'
|
10
|
+
|
11
|
+
# TODO: switch to namespace in v1.0
|
12
|
+
setting :dynamo_db_table_name, default: 'logs'
|
13
|
+
setting :dynamo_db_client
|
14
|
+
setting :dynamo_db_queue_name, default: 'low'
|
15
|
+
else
|
16
|
+
setting :app_name, 'app_name'
|
17
|
+
|
18
|
+
# TODO: switch to namespace in v1.0
|
19
|
+
setting :dynamo_db_table_name, 'logs'
|
20
|
+
setting :dynamo_db_client
|
21
|
+
setting :dynamo_db_queue_name, 'low'
|
22
|
+
end
|
9
23
|
end
|
10
24
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require_relative '../event_tracer'
|
2
1
|
require_relative './basic_decorator'
|
3
2
|
# NOTES
|
4
3
|
# Datadog interface to send our usual actions
|
@@ -23,9 +22,11 @@ module EventTracer
|
|
23
22
|
DEFAULT_METRIC_TYPE = :count
|
24
23
|
DEFAULT_COUNTER = 1
|
25
24
|
|
25
|
+
attr_reader :allowed_tags
|
26
|
+
|
26
27
|
def initialize(decoratee, allowed_tags: [])
|
27
28
|
super(decoratee)
|
28
|
-
@allowed_tags = allowed_tags
|
29
|
+
@allowed_tags = allowed_tags.freeze
|
29
30
|
end
|
30
31
|
|
31
32
|
LOG_TYPES.each do |log_type|
|
@@ -55,7 +56,6 @@ module EventTracer
|
|
55
56
|
|
56
57
|
private
|
57
58
|
|
58
|
-
attr_reader :decoratee, :allowed_tags
|
59
59
|
alias_method :datadog, :decoratee
|
60
60
|
|
61
61
|
def valid_args?(metrics)
|
@@ -1,8 +1,13 @@
|
|
1
1
|
module EventTracer
|
2
2
|
module DynamoDB
|
3
3
|
class Client
|
4
|
-
|
5
|
-
|
4
|
+
class << self
|
5
|
+
extend Gem::Deprecate
|
6
|
+
|
7
|
+
def call
|
8
|
+
Aws::DynamoDB::Client.new
|
9
|
+
end
|
10
|
+
deprecate :call, 'EventTracer::Config.config.dynamo_db_client', 2021, 12
|
6
11
|
end
|
7
12
|
end
|
8
13
|
end
|
@@ -7,33 +7,10 @@ require_relative 'default_processor'
|
|
7
7
|
|
8
8
|
module EventTracer
|
9
9
|
module DynamoDB
|
10
|
-
class Logger
|
10
|
+
class Logger < BufferedLogger
|
11
11
|
def initialize(buffer: Buffer.new(buffer_size: 0), log_processor: DefaultProcessor.new)
|
12
|
-
|
13
|
-
@log_processor = log_processor
|
12
|
+
super(buffer: buffer, log_processor: log_processor, worker: Worker)
|
14
13
|
end
|
15
|
-
|
16
|
-
EventTracer::LOG_TYPES.each do |log_type|
|
17
|
-
define_method log_type do |**args|
|
18
|
-
save_message log_type, **args
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
attr_reader :buffer, :log_processor
|
25
|
-
|
26
|
-
def save_message(log_type, action:, message:, **args)
|
27
|
-
payload = log_processor.call(log_type, action: action, message: message, args: args)
|
28
|
-
|
29
|
-
unless buffer.add(payload)
|
30
|
-
all_payloads = buffer.flush + [payload]
|
31
|
-
Worker.perform_async(all_payloads)
|
32
|
-
end
|
33
|
-
|
34
|
-
LogResult.new(true)
|
35
|
-
end
|
36
|
-
|
37
14
|
end
|
38
15
|
end
|
39
16
|
end
|
@@ -15,19 +15,24 @@ module EventTracer
|
|
15
15
|
class Worker
|
16
16
|
include ::Sidekiq::Worker
|
17
17
|
|
18
|
-
sidekiq_options retry: 1, queue:
|
18
|
+
sidekiq_options retry: 1, queue: EventTracer::Config.config.dynamo_db_queue_name
|
19
19
|
|
20
20
|
# See https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#batch_write_item-instance_method
|
21
21
|
MAX_DYNAMO_DB_ITEM_PER_REQUEST = 25
|
22
22
|
|
23
|
+
def initialize(client = nil)
|
24
|
+
@config = EventTracer::Config.config
|
25
|
+
@client = client || @config.dynamo_db_client || Client.call
|
26
|
+
end
|
27
|
+
|
23
28
|
def perform(items)
|
24
29
|
wrap(items).each_slice(MAX_DYNAMO_DB_ITEM_PER_REQUEST) do |batch|
|
25
30
|
data = batch.map do |item|
|
26
31
|
{ put_request: { item: clean_empty_values(item) } }
|
27
32
|
end
|
28
33
|
|
29
|
-
|
30
|
-
request_items: {
|
34
|
+
client.batch_write_item(
|
35
|
+
request_items: { config.dynamo_db_table_name => data }
|
31
36
|
)
|
32
37
|
|
33
38
|
rescue Aws::DynamoDB::Errors::ServiceError => e
|
@@ -43,6 +48,8 @@ module EventTracer
|
|
43
48
|
|
44
49
|
private
|
45
50
|
|
51
|
+
attr_reader :client, :config
|
52
|
+
|
46
53
|
def wrap(items)
|
47
54
|
# NOTE: This allows us to handle either buffered or unbuffered payloads
|
48
55
|
if items.is_a?(Hash)
|
data/lib/event_tracer/version.rb
CHANGED
data/lib/event_tracer.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_tracer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- melvrickgoh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/event_tracer/base_logger.rb
|
94
94
|
- lib/event_tracer/basic_decorator.rb
|
95
95
|
- lib/event_tracer/buffer.rb
|
96
|
+
- lib/event_tracer/buffered_logger.rb
|
96
97
|
- lib/event_tracer/config.rb
|
97
98
|
- lib/event_tracer/datadog_logger.rb
|
98
99
|
- lib/event_tracer/dynamo_db/client.rb
|