event_tracer 0.4.1 → 0.4.2

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: 335d4c810b2a3e378d826518f8e8c6c2a8a1310f029401381ac2f407437554ca
4
- data.tar.gz: 95971a338ad15cb6f5f74bb78f10f59dfba0918c7578a3e1057f8d11e5dc7bbb
3
+ metadata.gz: c33ea83663eda9d96f8055d957ab688d6be6f957023ea689b5f119abedfb7ad8
4
+ data.tar.gz: f6f328085fdc3de07dafa12e27bac3752b18249bcd5bbd3cd81046222c853f19
5
5
  SHA512:
6
- metadata.gz: 473b42b4728e7233bdddaa4d85c681b33b41c71c26eb78ee9578c332f878e78234e6007b37c6c120e0adf13eaa8dd87e18f09d2069cfe7ca578e2ef8f1fc6079
7
- data.tar.gz: 5a58acc598909419d8164a4cfb46c2c9695b12faee98bdf2ae937648dc964c4c70e04c78e8a2395ed133a245ca86d4ac7d471972a7e72510267d2bcb754b1e56
6
+ metadata.gz: 49bf70ea7a94f1a88410b8b014c77763fd4f9f581503fb48500c07e02000db3325c3b113baa1df5f733b1326e02e28441137512972f8e1b8c07a0917f662c59c
7
+ data.tar.gz: 70a852a9f2de92aa90ce63381ac7b63252d0f889b9f0bf34eb51d4d43e4e9740b5532029571992150ebb50dae035fb1a9a5b12383c3e48eaeb25c15045cffcb5
@@ -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
@@ -9,5 +9,6 @@ module EventTracer
9
9
  # TODO: switch to namespace in v1.0
10
10
  setting :dynamo_db_table_name, default: 'logs'
11
11
  setting :dynamo_db_client
12
+ setting :dynamo_db_queue_name, default: 'low'
12
13
  end
13
14
  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
- @buffer = buffer
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,7 +15,7 @@ module EventTracer
15
15
  class Worker
16
16
  include ::Sidekiq::Worker
17
17
 
18
- sidekiq_options retry: 1, queue: 'low'
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
@@ -1,3 +1,3 @@
1
1
  module EventTracer
2
- VERSION = '0.4.1'.freeze
2
+ VERSION = '0.4.2'.freeze
3
3
  end
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.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - melvrickgoh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-01 00:00:00.000000000 Z
11
+ date: 2021-12-20 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