event_tracer 0.4.5 → 0.5.1

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: db21e7db07d318ce6c78448f6e7ce6ae8819c89456708c9eac9b44dddde547b1
4
- data.tar.gz: dcc79806b5e10f6f34ebd19c8a77bdfcae27bb3c7b064811196b9617c4d3c0b8
3
+ metadata.gz: 3c2e5bbf4d4546e3ece6589508e00fc01eb30ca41b572ff2afbb4185b73c93d5
4
+ data.tar.gz: e3fe3b13cf8fc1e43732a75386502618427cab7a449fe95b8d2c69789383947b
5
5
  SHA512:
6
- metadata.gz: 6ab07f8de34b3c499a4b3b16c3d1e3895b4776dcca97e34a701d68bbdb1654312f7803d78e2d2c9e69a2a8173b8087e613749231de6eed1762eb24f6c6029220
7
- data.tar.gz: 37ef3ac7ded60e1c4d1ebe75e00e3a76b9ae2230f7eeba4b8961be96054bc5e54b2cc4b6a0e7224e30e232b7e27f80e3bcc88d308c0c0f1dafc244fb4082f073
6
+ metadata.gz: 17cd02fe83f7725b8e2a9d495979f5b183e2a63fc071b1b58795adfb910ed0c9048f1692b608d78d0348377b4c9216c1601481234ff60791206b2c1797e7d51f
7
+ data.tar.gz: ba23fdd140689fa467671a1f28024f38ea6b5c9e1ddd911c4980cbb91d57faf7a5ad2ce028aaffcead4f75d06ac4d5e30b0728525a3dac074ac366b8318f2797
@@ -43,8 +43,9 @@ module EventTracer
43
43
  end
44
44
  when Hash
45
45
  metrics.each do |metric_name, metric_payload|
46
- metric_type = SUPPORTED_METRIC_TYPES[metric_payload.fetch(:type).to_sym]
47
- appsignal.public_send(metric_type, metric_name, metric_payload.fetch(:value), tags) if metric_type
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
48
49
  end
49
50
  end
50
51
 
@@ -46,6 +46,8 @@ module EventTracer
46
46
  )
47
47
 
48
48
  worker.perform_async(filtered_payloads) if filtered_payloads.any?
49
+ rescue StandardError => error
50
+ raise EventTracer::ErrorWithPayload.new(error, payloads)
49
51
  end
50
52
 
51
53
  def filter_invalid_data(payloads)
@@ -12,6 +12,7 @@ module EventTracer
12
12
  setting :dynamo_db_table_name, default: 'logs'
13
13
  setting :dynamo_db_client
14
14
  setting :dynamo_db_queue_name, default: 'low'
15
+ setting :error_handler, default: ->(error, _payload) { raise error }
15
16
  else
16
17
  setting :app_name, 'app_name'
17
18
 
@@ -19,6 +20,7 @@ module EventTracer
19
20
  setting :dynamo_db_table_name, 'logs'
20
21
  setting :dynamo_db_client
21
22
  setting :dynamo_db_queue_name, 'low'
23
+ setting :error_handler, ->(error, _payload) { raise error }
22
24
  end
23
25
  end
24
26
  end
@@ -18,15 +18,16 @@ module EventTracer
18
18
  gauge: :gauge,
19
19
  set: :set,
20
20
  histogram: :histogram
21
- }
21
+ }.freeze
22
22
  DEFAULT_METRIC_TYPE = :count
23
23
  DEFAULT_COUNTER = 1
24
24
 
25
25
  attr_reader :allowed_tags
26
26
 
27
- def initialize(decoratee, allowed_tags: [])
27
+ def initialize(decoratee, allowed_tags: [], default_tags: {})
28
28
  super(decoratee)
29
29
  @allowed_tags = allowed_tags.freeze
30
+ @default_tags = default_tags.freeze
30
31
  end
31
32
 
32
33
  LOG_TYPES.each do |log_type|
@@ -45,8 +46,9 @@ module EventTracer
45
46
  end
46
47
  when Hash
47
48
  metrics.each do |metric_name, metric_payload|
48
- metric_type = SUPPORTED_METRIC_TYPES[metric_payload.fetch(:type).to_sym]
49
- datadog.public_send(metric_type, metric_name, metric_payload.fetch(:value), tags: tags) if metric_type
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
50
52
  end
51
53
  end
52
54
 
@@ -58,12 +60,14 @@ module EventTracer
58
60
 
59
61
  alias_method :datadog, :decoratee
60
62
 
63
+ attr_reader :default_tags
64
+
61
65
  def valid_args?(metrics)
62
66
  metrics && (metrics.is_a?(Hash) || metrics.is_a?(Array))
63
67
  end
64
68
 
65
69
  def build_tags(args)
66
- args.slice(*allowed_tags).map do |tag, value|
70
+ @default_tags.merge(args.slice(*allowed_tags)).map do |tag, value|
67
71
  "#{tag}:#{value}"
68
72
  end
69
73
  end
@@ -0,0 +1,10 @@
1
+ module EventTracer
2
+ class ErrorWithPayload < StandardError
3
+ attr_reader :payload
4
+
5
+ def initialize(error, payload)
6
+ super(error)
7
+ @payload = payload
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module EventTracer
2
- VERSION = '0.4.5'.freeze
2
+ VERSION = '0.5.1'.freeze
3
3
  end
data/lib/event_tracer.rb CHANGED
@@ -32,7 +32,15 @@ module EventTracer
32
32
 
33
33
  loggers.each do |code, logger|
34
34
  if args[:action] && args[:message]
35
- result.record code, logger.send(log_type, **args)
35
+ begin
36
+ result.record code, logger.send(log_type, **args)
37
+ rescue EventTracer::ErrorWithPayload => error
38
+ EventTracer::Config.config.error_handler.call(error.cause || error, error.payload)
39
+ result.record code, LogResult.new(false, error.message)
40
+ rescue StandardError => error
41
+ EventTracer::Config.config.error_handler.call(error, args)
42
+ result.record code, LogResult.new(false, error.message)
43
+ end
36
44
  else
37
45
  result.record code, LogResult.new(false, 'Fields action & message need to be populated')
38
46
  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.4.5
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - melvrickgoh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-22 00:00:00.000000000 Z
11
+ date: 2022-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -100,6 +100,7 @@ files:
100
100
  - lib/event_tracer/dynamo_db/default_processor.rb
101
101
  - lib/event_tracer/dynamo_db/logger.rb
102
102
  - lib/event_tracer/dynamo_db/worker.rb
103
+ - lib/event_tracer/error_with_payload.rb
103
104
  - lib/event_tracer/log_result.rb
104
105
  - lib/event_tracer/version.rb
105
106
  homepage: https://github.com/melvrickgoh/event_tracer