co_aspects 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6bb76c1733ed9e04c038330902a41c5988ee64a
4
- data.tar.gz: 823a7f324eaf090a1d4e51946514dde9eb9c8dfa
3
+ metadata.gz: 208d908a472f5db2270994e56545883d57cba04d
4
+ data.tar.gz: b954c735a140a3e0fa68303150b11dbc684e915b
5
5
  SHA512:
6
- metadata.gz: 1ea0d9be92f14f244926dd9e9a3358f6ecd9a5c80e8d7c1dc50d319fab0ca244aa483c65ce475c578b7cf3e09b8689464931a19d71cfd383212ffdb6767931e1
7
- data.tar.gz: 4c34bdb2542ec172c769b9d1a5cebbd964ab69c9bb81b583a1ef5a91b04d16028474bc27e2476fcc05a46a1daf66a44122540d126faa8bbb7ddcbf37094a53aa
6
+ metadata.gz: bd2578906c5f440c6f6bdf0b745d193b164d7c3f8a7b8e6928c045baaa7e2e254b2af3dcdcdc953965f549803a940ea061924b61a05b5be89df96c6b340cd339
7
+ data.tar.gz: 2ce68cc56570b695063bb99b72dc3d4d4fa7ed42556eed9dc2fd2991ed35d39c48de89bcea98296a6564ebd6700b4af7f3d3d4edc907daeb01c63c65de89ca1d
@@ -1,10 +1,17 @@
1
1
  require 'newrelic_rpm'
2
+ require_relative 'rescue_and_notify_error'
2
3
 
3
4
  module CoAspects
4
5
  module Aspects
5
6
  # Rescues any error and notifies NewRelic about it, without raising it
6
7
  # again.
7
8
  #
9
+ # If the exception responds to `newrelic_opts` then the return value will be
10
+ # used as the noticed error options.
11
+ #
12
+ # Important: The class `CoAspects::Aspects::RescueAndNotifyError` can be
13
+ # used as parent to custom error classes.
14
+ #
8
15
  # Important: If CoAspects::Aspects::RescueAndNotifyAspect.enable_test_mode!
9
16
  # is executed, then instead of calling NewRelic, it will raise the exception
10
17
  # as if this aspect didn't exist. It's to be used by tests, to see
@@ -56,7 +63,11 @@ module CoAspects
56
63
  if RescueAndNotifyAspect.test_mode
57
64
  raise e
58
65
  else
59
- NewRelic::Agent.notice_error(e, stack_trace: e.backtrace)
66
+ opts = {}
67
+ if e.respond_to?(:newrelic_opts)
68
+ opts.merge!(e.newrelic_opts)
69
+ end
70
+ NewRelic::Agent.notice_error(e, opts)
60
71
  end
61
72
  end
62
73
  end
@@ -0,0 +1,12 @@
1
+ module CoAspects
2
+ module Aspects
3
+ class RescueAndNotifyError < RuntimeError
4
+ attr_reader :newrelic_opts
5
+
6
+ def initialize(message, newrelic_opts)
7
+ super(message)
8
+ @newrelic_opts = newrelic_opts
9
+ end
10
+ end
11
+ end
12
+ end
@@ -40,7 +40,7 @@ module CoAspects
40
40
  # # => StatsD.increment('my_key.dynamic')
41
41
  class StatsIncrementAspect < Aspector::Base
42
42
  around interception_arg: true, method_arg: true do |interception, method, proxy, *args, &block|
43
- key = StatsdHelper.key(self.class,
43
+ key = StatsdHelper.key(self,
44
44
  method,
45
45
  args,
46
46
  interception.options[:annotation][:as],
@@ -41,7 +41,7 @@ module CoAspects
41
41
  # # => StatsD.measure('my_key.dynamic')
42
42
  class StatsMeasureAspect < Aspector::Base
43
43
  around interception_arg: true, method_arg: true do |interception, method, proxy, *args, &block|
44
- key = StatsdHelper.key(self.class,
44
+ key = StatsdHelper.key(self,
45
45
  method,
46
46
  args,
47
47
  interception.options[:annotation][:as],
@@ -7,13 +7,15 @@ module CoAspects
7
7
  klass.name.underscore.tr('/', '.') + ".#{method_name}"
8
8
  end
9
9
 
10
- def key(klass, method_name, method_args, statsd_prefix, statsd_block)
10
+ def key(instance, method_name, method_args, statsd_prefix, statsd_block)
11
11
  if statsd_prefix || statsd_block
12
12
  key = statsd_prefix.to_s
13
- key += statsd_block.call(*method_args) if statsd_block
13
+ if statsd_block
14
+ key += instance.instance_exec(*method_args, &statsd_block).to_s
15
+ end
14
16
  key.downcase
15
17
  else
16
- default_prefix(klass, method_name)
18
+ default_prefix(instance.class, method_name)
17
19
  end
18
20
  end
19
21
  end
@@ -1,3 +1,3 @@
1
1
  module CoAspects
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: co_aspects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaston Jorquera
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -133,6 +133,7 @@ files:
133
133
  - lib/co_aspects/aspects/deprecate_aspect.rb
134
134
  - lib/co_aspects/aspects/log_call_aspect.rb
135
135
  - lib/co_aspects/aspects/rescue_and_notify_aspect.rb
136
+ - lib/co_aspects/aspects/rescue_and_notify_error.rb
136
137
  - lib/co_aspects/aspects/stats_increment_aspect.rb
137
138
  - lib/co_aspects/aspects/stats_measure_aspect.rb
138
139
  - lib/co_aspects/aspects/statsd_helper.rb