action_reporter 1.0.3 → 1.0.4

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: 49736906f57c97cd86a7f0963fa78a63d6cbbb9d0fe03d601b987b376dca8e00
4
+ data.tar.gz: 6446a9feb95c216715b07b1775239b600a2ad1ae8083f7fbacdf86cd97b44469
5
5
  SHA512:
6
- metadata.gz: a06f86134a8c2499ee2c282189984a9ae8ede582dcae5d03db9cdcba656ef4540283089f3dd7cf1b54c7a4910d28b35ce5a876ba012cfc8fd1e52ae27bc43cd9
7
- data.tar.gz: 243a13b9eae0f41dab7bd49d0fad1c1538eea0b08d8d6f833daa90cbc2943ee73806012d4108e4100574508157f763fa30fc51cd9c7efeb545b308865ae6b1ad
6
+ metadata.gz: 7294c392d117b9a54625bb80b417c489408e2068d33b9338ec8d3bc60a0a91f3e360163fdcc9e6830eba1231a35ec5fe49f9c58b089f60e983e841302f80ede1
7
+ data.tar.gz: 047d3ee881ea607458bd29d97dfcb72e3aee38b899aaa2893532a38ccf1f9c466ffd58b4459a0d70355e895a722419ac11cacca60e6f213c3b9cdbe978541715
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.4
2
+
3
+ * Move `transform_context` to individual reporter classes
4
+
1
5
  # 1.0.3
2
6
 
3
7
  * 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.4"
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
@@ -8,13 +8,12 @@ module ActionReporter
8
8
  end
9
9
 
10
10
  def context(args)
11
- args.each do |key, value|
12
- Sentry.configure_scope { |scope| scope.set_context(key, value) }
13
- end
11
+ new_context = transform_context(args)
12
+ Sentry.set_context(args)
14
13
  end
15
14
 
16
- def reset_context
17
- Sentry.configure_scope { |scope| scope.clear_breadcrumbs }
15
+ def audited_user=(user)
16
+ Sentry.set_user(global_id: user.to_global_id.to_s) if user
18
17
  end
19
18
  end
20
19
  end
@@ -1,3 +1,3 @@
1
1
  module ActionReporter
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov