action_reporter 1.0.3 → 1.0.5

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: de9e1d1bcb3e0d357840b7067b944679d1cfa9833e1cfc9fdbabe035edd1f44a
4
- data.tar.gz: 7a46f2699a6a7ef43dc9a9f90f638c95d289786009b688e4714c6b615d6a8743
3
+ metadata.gz: 32481c273e889f21cb750b677fdfd75fe7c1582b483e07a3024e79ecdbc14a44
4
+ data.tar.gz: d5b037711d2112362680f8f72483a9e3937985d8b06152e5839a777b36f118f7
5
5
  SHA512:
6
- metadata.gz: a06f86134a8c2499ee2c282189984a9ae8ede582dcae5d03db9cdcba656ef4540283089f3dd7cf1b54c7a4910d28b35ce5a876ba012cfc8fd1e52ae27bc43cd9
7
- data.tar.gz: 243a13b9eae0f41dab7bd49d0fad1c1538eea0b08d8d6f833daa90cbc2943ee73806012d4108e4100574508157f763fa30fc51cd9c7efeb545b308865ae6b1ad
6
+ metadata.gz: dcec530e56b6e82c019aff4475e970d6642d582620c37a1ca3f099163c3c3de0dde3a367e68de11a897edbf2f2c7ba00b057979b1ca71a1207f7b25549c94257
7
+ data.tar.gz: 1fad20c37845fb64fda7b4adfc81ba676b671bba8384b8d0e75752908fe5a3db1368e7d50ea808ea3cee3eb138fa19cd22064eec7f6384746ad1fea770de6116
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 1.0.5
2
+
3
+ * Fix Sentry reporting and context setting
4
+
5
+ # 1.0.4
6
+
7
+ * Move `transform_context` to individual reporter classes
8
+
1
9
  # 1.0.3
2
10
 
3
11
  * Fix scoutapm notice method
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "action_reporter"
3
- s.version = "1.0.3"
3
+ s.version = "1.0.5"
4
4
 
5
5
  s.license = "MIT"
6
6
 
@@ -2,10 +2,6 @@ module ActionReporter
2
2
  class AuditedReporter < Base
3
3
  class_accessor "Audited"
4
4
 
5
- def transform_context?
6
- false
7
- end
8
-
9
5
  def notify(*)
10
6
  end
11
7
 
@@ -13,9 +9,6 @@ module ActionReporter
13
9
  Audited.store[:current_remote_address] = args[:remote_addr] if args[
14
10
  :remote_addr
15
11
  ].present?
16
- Audited.store[:audited_user] = args[:audited_user] if args[
17
- :audited_user
18
- ].present?
19
12
  end
20
13
 
21
14
  def reset_context
@@ -26,5 +19,9 @@ module ActionReporter
26
19
  def audited_user
27
20
  Audited.store[:audited_user]
28
21
  end
22
+
23
+ def audited_user=(user)
24
+ Audited.store[:audited_user] = user
25
+ end
29
26
  end
30
27
  end
@@ -7,8 +7,14 @@ module ActionReporter
7
7
  const_set(const_name, Object.const_get(class_name))
8
8
  end
9
9
 
10
- def transform_context?
11
- true
10
+ def transform_context(context)
11
+ ActionReporter::Utils.deep_transform_values(context) do |value|
12
+ if value.respond_to?(:to_global_id)
13
+ value.to_global_id.to_s
14
+ else
15
+ value
16
+ end
17
+ end
12
18
  end
13
19
 
14
20
  def notify(*)
@@ -3,11 +3,13 @@ module ActionReporter
3
3
  class_accessor "Honeybadger"
4
4
 
5
5
  def notify(error, context: {})
6
- Honeybadger.notify(error, context: context)
6
+ new_context = transform_context(context)
7
+ Honeybadger.notify(error, context: new_context)
7
8
  end
8
9
 
9
10
  def context(args)
10
- Honeybadger.context(args)
11
+ new_context = transform_context(args)
12
+ Honeybadger.context(new_context)
11
13
  end
12
14
 
13
15
  def reset_context
