event_tracer 0.6.1 → 0.6.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: bc787e6f2e531d8525792eec4d55f3576f7b6543e356319fce7c065c436385d6
4
- data.tar.gz: 22172cf85886ee0b668820d55bd13346997cd648b542337cc982c91510f01f50
3
+ metadata.gz: 77541537838df5e2de191b30cac6096e30ef9afbba5634c99ab7dceca8378f80
4
+ data.tar.gz: ce9067501e85318e4b22d731d9e28472e11b4142d70ff4d4e6b3049c5d5daf35
5
5
  SHA512:
6
- metadata.gz: d2afa747344e9e07aa85fa1d22a6612fca83df74e2bcfeb384b4f91e742e2d4a545c1070ceb9006592dff7bc97fefefe40ed4f326002f7f76119be24e9e26287
7
- data.tar.gz: c176243abadde0675d267138476b2dbe9cbe20f78a3d49a479c96e9a086abb83ff4df859da65029aadb115d7d42a83fddf630de32ed797e7f7c8d930dec05fcf
6
+ metadata.gz: 3980aee7c87f0e4b7aaad10def59b2a2d7cf6aa9facad6a34193dd453048c428c0553c735fae7294376ed44e574c3371854e56eb36ec77197094a96a55945354
7
+ data.tar.gz: 816e02c8bddc0444fba2f8e189789c887ef2f82fc3a76618af2ed56145b249a64f4f3a5ddbba7d0fc319b8da976a72a1cd897033046849549d775b7d5498ca33
@@ -1,4 +1,4 @@
1
- require_relative './basic_decorator'
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 < BasicDecorator
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
- LOG_TYPES.each do |log_type|
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
- success_result
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
- private
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
@@ -1,4 +1,5 @@
1
- require_relative './basic_decorator'
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 < BasicDecorator
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
- LOG_TYPES.each do |log_type|
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
- success_result
56
- end
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 < BasicDecorator
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
- DEFAULT_INCREMENT = 1
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
- LOG_TYPES.each do |log_type|
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
- success_result
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 :default_tags, :raise_if_missing
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 build_metric_labels(args)
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
@@ -1,3 +1,3 @@
1
1
  module EventTracer
2
- VERSION = '0.6.1'.freeze
2
+ VERSION = '0.6.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.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - melvrickgoh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-02 00:00:00.000000000 Z
11
+ date: 2022-06-22 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