event_tracer 0.1.2 → 0.3.0
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 +4 -16
- data/lib/event_tracer/appsignal_logger.rb +39 -22
- data/lib/event_tracer/base_logger.rb +3 -3
- data/lib/event_tracer/basic_decorator.rb +11 -1
- data/lib/event_tracer/datadog_logger.rb +71 -0
- data/lib/event_tracer/version.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16cc39532664c9eb8da45f8f90a3a76ca7f180cc81da848bdf980dba5f91bfc8
|
4
|
+
data.tar.gz: 713186d9e6d2de28d334f2a29db2be8e8619f7176080b5d9390f5225568db0af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a5faa6c50a2662896675686b0da3b2706ca29ec102e244be0230547e551e2da014af73954a2396870ebf20b1e55b170451e8f4863257a713776aab6dbc301d6
|
7
|
+
data.tar.gz: c2b1ce96276d8821b476a21c35528c3f1c738363d960e1c709e3a1f361228fe4d0ac09ab8f13f2c6a1daef834f35f0fe22fca8b2cc328eab54a114eaa062a039
|
data/lib/event_tracer.rb
CHANGED
@@ -31,14 +31,10 @@ module EventTracer
|
|
31
31
|
result = Result.new
|
32
32
|
|
33
33
|
loggers.each do |code, logger|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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)
|
34
|
+
if args[:action] && args[:message]
|
35
|
+
result.record code, logger.send(log_type, **args)
|
36
|
+
else
|
37
|
+
result.record code, LogResult.new(false, 'Fields action & message need to be populated')
|
42
38
|
end
|
43
39
|
end
|
44
40
|
|
@@ -55,14 +51,6 @@ module EventTracer
|
|
55
51
|
@loggers.select { |code, _logger| selected_codes.include?(code) }
|
56
52
|
end
|
57
53
|
|
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
54
|
def self.registered_logger_codes
|
67
55
|
@loggers.keys
|
68
56
|
end
|
@@ -2,45 +2,62 @@ require_relative '../event_tracer'
|
|
2
2
|
require_relative './basic_decorator'
|
3
3
|
|
4
4
|
# NOTES
|
5
|
-
# Appsignal interface to send our usual actions
|
5
|
+
# Appsignal interface to send our usual actions
|
6
6
|
# BasicDecorator adds a transparent interface on top of the appsignal interface
|
7
7
|
#
|
8
|
-
# Usage: EventTracer.register :appsignal,
|
9
|
-
#
|
8
|
+
# Usage: EventTracer.register :appsignal,
|
9
|
+
# EventTracer::AppsignalLogger.new(Appsignal, allowed_tags: ['tag_1', 'tag_2'])
|
10
|
+
#
|
11
|
+
# appsignal_logger.info metrics: [:counter_1, :counter_2]
|
12
|
+
# appsignal_logger.info metrics: { counter_1: { type: :counter, value: 1 }, gauce_2: { type: :gauce, value: 10 } }
|
10
13
|
module EventTracer
|
11
14
|
class AppsignalLogger < BasicDecorator
|
12
15
|
|
13
|
-
|
16
|
+
SUPPORTED_METRIC_TYPES = {
|
17
|
+
counter: :increment_counter,
|
18
|
+
distribution: :add_distribution_value,
|
19
|
+
gauge: :set_gauge
|
20
|
+
}
|
21
|
+
DEFAULT_METRIC_TYPE = :increment_counter
|
22
|
+
DEFAULT_COUNTER = 1
|
23
|
+
|
24
|
+
def initialize(decoratee, allowed_tags: [])
|
25
|
+
super(decoratee)
|
26
|
+
@allowed_tags = allowed_tags
|
27
|
+
end
|
14
28
|
|
15
29
|
LOG_TYPES.each do |log_type|
|
16
30
|
define_method log_type do |**args|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
31
|
+
metrics = args[:metrics]
|
32
|
+
|
33
|
+
return fail_result('Invalid appsignal config') unless valid_args?(metrics)
|
34
|
+
return success_result if metrics.empty?
|
35
|
+
|
36
|
+
tags = args.slice(*allowed_tags)
|
37
|
+
|
38
|
+
case metrics
|
39
|
+
when Array
|
40
|
+
metrics.each do |metric|
|
41
|
+
appsignal.public_send(DEFAULT_METRIC_TYPE, metric, DEFAULT_COUNTER, tags)
|
42
|
+
end
|
43
|
+
when Hash
|
44
|
+
metrics.each do |metric_name, metric_payload|
|
45
|
+
metric_type = SUPPORTED_METRIC_TYPES[metric_payload.fetch(:type).to_sym]
|
46
|
+
appsignal.public_send(metric_type, metric_name, metric_payload.fetch(:value), tags) if metric_type
|
47
|
+
end
|
24
48
|
end
|
25
49
|
|
26
|
-
|
50
|
+
success_result
|
27
51
|
end
|
28
52
|
end
|
29
53
|
|
30
54
|
private
|
31
55
|
|
32
|
-
attr_reader :
|
56
|
+
attr_reader :decoratee, :allowed_tags
|
33
57
|
alias_method :appsignal, :decoratee
|
34
58
|
|
35
|
-
def
|
36
|
-
|
59
|
+
def valid_args?(metrics)
|
60
|
+
metrics && (metrics.is_a?(Hash) || metrics.is_a?(Array))
|
37
61
|
end
|
38
|
-
|
39
|
-
def send_metric(metric, payload)
|
40
|
-
payload.each do |increment, value|
|
41
|
-
appsignal.send(metric, increment, value)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
62
|
end
|
46
63
|
end
|
@@ -7,8 +7,8 @@ module EventTracer
|
|
7
7
|
class BaseLogger < BasicDecorator
|
8
8
|
|
9
9
|
LOG_TYPES.each do |log_type|
|
10
|
-
define_method log_type do
|
11
|
-
send_message(log_type,
|
10
|
+
define_method log_type do |**args|
|
11
|
+
send_message(log_type, **args)
|
12
12
|
LogResult.new(true)
|
13
13
|
end
|
14
14
|
end
|
@@ -20,7 +20,7 @@ module EventTracer
|
|
20
20
|
|
21
21
|
# EventTracer ensures action & message is always populated
|
22
22
|
def send_message(log_method, action:, message:, **args)
|
23
|
-
data = args.merge(action: action, message: message)
|
23
|
+
data = args.merge(action: action, message: message).except(:metrics)
|
24
24
|
logger.public_send(log_method, data)
|
25
25
|
end
|
26
26
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
1
3
|
module EventTracer
|
2
4
|
class BasicDecorator < Delegator
|
3
5
|
|
@@ -14,5 +16,13 @@ module EventTracer
|
|
14
16
|
@delegate_sd_obj = obj
|
15
17
|
end
|
16
18
|
|
19
|
+
def success_result
|
20
|
+
LogResult.new(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fail_result(message)
|
24
|
+
LogResult.new(false, message)
|
25
|
+
end
|
26
|
+
|
17
27
|
end
|
18
|
-
end
|
28
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative '../event_tracer'
|
2
|
+
require_relative './basic_decorator'
|
3
|
+
# NOTES
|
4
|
+
# Datadog interface to send our usual actions
|
5
|
+
# BasicDecorator adds a transparent interface on top of the datadog interface
|
6
|
+
#
|
7
|
+
# Usage: EventTracer.register :datadog,
|
8
|
+
# EventTracer::DataDogLogger.new(DataDog, allowed_tags: ['tag_1', 'tag_2'])
|
9
|
+
#
|
10
|
+
# data_dog_logger.info metrics: [:counter_1, :counter_2]
|
11
|
+
# data_dog_logger.info metrics: { counter_1: { type: :counter, value: 1}, gauce_2: { type: :gauce, value: 10 } }
|
12
|
+
|
13
|
+
module EventTracer
|
14
|
+
class DatadogLogger < BasicDecorator
|
15
|
+
|
16
|
+
SUPPORTED_METRIC_TYPES = {
|
17
|
+
counter: :count,
|
18
|
+
distribution: :distribution,
|
19
|
+
gauge: :gauge,
|
20
|
+
set: :set,
|
21
|
+
histogram: :histogram
|
22
|
+
}
|
23
|
+
DEFAULT_METRIC_TYPE = :count
|
24
|
+
DEFAULT_COUNTER = 1
|
25
|
+
|
26
|
+
def initialize(decoratee, allowed_tags: [])
|
27
|
+
super(decoratee)
|
28
|
+
@allowed_tags = allowed_tags
|
29
|
+
end
|
30
|
+
|
31
|
+
LOG_TYPES.each do |log_type|
|
32
|
+
define_method log_type do |**args|
|
33
|
+
metrics = args[:metrics]
|
34
|
+
|
35
|
+
return fail_result('Invalid Datadog config') unless valid_args?(metrics)
|
36
|
+
return success_result if metrics.empty?
|
37
|
+
|
38
|
+
tags = build_tags(args)
|
39
|
+
|
40
|
+
case metrics
|
41
|
+
when Array
|
42
|
+
metrics.each do |metric|
|
43
|
+
datadog.public_send(DEFAULT_METRIC_TYPE, metric, DEFAULT_COUNTER, tags: tags)
|
44
|
+
end
|
45
|
+
when Hash
|
46
|
+
metrics.each do |metric_name, metric_payload|
|
47
|
+
metric_type = SUPPORTED_METRIC_TYPES[metric_payload.fetch(:type).to_sym]
|
48
|
+
datadog.public_send(metric_type, metric_name, metric_payload.fetch(:value), tags: tags) if metric_type
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
success_result
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
attr_reader :decoratee, :allowed_tags
|
59
|
+
alias_method :datadog, :decoratee
|
60
|
+
|
61
|
+
def valid_args?(metrics)
|
62
|
+
metrics && (metrics.is_a?(Hash) || metrics.is_a?(Array))
|
63
|
+
end
|
64
|
+
|
65
|
+
def build_tags(args)
|
66
|
+
args.slice(*allowed_tags).map do |tag, value|
|
67
|
+
"#{tag}:#{value}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/event_tracer/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_tracer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- melvrickgoh
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.1.4
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.1.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,13 +64,14 @@ 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/datadog_logger.rb
|
67
68
|
- lib/event_tracer/log_result.rb
|
68
69
|
- lib/event_tracer/version.rb
|
69
70
|
homepage: https://github.com/melvrickgoh/event_tracer
|
70
71
|
licenses:
|
71
72
|
- MIT
|
72
73
|
metadata: {}
|
73
|
-
post_install_message:
|
74
|
+
post_install_message:
|
74
75
|
rdoc_options: []
|
75
76
|
require_paths:
|
76
77
|
- lib/event_tracer
|
@@ -86,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
87
|
- !ruby/object:Gem::Version
|
87
88
|
version: '0'
|
88
89
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
90
|
-
signing_key:
|
90
|
+
rubygems_version: 3.2.3
|
91
|
+
signing_key:
|
91
92
|
specification_version: 4
|
92
93
|
summary: Thin wrapper for formatted logging/ metric services to be used as a single
|
93
94
|
service
|