event_tracer 0.1.0 → 0.1.1
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.rb +50 -11
- data/lib/event_tracer/appsignal_logger.rb +13 -4
- data/lib/event_tracer/base_logger.rb +4 -5
- data/lib/event_tracer/log_result.rb +4 -0
- data/lib/event_tracer/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e56b2ea7016745d2ba377a333e9519ef5ee67cfe
|
4
|
+
data.tar.gz: d50a901de9514382b3d51f474c1c424c4cfa86f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a49cc7f8647c7a6ca1b5949179e452b7df5bb0b22bdc6efe4d9a753907acbe813eb2a60bb7eaaa45a0a9649d808c2e5e950d841f2e1be0047b06cfcf171d8d96
|
7
|
+
data.tar.gz: 75de1c117e50cb645f733500c8d5324e93c5012cf0fd0dd4bbb0817683f6ac5e803258888477e0f3050a21304cc29cd7fe11830fb771203d755650c5b8744859
|
data/lib/event_tracer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require 'event_tracer/version'
|
2
|
+
require 'event_tracer/log_result'
|
2
3
|
|
3
4
|
module EventTracer
|
4
5
|
|
@@ -16,30 +17,68 @@ module EventTracer
|
|
16
17
|
|
17
18
|
LOG_TYPES.each do |log_type|
|
18
19
|
define_singleton_method log_type do |loggers: nil, **args|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
rescue Exception => e
|
25
|
-
p e.message
|
26
|
-
false
|
27
|
-
end
|
20
|
+
send_log_messages(
|
21
|
+
log_type,
|
22
|
+
(selected_loggers(loggers) || @loggers),
|
23
|
+
args
|
24
|
+
)
|
28
25
|
end
|
29
26
|
end
|
30
27
|
|
31
28
|
private
|
32
29
|
|
30
|
+
def self.send_log_messages(log_type, loggers, args)
|
31
|
+
result = Result.new
|
32
|
+
|
33
|
+
loggers.each do |code, logger|
|
34
|
+
begin
|
35
|
+
if args[:action] && args[:message]
|
36
|
+
result.record code, logger.send(log_type, filtered_log_arguments(code, args))
|
37
|
+
else
|
38
|
+
result.record code, LogResult.new(false, 'Fields action & message need to be populated')
|
39
|
+
end
|
40
|
+
rescue Exception => e
|
41
|
+
result.record code, LogResult.new(false, e.message)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
result
|
46
|
+
end
|
47
|
+
|
33
48
|
def self.selected_loggers(logger_codes)
|
34
49
|
return unless logger_codes.is_a?(Array)
|
35
50
|
return if logger_codes.detect { |code| !code.is_a?(Symbol) }
|
36
51
|
|
37
|
-
selected_codes = logger_codes.uniq &
|
52
|
+
selected_codes = logger_codes.uniq & registered_logger_codes
|
38
53
|
|
39
54
|
return if selected_codes.empty?
|
40
55
|
@loggers.select { |code, _logger| selected_codes.include?(code) }
|
41
56
|
end
|
42
57
|
|
58
|
+
def self.filtered_log_arguments(logger_code, args)
|
59
|
+
blacklisted_logger_keys = registered_logger_codes - [logger_code]
|
60
|
+
|
61
|
+
args.reject do |key, _value|
|
62
|
+
blacklisted_logger_keys.include?(key)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.registered_logger_codes
|
67
|
+
@loggers.keys
|
68
|
+
end
|
69
|
+
|
70
|
+
class Result
|
71
|
+
attr_reader :records
|
72
|
+
|
73
|
+
def initialize
|
74
|
+
@records = {}
|
75
|
+
end
|
76
|
+
|
77
|
+
def record(logger_code, outcome)
|
78
|
+
records[logger_code] = outcome
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
43
82
|
end
|
44
83
|
|
45
84
|
project_root = File.dirname(File.absolute_path(__FILE__))
|
@@ -14,11 +14,16 @@ module EventTracer
|
|
14
14
|
|
15
15
|
LOG_TYPES.each do |log_type|
|
16
16
|
define_method log_type do |**args|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
return LogResult.new(false, "Invalid appsignal config") unless args[:appsignal] && args[:appsignal].is_a?(Hash)
|
18
|
+
|
19
|
+
applied_metrics(args[:appsignal]).each do |metric|
|
20
|
+
metric_args = args[:appsignal][metric]
|
21
|
+
return LogResult.new(false, "Appsignal metric #{metric} invalid") unless metric_args && metric_args.is_a?(Hash)
|
22
|
+
|
23
|
+
send_metric metric, metric_args
|
20
24
|
end
|
21
|
-
|
25
|
+
|
26
|
+
LogResult.new(true)
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
@@ -27,6 +32,10 @@ module EventTracer
|
|
27
32
|
attr_reader :appsignal, :decoratee
|
28
33
|
alias_method :appsignal, :decoratee
|
29
34
|
|
35
|
+
def applied_metrics(appsignal_args)
|
36
|
+
appsignal_args.keys.select { |metric| SUPPORTED_METRICS.include?(metric) }
|
37
|
+
end
|
38
|
+
|
30
39
|
def send_metric(metric, payload)
|
31
40
|
payload.each do |increment, value|
|
32
41
|
appsignal.send(metric, increment, value)
|
@@ -9,6 +9,7 @@ module EventTracer
|
|
9
9
|
LOG_TYPES.each do |log_type|
|
10
10
|
define_method log_type do |*args|
|
11
11
|
send_message(log_type, *args)
|
12
|
+
LogResult.new(true)
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
@@ -17,11 +18,9 @@ module EventTracer
|
|
17
18
|
attr_reader :logger, :decoratee
|
18
19
|
alias_method :logger, :decoratee
|
19
20
|
|
20
|
-
#
|
21
|
-
def send_message(log_method, action
|
22
|
-
|
23
|
-
message_to_send = simple_message ? simple_message : args.to_json
|
24
|
-
logger.send(log_method, "[#{action}] #{message_to_send}")
|
21
|
+
# EventTracer ensures action & message is always populated
|
22
|
+
def send_message(log_method, action:, message:, **args)
|
23
|
+
logger.send(log_method, "[#{action}] #{message} #{args.to_json}")
|
25
24
|
end
|
26
25
|
|
27
26
|
end
|
data/lib/event_tracer/version.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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- melvrickgoh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/event_tracer/appsignal_logger.rb
|
65
65
|
- lib/event_tracer/base_logger.rb
|
66
66
|
- lib/event_tracer/basic_decorator.rb
|
67
|
+
- lib/event_tracer/log_result.rb
|
67
68
|
- lib/event_tracer/version.rb
|
68
69
|
homepage: https://github.com/melvrickgoh/event_tracer
|
69
70
|
licenses:
|