@@ -3,16 +3,15 @@ module ActionReporter
3
3
  class_accessor "Rails"
4
4
 
5
5
  def notify(error, context: {})
6
+ new_context = transform_context(context)
6
7
  Rails.logger.info(
7
- "Reporter notification: #{error.inspect}, #{context.inspect}"
8
+ "Reporter notification: #{error.inspect}, #{new_context.inspect}"
8
9
  )
9
10
  end
10
11
 
11
12
  def context(args)
12
- Rails.logger.info("Reporter context: #{args.inspect}")
13
- end
14
-
15
- def reset_context
13
+ new_context = transform_context(args)
14
+ Rails.logger.info("Reporter context: #{new_context.inspect}")
16
15
  end
17
16
  end
18
17
  end
@@ -9,7 +9,8 @@ module ActionReporter
9
9
  end
10
10
 
11
11
  def context(args)
12
- ScoutApmContext.add(args)
12
+ new_context = transform_context(args)
13
+ ScoutApmContext.add(new_context)
13
14
  end
14
15
  end
15
16
  end
@@ -3,18 +3,24 @@ module ActionReporter
3
3
  class_accessor "Sentry"
4
4
 
5
5
  def notify(error, context: {})
6
- self.context(context)
7
- Sentry.capture_exception(error)
6
+ Sentry.with_scope do |temp_scope|
7
+ temp_scope.set_contexts(transform_context(context))
8
+
9
+ if error.is_a?(StandardError)
10
+ Sentry.capture_exception(error)
11
+ else
12
+ Sentry.capture_message(error)
13
+ end
14
+ end
8
15
  end
9
16
 
10
17
  def context(args)
11
- args.each do |key, value|
12
- Sentry.configure_scope { |scope| scope.set_context(key, value) }
13
- end
18
+ new_context = transform_context(args)
19
+ Sentry.get_current_scope.set_contexts(new_context)
14
20
  end
15
21
 
16
- def reset_context
17
- Sentry.configure_scope { |scope| scope.clear_breadcrumbs }
22
+ def audited_user=(user)
23
+ Sentry.set_user(global_id: user.to_global_id.to_s) if user
18
24
  end
19
25
  end
20
26
  end
@@ -1,3 +1,3 @@
1
1
  module ActionReporter
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.5'
3
3
  end
@@ -30,35 +30,37 @@ module ActionReporter
30
30
 
31
31
  def notify(error, context: {})
32
32
  enabled_reporters.each do |reporter|
33
- new_context =
34
- reporter.transform_context? ? transform_context(context) : context
35
- reporter.notify(error, context: new_context)
33
+ next unless reporter.respond_to?(:notify)
34
+
35
+ reporter.notify(error, context: context)
36
36
  end
37
37
  end
38
38
 
39
39
  def context(args)
40
40
  enabled_reporters.each do |reporter|
41
- new_args = reporter.transform_context? ? transform_context(args) : args
42
- reporter.context(new_args)
41
+ next unless reporter.respond_to?(:context)
42
+
43
+ reporter.context(args)
43
44
  end
44
45
  end
45
46
 
46
47
  def reset_context
47
- enabled_reporters.each(&:reset_context)
48
+ enabled_reporters.each do |reporter|
49
+ next unless reporter.respond_to?(:reset_context)
50
+
51
+ reporter.reset_context
52
+ end
48
53
  end
49
54
 
50
55
  def audited_user
51
56
  enabled_reporters.find { |r| r.respond_to?(:audited_user) }&.audited_user
52
57
  end
53
58
 
54
- def transform_context(context)
55
- filtered_context = context.reject { |k, _| k == :audited_user }
56
- ActionReporter::Utils.deep_transform_values(filtered_context) do |value|
57
- if value.respond_to?(:to_global_id)
58
- value.to_global_id.to_s
59
- else
60
- value
61
- end
59
+ def audited_user=(user)
60
+ enabled_reporters.each do |reporter|
61
+ next unless reporter.respond_to?(:audited_user=)
62
+
63
+ reporter.audited_user = user
62
64
  end
63
65
  end
64
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov