action_reporter 1.4.0 → 1.5.0

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: 14d5c87c8d8a4b89f4f0e18f67588d41b01d56e3fecc4ee3bcf40f634c08e9d9
4
- data.tar.gz: 0d49b5255bad01955454477adc0166d077e403976823e75659ed996a9843123a
3
+ metadata.gz: f663c691abaa4b55ce115001639b405521d07ee55b9bb37ec838c26f28e2fd4d
4
+ data.tar.gz: 4acb1954e62b1ecbfe19ba4112b1147bba8c44cbd703052bfba433b7aacd4cea
5
5
  SHA512:
6
- metadata.gz: 49dac3148afba57f4f7ebaf7e17ef2ca57cf4ea9d1f14a5ad5e748bbad3d143c2e2be28f99990295a66d307d4cb9c7dbb36a71a9a163701b825402bd3eebfd2e
7
- data.tar.gz: 5e66cdd226d395f552c56b9616fba0357a7695225f431dfbf5f3b4d302cfac58f68017720839b3911b190415fff55e319b761c82c718399d67926cd8b2b936e2
6
+ metadata.gz: 2d4554027681577f761d588d77a61e6745951de6b39671e8ff75e0d8190bb81173ece7cd521190a801a277cbf52392b7f816e40ae470115fa424381c75a3018e
7
+ data.tar.gz: 37265ec7091183773a6261ac2ae1b0e006f77bbd050bd03bfd48b18d1c17f3a1d661707024602cfeb76a4a5a1cc87a78193f0aa0f0d64c563b59a526e4213c88
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 1.5.0
2
+
3
+ * BREAKING: Rename `audited_user` to `current_user`
4
+ * Add `current_request_uuid` and `current_remote_addr` getters and setters
5
+ * Memoize `current_user`, `current_request_uuid`, and `current_remote_addr`
6
+
7
+ # 1.4.1
8
+
9
+ * Add paper_trail support
10
+
1
11
  # 1.4.0
2
12
 
3
13
  * Set minimum ruby version requirement to 2.5.0
