event_tracer 0.1.2 → 0.2.0

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: e0d3f6878e332430d33a93d947d071c7dab8e13c9d43ab15198c197bef399718
4
- data.tar.gz: eacc10d2ae0cf10a22e025146e5a7c4d5d65ebeeb5d56876469819305ccebd20
3
+ metadata.gz: 8be7917ff4969abe550fba1973934f60eca36600b9e1e6b541061cae4da176fa
4
+ data.tar.gz: b92553317d9c5432bfd64d8242ed099283f6c059c9ecfaa01a1252311001f64b
5
5
  SHA512:
6
- metadata.gz: 95b2950a8df1ef173a55f79220c791e527b3c42aef9f3692b65b1d80d5e36b1f0977f862cf6cc569f743912f5978897cc3140108f69f7b81e76c3b50757e26bc
7
- data.tar.gz: a0a834562f85a6b66c1aab0fabdb65a6cf952f3da3058b3b2b7c12b949957ba1974d73df06ab3cac704fb364fec262226451093828bd5d6648e01c3759737871
6
+ metadata.gz: 7c0ce2be131339ef8b498ed2fd15267d9d0026b21bded4f01b58b576ce238455a9025345ebd2a9ea30e742b3357f6718aa12f20c56d35ae6729c3556ec043129
7
+ data.tar.gz: a6bbd25e1299c39d17b0f95e86047367f5bf45bd64dc6c945ea6c67c5cbe065fb3e2e32fffb451e61430266d8d92e83324ec4a916f2e9d977a7cb2f3e1bf44dc
@@ -0,0 +1,75 @@
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, EventTracer::DataDogLogger.new(DataDog)
8
+ # data_dog_logger.info datadog: { count: { counter_1: 1, counter_2: 2 }, set: { gauge_1: 1 } }
9
+ # data_dog_logger.info datadog: { count: { counter_1: { value: 1, tags: ['tag1, tag2']} } }
10
+
11
+ module EventTracer
12
+ class DatadogLogger < BasicDecorator
13
+
14
+ class InvalidTagError < StandardError; end
15
+
16
+ SUPPORTED_METRICS ||= %i[count set distribution gauge histogram].freeze
17
+
18
+ LOG_TYPES.each do |log_type|
19
+ define_method log_type do |**args|
20
+ return LogResult.new(false, 'Invalid datadog config') unless args[:datadog]&.is_a?(Hash)
21
+
22
+ applied_metrics(args[:datadog]).each do |metric|
23
+ metric_args = args[:datadog][metric]
24
+ return LogResult.new(false, "Datadog metric #{metric} invalid") unless metric_args.is_a?(Hash)
25
+
26
+ send_metric metric, metric_args
27
+ end
28
+
29
+ LogResult.new(true)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :datadog, :decoratee
36
+ alias_method :datadog, :decoratee
37
+
38
+ def applied_metrics(datadog_args)
39
+ datadog_args.keys.select { |metric| SUPPORTED_METRICS.include?(metric) }
40
+ end
41
+
42
+ def send_metric(metric, payload)
43
+ payload.each do |increment, attribute|
44
+ if attribute.is_a?(Hash)
45
+ begin
46
+ datadog.public_send(
47
+ metric,
48
+ increment,
49
+ attribute.fetch(:value),
50
+ build_options(attribute[:tags])
51
+ )
52
+ rescue KeyError
53
+ raise InvalidTagError, "Datadog payload { #{increment}: #{attribute} } invalid"
54
+ end
55
+ else
56
+ datadog.public_send(metric, increment, attribute)
57
+ end
58
+ end
59
+ end
60
+
61
+ def build_options(tags)
62
+ return {} unless tags
63
+
64
+ formattted_tags =
65
+ if tags.is_a?(Array)
66
+ tags
67
+ else
68
+ tags.inject([]) do |acc, (tag, value)|
69
+ acc << "#{tag}:#{value}"
70
+ end
71
+ end
72
+ { tags: formattted_tags }
73
+ end
74
+ end
75
+ end
@@ -1,3 +1,3 @@
1
1
  module EventTracer
2
- VERSION = "0.1.2"
2
+ VERSION = '0.2.0'.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.1.2
4
+ version: 0.2.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: 2019-11-04 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.17'
19
+ version: '2.0'
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: '1.17'
26
+ version: '2.0'
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.0.3
90
- signing_key:
90
+ rubygems_version: 3.1.4
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