event_tracer 0.6.1 → 0.6.3
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 +9 -32
- data/lib/event_tracer/buffer.rb +4 -1
- data/lib/event_tracer/datadog_logger.rb +6 -35
- data/lib/event_tracer/metric_logger.rb +42 -0
- data/lib/event_tracer/prometheus_logger.rb +10 -43
- data/lib/event_tracer/version.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: 4e70e560e8704ed46e36010878ec3419edbf1b0f6674c82b92a28fbe17ea0caf
|
4
|
+
data.tar.gz: 6c2c3fa61d240cd7ea67460042125a030576f44797c002b3359a8fb547cf8af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc24ff64d2d48630c583a62fe53e9d1e328ad8fd4eed07a22fd24efda21b8f4478bf9f1f3736c54f50437a088cc0bae374d7f825e237275b06ef3ffd6951e438
|
7
|
+
data.tar.gz: 66b76929a73eddc3e136874729c96e8e9b3cda82131b6799d92c4266445ebc3af4fa2c2985c2698d84fe9f541d37ceecf1e9d80ff051bcece76fe93866e84c03
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative './
|
1
|
+
require_relative './metric_logger'
|
2
2
|
|
3
3
|
# NOTES
|
4
4
|
# Appsignal interface to send our usual actions
|
@@ -10,55 +10,32 @@ require_relative './basic_decorator'
|
|
10
10
|
# appsignal_logger.info metrics: [:counter_1, :counter_2]
|
11
11
|
# appsignal_logger.info metrics: { counter_1: { type: :counter, value: 1 }, gauce_2: { type: :gauce, value: 10 } }
|
12
12
|
module EventTracer
|
13
|
-
class AppsignalLogger <
|
13
|
+
class AppsignalLogger < MetricLogger
|
14
14
|
|
15
15
|
SUPPORTED_METRIC_TYPES = {
|
16
16
|
counter: :increment_counter,
|
17
17
|
distribution: :add_distribution_value,
|
18
18
|
gauge: :set_gauge
|
19
|
-
}
|
19
|
+
}.freeze
|
20
20
|
DEFAULT_METRIC_TYPE = :increment_counter
|
21
21
|
DEFAULT_COUNTER = 1
|
22
22
|
|
23
|
-
attr_reader :allowed_tags
|
24
|
-
|
25
23
|
def initialize(decoratee, allowed_tags: [])
|
26
24
|
super(decoratee)
|
27
25
|
@allowed_tags = allowed_tags.freeze
|
28
26
|
end
|
29
27
|
|
30
|
-
|
31
|
-
define_method log_type do |**args|
|
32
|
-
metrics = args[:metrics]
|
33
|
-
|
34
|
-
return fail_result('Invalid appsignal config') unless valid_args?(metrics)
|
35
|
-
return success_result if metrics.empty?
|
36
|
-
|
37
|
-
tags = args.slice(*allowed_tags)
|
38
|
-
|
39
|
-
case metrics
|
40
|
-
when Array
|
41
|
-
metrics.each do |metric|
|
42
|
-
appsignal.public_send(DEFAULT_METRIC_TYPE, metric, DEFAULT_COUNTER, tags)
|
43
|
-
end
|
44
|
-
when Hash
|
45
|
-
metrics.each do |metric_name, metric_payload|
|
46
|
-
payload = metric_payload.transform_keys(&:to_sym)
|
47
|
-
metric_type = SUPPORTED_METRIC_TYPES[payload.fetch(:type).to_sym]
|
48
|
-
appsignal.public_send(metric_type, metric_name, payload.fetch(:value), tags) if metric_type
|
49
|
-
end
|
50
|
-
end
|
28
|
+
private
|
51
29
|
|
52
|
-
|
30
|
+
def send_metric(metric_type, metric_name, value, tags)
|
31
|
+
appsignal.public_send(metric_type, metric_name, value, tags)
|
53
32
|
end
|
54
|
-
end
|
55
33
|
|
56
|
-
|
34
|
+
def build_tags(args)
|
35
|
+
args.slice(*allowed_tags)
|
36
|
+
end
|
57
37
|
|
58
38
|
alias_method :appsignal, :decoratee
|
59
39
|
|
60
|
-
def valid_args?(metrics)
|
61
|
-
metrics && (metrics.is_a?(Hash) || metrics.is_a?(Array))
|
62
|
-
end
|
63
40
|
end
|
64
41
|
end
|
data/lib/event_tracer/buffer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require_relative './
|
1
|
+
require_relative './metric_logger'
|
2
|
+
|
2
3
|
# NOTES
|
3
4
|
# Datadog interface to send our usual actions
|
4
5
|
# BasicDecorator adds a transparent interface on top of the datadog interface
|
@@ -10,7 +11,7 @@ require_relative './basic_decorator'
|
|
10
11
|
# data_dog_logger.info metrics: { counter_1: { type: :counter, value: 1}, gauce_2: { type: :gauce, value: 10 } }
|
11
12
|
|
12
13
|
module EventTracer
|
13
|
-
class DatadogLogger <
|
14
|
+
class DatadogLogger < MetricLogger
|
14
15
|
|
15
16
|
SUPPORTED_METRIC_TYPES = {
|
16
17
|
counter: :count,
|
@@ -22,50 +23,20 @@ module EventTracer
|
|
22
23
|
DEFAULT_METRIC_TYPE = :count
|
23
24
|
DEFAULT_COUNTER = 1
|
24
25
|
|
25
|
-
attr_reader :allowed_tags
|
26
|
-
|
27
26
|
def initialize(decoratee, allowed_tags: [], default_tags: {})
|
28
27
|
super(decoratee)
|
29
28
|
@allowed_tags = allowed_tags.freeze
|
30
29
|
@default_tags = default_tags.freeze
|
31
30
|
end
|
32
31
|
|
33
|
-
|
34
|
-
define_method log_type do |**args|
|
35
|
-
metrics = args[:metrics]
|
36
|
-
|
37
|
-
return fail_result('Invalid Datadog config') unless valid_args?(metrics)
|
38
|
-
return success_result if metrics.empty?
|
39
|
-
|
40
|
-
tags = build_tags(args)
|
41
|
-
|
42
|
-
case metrics
|
43
|
-
when Array
|
44
|
-
metrics.each do |metric|
|
45
|
-
datadog.public_send(DEFAULT_METRIC_TYPE, metric, DEFAULT_COUNTER, tags: tags)
|
46
|
-
end
|
47
|
-
when Hash
|
48
|
-
metrics.each do |metric_name, metric_payload|
|
49
|
-
payload = metric_payload.transform_keys(&:to_sym)
|
50
|
-
metric_type = SUPPORTED_METRIC_TYPES[payload.fetch(:type).to_sym]
|
51
|
-
datadog.public_send(metric_type, metric_name, payload.fetch(:value), tags: tags) if metric_type
|
52
|
-
end
|
53
|
-
end
|
32
|
+
private
|
54
33
|
|
55
|
-
|
56
|
-
|
34
|
+
def send_metric(metric_type, metric_name, value, tags)
|
35
|
+
datadog.public_send(metric_type, metric_name, value, tags: tags)
|
57
36
|
end
|
58
37
|
|
59
|
-
private
|
60
|
-
|
61
38
|
alias_method :datadog, :decoratee
|
62
39
|
|
63
|
-
attr_reader :default_tags
|
64
|
-
|
65
|
-
def valid_args?(metrics)
|
66
|
-
metrics && (metrics.is_a?(Hash) || metrics.is_a?(Array))
|
67
|
-
end
|
68
|
-
|
69
40
|
def build_tags(args)
|
70
41
|
default_tags.merge(args.slice(*allowed_tags)).map do |tag, value|
|
71
42
|
"#{tag}:#{value}"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative './basic_decorator'
|
2
|
+
|
3
|
+
module EventTracer
|
4
|
+
class MetricLogger < BasicDecorator
|
5
|
+
|
6
|
+
attr_reader :allowed_tags
|
7
|
+
|
8
|
+
LOG_TYPES.each do |log_type|
|
9
|
+
define_method log_type do |**args|
|
10
|
+
metrics = args[:metrics]
|
11
|
+
|
12
|
+
return fail_result("Invalid metrics for #{self.class.name}") unless valid_args?(metrics)
|
13
|
+
return success_result if metrics.empty?
|
14
|
+
|
15
|
+
tags = build_tags(args)
|
16
|
+
|
17
|
+
case metrics
|
18
|
+
when Array
|
19
|
+
metrics.each do |metric|
|
20
|
+
send_metric(self.class::DEFAULT_METRIC_TYPE, metric, self.class::DEFAULT_COUNTER, tags)
|
21
|
+
end
|
22
|
+
when Hash
|
23
|
+
metrics.each do |metric_name, metric_payload|
|
24
|
+
payload = metric_payload.transform_keys(&:to_sym)
|
25
|
+
metric_type = self.class::SUPPORTED_METRIC_TYPES[payload.fetch(:type).to_sym]
|
26
|
+
send_metric(metric_type, metric_name, payload.fetch(:value), tags) if metric_type
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
success_result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :default_tags
|
37
|
+
|
38
|
+
def valid_args?(metrics)
|
39
|
+
metrics && (metrics.is_a?(Hash) || metrics.is_a?(Array))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,13 +1,14 @@
|
|
1
|
+
require_relative './metric_logger'
|
2
|
+
|
1
3
|
module EventTracer
|
2
|
-
class PrometheusLogger <
|
4
|
+
class PrometheusLogger < MetricLogger
|
3
5
|
|
4
6
|
SUPPORTED_METRIC_TYPES = {
|
5
7
|
counter: :increment_count,
|
6
8
|
gauge: :set_gauge
|
7
9
|
}.freeze
|
8
|
-
|
9
|
-
|
10
|
-
attr_reader :allowed_tags
|
10
|
+
DEFAULT_METRIC_TYPE = :increment_count
|
11
|
+
DEFAULT_COUNTER = 1
|
11
12
|
|
12
13
|
def initialize(prometheus, allowed_tags: [], default_tags: {}, raise_if_missing: true)
|
13
14
|
super(prometheus)
|
@@ -16,49 +17,15 @@ module EventTracer
|
|
16
17
|
@raise_if_missing = raise_if_missing
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
define_method log_type do |**args|
|
21
|
-
metrics = args[:metrics]
|
22
|
-
|
23
|
-
return fail_result('Invalid metrics for Prometheus') unless valid_args?(metrics)
|
24
|
-
return success_result if metrics.empty?
|
25
|
-
|
26
|
-
labels = build_metric_labels(args)
|
27
|
-
|
28
|
-
case metrics
|
29
|
-
when Array
|
30
|
-
metrics.each do |metric_name|
|
31
|
-
increment_count(metric_name, DEFAULT_INCREMENT, labels: labels)
|
32
|
-
end
|
33
|
-
when Hash
|
34
|
-
metrics.each do |metric_name, metric_payload|
|
35
|
-
payload = metric_payload.transform_keys(&:to_sym)
|
36
|
-
metric_type = SUPPORTED_METRIC_TYPES[payload.fetch(:type).to_sym]
|
37
|
-
|
38
|
-
if metric_type
|
39
|
-
send(
|
40
|
-
metric_type,
|
41
|
-
metric_name,
|
42
|
-
payload.fetch(:value),
|
43
|
-
labels: labels
|
44
|
-
)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
20
|
+
private
|
48
21
|
|
49
|
-
|
22
|
+
def send_metric(metric_type, metric_name, value, labels)
|
23
|
+
send(metric_type, metric_name, value, labels: labels)
|
50
24
|
end
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
25
|
|
55
26
|
alias_method :prometheus, :decoratee
|
56
27
|
|
57
|
-
attr_reader :
|
58
|
-
|
59
|
-
def valid_args?(metrics)
|
60
|
-
metrics && (metrics.is_a?(Hash) || metrics.is_a?(Array))
|
61
|
-
end
|
28
|
+
attr_reader :raise_if_missing
|
62
29
|
|
63
30
|
def increment_count(metric_name, value, labels:)
|
64
31
|
metric = get_metric(metric_name.to_sym, :counter)
|
@@ -84,7 +51,7 @@ module EventTracer
|
|
84
51
|
)
|
85
52
|
end
|
86
53
|
|
87
|
-
def
|
54
|
+
def build_tags(args)
|
88
55
|
allowed_tags.inject(default_tags) do |metric_labels, tag|
|
89
56
|
metric_labels.merge(tag => args[tag])
|
90
57
|
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.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- melvrickgoh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/event_tracer/dynamo_db/worker.rb
|
103
103
|
- lib/event_tracer/error_with_payload.rb
|
104
104
|
- lib/event_tracer/log_result.rb
|
105
|
+
- lib/event_tracer/metric_logger.rb
|
105
106
|
- lib/event_tracer/prometheus_logger.rb
|
106
107
|
- lib/event_tracer/version.rb
|
107
108
|
homepage: https://github.com/melvrickgoh/event_tracer
|