data/README.md CHANGED
@@ -1,12 +1,15 @@
1
1
  # action_reporter
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/action_reporter.svg)](https://badge.fury.io/rb/action_reporter) [![Test Status](https://github.com/amkisko/action_reporter.rb/actions/workflows/test.yml/badge.svg)](https://github.com/amkisko/action_reporter.rb/actions/workflows/test.yml)
3
+ [![Gem Version](https://badge.fury.io/rb/action_reporter.svg)](https://badge.fury.io/rb/action_reporter) [![Test Status](https://github.com/amkisko/action_reporter.rb/actions/workflows/test.yml/badge.svg)](https://github.com/amkisko/action_reporter.rb/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/amkisko/action_reporter.rb/graph/badge.svg?token=JCV2A7NWTE)](https://codecov.io/gh/amkisko/action_reporter.rb)
4
+
5
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/f4bef9a52eac43a5a0f6d8c1b58cc6af)](https://app.codacy.com/gh/amkisko/action_reporter.rb/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/f4bef9a52eac43a5a0f6d8c1b58cc6af)](https://app.codacy.com/gh/amkisko/action_reporter.rb/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
4
6
 
5
7
  Ruby wrapper for multiple reporting services.
6
8
 
7
9
  Supported services:
8
10
  - Rails logger
9
11
  - Audited
12
+ - PaperTrail
10
13
  - Sentry
11
14
  - Honeybadger
12
15
  - scoutapm
@@ -39,6 +42,7 @@ Put this in your `config/initializers/action_reporter.rb` file:
39
42
  ActionReporter.enabled_reporters = [
40
43
  ActionReporter::RailsReporter.new,
41
44
  # ActionReporter::AuditedReporter.new,
45
+ # ActionReporter::PaperTrailReporter.new,
42
46
  # ActionReporter::SentryReporter.new,
43
47
  # ActionReporter::HoneybadgerReporter.new,
44
48
  # ActionReporter::ScoutApmReporter.new
@@ -48,15 +52,40 @@ ActionReporter.enabled_reporters = [
48
52
  Then you can use it in your code:
49
53
 
50
54
  ```ruby
51
- ActionReporter.audited_user = current_user
55
+ ActionReporter.current_user = current_user
56
+ ActionReporter.current_request_uuid = request.env['action_dispatch.request_id']
57
+ ActionReporter.current_remote_addr = request.env['action_dispatch.remote_ip']
52
58
  ActionReporter.context(entry_id: entry.id)
53
59
  ActionReporter.notify('Something went wrong', context: { record: record })
54
60
  ```
55
61
 
62
+ ## Hook debugger to notify method
63
+
64
+ Apply patch on initializer level or before running the main code:
65
+
66
+ ```ruby
67
+ module ActionReporter
68
+ class RailsReporter < Base
69
+ def notify(error, context: {})
70
+ super
71
+ binding.pry
72
+ end
73
+ end
74
+ end
75
+ ```
76
+
56
77
  ## Contributing
57
78
 
58
79
  Bug reports and pull requests are welcome on GitHub at https://github.com/amkisko/action_reporter.rb
59
80
 
81
+ Contribution policy:
82
+ - It might take up to 2 calendar weeks to review and merge critical fixes
83
+ - It might take up to 6 calendar months to review and merge pull request
84
+ - It might take up to 1 calendar year to review an issue
85
+ - New integrations and third-party features are not nessessarily added to the gem
86
+ - Pull request should have test coverage for affected parts
87
+ - Pull request should have changelog entry
88
+
60
89
  ## Publishing
61
90
 
62
91
  ```sh
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "action_reporter"
3
- gem.version = File.read(File.expand_path('../lib/action_reporter.rb', __FILE__)).match(/VERSION\s*=\s*'(.*?)'/)[1]
3
+ gem.version = File.read(File.expand_path("../lib/action_reporter.rb", __FILE__)).match(/VERSION\s*=\s*'(.*?)'/)[1]
4
4
 
5
5
  gem.license = "MIT"
6
6
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
21
21
  "rubygems_mfa_required" => "true"
22
22
  }
23
23
 
24
- gem.files = Dir.glob("lib/**/*.rb") + Dir.glob("bin/**/*") + %w(CHANGELOG.md LICENSE.md README.md action_reporter.gemspec)
24
+ gem.files = Dir.glob("lib/**/*.rb") + Dir.glob("bin/**/*") + %w[CHANGELOG.md LICENSE.md README.md action_reporter.gemspec]
25
25
 
26
26
  # s.bindir = "bin"
27
27
  # s.executables = ["action_reporter"]
@@ -29,15 +29,17 @@ Gem::Specification.new do |gem|
29
29
  gem.required_ruby_version = ">= 2.5.0"
30
30
  gem.require_path = "lib"
31
31
 
32
- gem.add_runtime_dependency 'rails', '> 5'
33
- gem.add_runtime_dependency 'audited', '~> 5'
34
- gem.add_runtime_dependency 'honeybadger', '~> 5'
35
- gem.add_runtime_dependency 'sentry-ruby', '~> 5'
36
- gem.add_runtime_dependency 'scout_apm', '~> 5'
37
-
38
- gem.add_development_dependency 'rspec', '~> 3'
39
- gem.add_development_dependency 'webmock', '~> 3'
40
- gem.add_development_dependency 'pry', '~> 0.14'
41
- gem.add_development_dependency 'simplecov', '~> 0.21'
42
- gem.add_development_dependency 'simplecov-cobertura', '~> 2'
32
+ gem.add_runtime_dependency "rails", "> 5"
33
+
34
+ gem.add_development_dependency "audited", "~> 5"
35
+ gem.add_development_dependency "honeybadger", "~> 5"
36
+ gem.add_development_dependency "sentry-ruby", "~> 5"
37
+ gem.add_development_dependency "scout_apm", "~> 5"
38
+ gem.add_development_dependency "paper_trail", "~> 15"
39
+
40
+ gem.add_development_dependency "rspec", "~> 3"
41
+ gem.add_development_dependency "webmock", "~> 3"
42
+ gem.add_development_dependency "pry", "~> 0.14"
43
+ gem.add_development_dependency "simplecov", "~> 0.21"
44
+ gem.add_development_dependency "simplecov-cobertura", "~> 2"
43
45
  end
@@ -6,22 +6,36 @@ module ActionReporter
6
6
  end
7
7
 
8
8
  def context(args)
9
- Audited.store[:current_remote_address] = args[:remote_addr] if args[
10
- :remote_addr
11
- ].present?
12
9
  end
13
10
 
14
11
  def reset_context
15
12
  Audited.store.delete(:current_remote_address)
16
- Audited.store.delete(:audited_user)
13
+ Audited.store.delete(:current_request_uuid)
14
+ Audited.store.delete(:current_user)
17
15
  end
18
16
 
19
- def audited_user
20
- Audited.store[:audited_user]
17
+ def current_user
18
+ Audited.store[:current_user]
21
19
  end
22
20
 
23
- def audited_user=(user)
24
- Audited.store[:audited_user] = user
21
+ def current_user=(user)
22
+ Audited.store[:current_user] = user
23
+ end
24
+
25
+ def current_request_uuid
26
+ Audited.store[:current_request_uuid]
27
+ end
28
+
29
+ def current_request_uuid=(request_uuid)
30
+ Audited.store[:current_request_uuid] = request_uuid
31
+ end
32
+
33
+ def current_remote_addr
34
+ Audited.store[:current_remote_address]
35
+ end
36
+
37
+ def current_remote_addr=(remote_addr)
38
+ Audited.store[:current_remote_address] = remote_addr
25
39
  end
26
40
  end
27
41
  end
@@ -21,7 +21,7 @@ module ActionReporter
21
21
  honeybadger_class.check_in(check_in_id)
22
22
  end
23
23
 
24
- def audited_user=(user)
24
+ def current_user=(user)
25
25
  honeybadger_class.context(user_global_id: user.to_global_id.to_s) if user
26
26
  end
27
27
  end
@@ -0,0 +1,23 @@
1
+ module ActionReporter
2
+ class PaperTrailReporter < Base
3
+ class_accessor "PaperTrail", gem_spec: "paper_trail (~> 15)"
4
+
5
+ def notify(*)
6
+ end
7
+
8
+ def context(args)
9
+ end
10
+
11
+ def reset_context
12
+ PaperTrail.request.whodunnit = nil
13
+ end
14
+
15
+ def current_user
16
+ PaperTrail.request.whodunnit
17
+ end
18
+
19
+ def current_user=(user)
20
+ PaperTrail.request.whodunnit = user
21
+ end
22
+ end
23
+ end
@@ -13,8 +13,12 @@ module ActionReporter
13
13
  scoutapm_context_class.add(new_context)
14
14
  end
15
15
 
16
- def audited_user=(user)
16
+ def current_user=(user)
17
17
  scoutapm_context_class.add_user(user_global_id: user&.to_global_id&.to_s)
18
18
  end
19
+
20
+ def ignore_transaction!
21
+ scoutapm_context_class.ignore_transaction!
22
+ end
19
23
  end
20
24
  end
@@ -22,7 +22,7 @@ module ActionReporter
22
22
  sentry_class.get_current_scope.set_context("context", {})
23
23
  end
24
24
 
25
- def audited_user=(user)
25
+ def current_user=(user)
26
26
  sentry_class.set_user(user_global_id: user&.to_global_id&.to_s)
27
27
  end
28
28
  end
@@ -5,18 +5,20 @@ require 'action_reporter/honeybadger_reporter'
5
5
  require 'action_reporter/sentry_reporter'
6
6
  require 'action_reporter/scout_apm_reporter'
7
7
  require 'action_reporter/audited_reporter'
8
+ require 'action_reporter/paper_trail_reporter'
8
9
 
9
10
  module ActionReporter
10
11
  module_function
11
12
 
12
- VERSION = '1.4.0'.freeze
13
+ VERSION = '1.5.0'.freeze
13
14
 
14
15
  AVAILABLE_REPORTERS = [
15
16
  ActionReporter::RailsReporter,
16
17
  ActionReporter::HoneybadgerReporter,
17
18
  ActionReporter::SentryReporter,
18
19
  ActionReporter::ScoutApmReporter,
19
- ActionReporter::AuditedReporter
20
+ ActionReporter::AuditedReporter,
21
+ ActionReporter::PaperTrailReporter
20
22
  ].freeze
21
23
 
22
24
  @enabled_reporters = []
@@ -53,15 +55,42 @@ module ActionReporter
53
55
  end
54
56
  end
55
57
 
56
- def audited_user
57
- enabled_reporters.find { |r| r.respond_to?(:audited_user) }&.audited_user
58
+ def current_user
59
+ @current_user
58
60
  end
59
61
 
60
- def audited_user=(user)
62
+ def current_user=(user)
63
+ @current_user = user
61
64
  enabled_reporters.each do |reporter|
62
- next unless reporter.respond_to?(:audited_user=)
65
+ next unless reporter.respond_to?(:current_user=)
63
66
 
64
- reporter.audited_user = user
67
+ reporter.current_user = user
68
+ end
69
+ end
70
+
71
+ def current_request_uuid
72
+ @current_request_uuid
73
+ end
74
+
75
+ def current_request_uuid=(request_uuid)
76
+ @current_request_uuid = request_uuid
77
+ enabled_reporters.each do |reporter|
78
+ next unless reporter.respond_to?(:current_request_uuid=)
79
+
80
+ reporter.current_request_uuid = request_uuid
81
+ end
82
+ end
83
+
84
+ def current_remote_addr
85
+ @current_remote_addr
86
+ end
87
+
88
+ def current_remote_addr=(remote_addr)
89
+ @current_remote_addr = remote_addr
90
+ enabled_reporters.each do |reporter|
91
+ next unless reporter.respond_to?(:current_remote_addr=)
92
+
93
+ reporter.current_remote_addr = remote_addr
65
94
  end
66
95
  end
67
96
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-30 00:00:00.000000000 Z
11
+ date: 2024-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -31,7 +31,7 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '5'
34
- type: :runtime
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -45,7 +45,7 @@ dependencies:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '5'
48
- type: :runtime
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
@@ -59,7 +59,7 @@ dependencies:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '5'
62
- type: :runtime
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -73,13 +73,27 @@ dependencies:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '5'
76
- type: :runtime
76
+ type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: paper_trail
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '15'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '15'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rspec
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -166,6 +180,7 @@ files:
166
180
  - lib/action_reporter/base.rb
167
181
  - lib/action_reporter/error.rb
168
182
  - lib/action_reporter/honeybadger_reporter.rb
183
+ - lib/action_reporter/paper_trail_reporter.rb
169
184
  - lib/action_reporter/rails_reporter.rb
170
185
  - lib/action_reporter/scout_apm_reporter.rb
171
186
  - lib/action_reporter/sentry_reporter.rb
@@ -194,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
209
  - !ruby/object:Gem::Version
195
210
  version: '0'
196
211
  requirements: []
197
- rubygems_version: 3.4.19
212
+ rubygems_version: 3.5.11
198
213
  signing_key:
199
214
  specification_version: 4
200
215
  summary: See description