action_reporter 1.0.2 → 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: '0569ae232aed54ea4777b366d95fef80a4058d02a2c22bccdf1a56614282ff99'
4
- data.tar.gz: 22317e6ea26f6a06f1626a7812ed65dbee279b9b45f6485166cb0c2bc0da7bf1
3
+ metadata.gz: 49736906f57c97cd86a7f0963fa78a63d6cbbb9d0fe03d601b987b376dca8e00
4
+ data.tar.gz: 6446a9feb95c216715b07b1775239b600a2ad1ae8083f7fbacdf86cd97b44469
5
5
  SHA512:
6
- metadata.gz: 34c9ca0d8dfed3925742e698a2f013aebdda61bbad8f6a63e5751e42cb56c57d605b67965fa612dee07e2d84d467fd749abe3d460ad4ad9a921568817f9bfdb8
7
- data.tar.gz: 00b99d87c2ece2ba07779ab176b063e7ef862466f4f7354905da3272b8a7b622b7775f7e92cb144615c4759667be7d98ae2f704cbcfc94c5c198f22bda3ac6e3
6
+ metadata.gz: 7294c392d117b9a54625bb80b417c489408e2068d33b9338ec8d3bc60a0a91f3e360163fdcc9e6830eba1231a35ec5fe49f9c58b089f60e983e841302f80ede1
7
+ data.tar.gz: 047d3ee881ea607458bd29d97dfcb72e3aee38b899aaa2893532a38ccf1f9c466ffd58b4459a0d70355e895a722419ac11cacca60e6f213c3b9cdbe978541715
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 1.0.4
2
+
3
+ * Move `transform_context` to individual reporter classes
4
+
5
+ # 1.0.3
6
+
7
+ * Fix scoutapm notice method
8
+
1
9
  # 1.0.2
2
10
 
3
11
  * Add ruby version support for versions lower than 3.2.0
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "action_reporter"
3
- s.version = "1.0.2"
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
@@ -1,14 +1,16 @@
1
1
  module ActionReporter
2
2
  class ScoutApmReporter < Base
3
- class_accessor "ScoutApm::Agent"
3
+ class_accessor "ScoutApm::Error"
4
4
  class_accessor "ScoutApm::Context"
5
5
 
6
- def notify(*args, **kwargs)
7
- ScoutApmAgent.instance.error(*args, **kwargs)
6
+ def notify(error, context: {})
7
+ self.context(context)
8
+ ScoutApmError.capture(error)
8
9
  end
9
10
 
10
11
  def context(args)
11
- ScoutApmContext.add(args)
12
+ new_context = transform_context(args)
13
+ ScoutApmContext.add(new_context)
12
14
  end
13
15
  end
14
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.2'
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.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov