sidekiq-logstash 3.0.0 → 3.2.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
  SHA256:
3
- metadata.gz: de10e32b59ccde04045df621855e1257e4290003c08686be06ac2691ff3eadce
4
- data.tar.gz: 2ae07b48658b5f72bef3fa621eef3f57eac826fbd976dcadd3ec2df6e4c74549
3
+ metadata.gz: 7da540744ff32bbe1218075f40fa979c9b5a9bdb7211c45df40ec8191b2b51cc
4
+ data.tar.gz: '09e58a7cd2504538079fc8493e7fef3a59a9217736a0b1bf1425f6ba208f20c8'
5
5
  SHA512:
6
- metadata.gz: 85183e59824a52c5f8394ba5d45e0ca7a8df48dc6b1f668c2c0e880102713a3f7678e19f141172a78909bf030186210d644101b93684edf2f513ef31dceee3e0
7
- data.tar.gz: a56567d1a6715345e11bc5292188bf20a7c3db4b11f433071def26f9a39e95a366e14ffbceaf537f56021211c0dc2607fc275b6bcf0a46da5fdef2a6154449ae
6
+ metadata.gz: 746c123b2341c14f1d565d830f489a5eddb6591ba56f6c72ffaafd737524126cd24df17fdc808af5b8271fa88f94c5e5356d37e923ba5327cf849a56080d7d7e
7
+ data.tar.gz: f79226102532246d67bffcbe478d6e30781838d995d7c50f627e6a309f49f1a1b347aa7dbc1720733985a217a98d9c97d77db71ff53097d4b29c8fcd217012bc
@@ -10,16 +10,20 @@ env:
10
10
  GIT_COMMIT_SHA: ${{ github.sha }}
11
11
  GIT_BRANCH: ${{ github.ref }}
12
12
 
13
+ permissions:
14
+ contents: read # to fetch code (actions/checkout)
15
+
13
16
  jobs:
14
17
  linting:
15
18
  runs-on: ubuntu-latest
16
19
 
17
20
  steps:
18
- - uses: actions/checkout@v2
21
+ - uses: actions/checkout@v4
19
22
  - uses: ruby/setup-ruby@v1
20
23
  with:
21
- ruby-version: 2.7
24
+ ruby-version: 3
22
25
  bundler-cache: true
26
+
23
27
  - name: Run rubocop
24
28
  run: bundle exec rubocop --format progress
25
29
  build:
@@ -27,13 +31,14 @@ jobs:
27
31
  runs-on: ubuntu-latest
28
32
  strategy:
29
33
  matrix:
30
- ruby: ['2.7', '3.0', '3.1']
34
+ ruby: ['3.0', '3.1', '3.2', '3.3']
31
35
 
32
36
  steps:
33
- - uses: actions/checkout@v2
37
+ - uses: actions/checkout@v4
34
38
  - uses: ruby/setup-ruby@v1
35
39
  with:
36
40
  ruby-version: ${{ matrix.ruby }}
37
41
  bundler-cache: true
42
+
38
43
  - name: Run tests
39
44
  run: bundle exec rake
@@ -10,12 +10,10 @@ jobs:
10
10
  runs-on: ubuntu-latest
11
11
 
12
12
  steps:
13
- - uses: actions/checkout@master
14
-
15
- - name: Set up Ruby 2.7
16
- uses: actions/setup-ruby@v1
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-ruby@v1
17
15
  with:
18
- ruby-version: 2.7.x
16
+ ruby-version: 3
19
17
 
20
18
  - name: Publish to RubyGems
21
19
  run: |
data/.rubocop.yml CHANGED
@@ -7,12 +7,15 @@ AllCops:
7
7
  DisplayCopNames: true
8
8
  DisplayStyleGuide: true
9
9
  NewCops: enable
10
- TargetRubyVersion: 2.7
10
+ TargetRubyVersion: 3.0
11
11
 
12
12
  Metrics/BlockLength:
13
13
  Exclude:
14
14
  - spec/**/*.rb
15
15
 
16
+ Metrics/ModuleLength:
17
+ Enabled: false
18
+
16
19
  Layout/LineLength:
17
20
  Max: 120
18
21
  Exclude:
data/Gemfile CHANGED
@@ -3,3 +3,9 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
+
7
+ gem 'factory_bot', github: 'thoughtbot/factory_bot', branch: 'main'
8
+ gem 'rake'
9
+ gem 'rspec'
10
+ gem 'rspec-json_expectations'
11
+ gem 'rubocop-performance'
data/README.md CHANGED
@@ -33,6 +33,7 @@ Sidekiq::Logstash turns your [Sidekiq](https://github.com/mperham/sidekiq) log i
33
33
  Add one of the following lines to your application's Gemfile:
34
34
 
35
35
  ```ruby
36
+ gem 'sidekiq-logstash', '~> 3.0' # Sidekiq 7
36
37
  gem 'sidekiq-logstash', '~> 2.0' # Sidekiq 6
37
38
  gem 'sidekiq-logstash', '< 2' # Sidekiq 5 or older
38
39
  ```
@@ -82,6 +83,13 @@ Sidekiq::Logstash.configure do |config|
82
83
  # by default, sidekiq-logstash removes the default error handler
83
84
  # to keep it, simply set this to true
84
85
  config.keep_default_error_handler = true
86
+
87
+ # To enable a log structure that includes details about exception causes,
88
+ # uncomment the following lines:
89
+ #
90
+ # config.log_job_exception_with_causes = true
91
+ # # To specify the maximum depth of causes to log:
92
+ # config.causes_logging_max_depth = 3 # Default is 2
85
93
  end
86
94
  ```
87
95
 
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Utility that allows us to get a hash representation of an exception
4
+ module ExceptionUtils
5
+ module_function
6
+
7
+ def get_exception_with_cause_hash(exc, parent_backtrace = nil, max_depth_left: 1)
8
+ error_hash = {
9
+ 'class' => exc.class.to_s,
10
+ 'message' => exc.message,
11
+ 'backtrace' => backtrace_for(exc, parent_backtrace)
12
+ }
13
+
14
+ if (cause = exc.cause) && max_depth_left.positive?
15
+ # Pass the current backtrace as the parent_backtrace to the cause to shorten cause's backtrace list
16
+ error_hash['cause'] = get_exception_with_cause_hash(cause, exc.backtrace, max_depth_left: max_depth_left - 1)
17
+ end
18
+
19
+ error_hash
20
+ end
21
+
22
+ def backtrace_for(exception, parent_backtrace = nil)
23
+ backtrace = exception.backtrace || []
24
+ if parent_backtrace
25
+ common_lines = backtrace.reverse.zip(parent_backtrace.reverse).take_while { |a, b| a == b }
26
+
27
+ backtrace = backtrace[0...-common_lines.length] if common_lines.any?
28
+ end
29
+
30
+ backtrace
31
+ end
32
+ end
@@ -27,7 +27,7 @@ module Sidekiq
27
27
 
28
28
  class CompiledFilter # :nodoc:
29
29
  def self.compile(filters)
30
- return ->(args) { args.dup } if filters.empty?
30
+ return lambda(&:dup) if filters.empty?
31
31
 
32
32
  strings = []
33
33
  regexps = []
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'sidekiq/exception_utils'
4
+
3
5
  module Sidekiq
4
6
  module Logging
5
7
  # Shared module with all the logics used by job loggers.
@@ -50,10 +52,24 @@ module Sidekiq
50
52
  payload['message'] += ": fail: #{payload['duration']} sec"
51
53
  payload['job_status'] = 'fail'
52
54
 
53
- exc = exc.cause || exc if exc.is_a? Sidekiq::JobRetry::Handled
54
- payload['error_message'] = exc.message
55
- payload['error'] = exc.class
56
- payload['error_backtrace'] = %('#{exc.backtrace.join("\n")}')
55
+ config = Sidekiq::Logstash.configuration
56
+ if config.log_job_exception_with_causes
57
+ payload['error'] = ExceptionUtils.get_exception_with_cause_hash(
58
+ exc, max_depth_left: config.causes_logging_max_depth
59
+ )
60
+ else
61
+ exc = exc.cause || exc if exc.is_a? Sidekiq::JobRetry::Handled
62
+ payload['error_message'] = exc.message
63
+ payload['error'] = exc.class.to_s
64
+ payload['error_backtrace'] = %('#{exc.backtrace.join("\n")}')
65
+ if (cause = exc.cause)
66
+ payload['error_cause'] = {
67
+ 'class' => cause.class.to_s,
68
+ 'message' => cause.message,
69
+ 'backtrace' => ExceptionUtils.backtrace_for(cause, exc.backtrace)
70
+ }
71
+ end
72
+ end
57
73
 
58
74
  process_payload(payload)
59
75
  end
@@ -4,11 +4,18 @@ module Sidekiq
4
4
  module Logstash
5
5
  # Class that allows to configure the gem behaviour.
6
6
  class Configuration
7
- attr_accessor :custom_options, :filter_args, :job_start_log, :keep_default_error_handler
7
+ attr_accessor :custom_options,
8
+ :filter_args,
9
+ :job_start_log,
10
+ :keep_default_error_handler,
11
+ :log_job_exception_with_causes,
12
+ :causes_logging_max_depth
8
13
 
9
14
  def initialize
10
15
  @filter_args = []
11
16
  @job_start_log = false
17
+ @log_job_exception_with_causes = false
18
+ @causes_logging_max_depth = 2
12
19
  end
13
20
 
14
21
  # Added to ensure custom_options is a Proc
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Logstash
5
- VERSION = '3.0.0'
5
+ VERSION = '3.2.0'
6
6
  end
7
7
  end
@@ -4,7 +4,6 @@ require 'sidekiq/logstash/configuration'
4
4
  require 'sidekiq/logstash/version'
5
5
  require 'sidekiq/logging/logstash_formatter'
6
6
  require 'sidekiq/logging/argument_filter'
7
- require 'sidekiq/logstash_job_logger'
8
7
 
9
8
  module Sidekiq
10
9
  # Main level module for Sidekiq::Logstash.
@@ -22,6 +21,8 @@ module Sidekiq
22
21
  def self.setup(_opts = {})
23
22
  # Calls Sidekiq.configure_server to inject logics
24
23
  Sidekiq.configure_server do |config|
24
+ require 'sidekiq/logstash_job_logger'
25
+
25
26
  # Remove default, noisy error handler,
26
27
  # unless LogStash.configuration.keep_default_error_handler is set to true
27
28
  unless configuration.keep_default_error_handler
@@ -19,15 +19,10 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
21
  spec.require_paths = ['lib']
22
- spec.required_ruby_version = '>= 2.7.0'
22
+ spec.required_ruby_version = '>= 3.0.0'
23
23
 
24
24
  spec.add_dependency 'logstash-event', '~> 1.2'
25
25
  spec.add_dependency 'sidekiq', '~> 7.0'
26
26
 
27
- spec.add_development_dependency 'factory_bot', '~> 6.1'
28
- spec.add_development_dependency 'rake', '>= 10'
29
- spec.add_development_dependency 'rspec', '~> 3.0'
30
- spec.add_development_dependency 'rspec-json_expectations', '~> 2.1.0'
31
- spec.add_development_dependency 'rubocop-performance', '~> 1.5'
32
27
  spec.metadata['rubygems_mfa_required'] = 'true'
33
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-logstash
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Giuffrida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-04 00:00:00.000000000 Z
11
+ date: 2024-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-event
@@ -38,76 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '7.0'
41
- - !ruby/object:Gem::Dependency
42
- name: factory_bot
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '6.1'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '6.1'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '10'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '10'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec-json_expectations
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 2.1.0
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 2.1.0
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop-performance
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '1.5'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '1.5'
111
41
  description: 'Sidekiq::Logstash turns your Sidekiq log into an organised, aggregated,
112
42
  JSON-syntax log ready to be sent to a logstash server.
113
43
 
@@ -130,6 +60,7 @@ files:
130
60
  - bin/console
131
61
  - bin/setup
132
62
  - bin/test_console
63
+ - lib/sidekiq/exception_utils.rb
133
64
  - lib/sidekiq/logging/argument_filter.rb
134
65
  - lib/sidekiq/logging/logstash_formatter.rb
135
66
  - lib/sidekiq/logging/shared.rb
@@ -151,14 +82,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
82
  requirements:
152
83
  - - ">="
153
84
  - !ruby/object:Gem::Version
154
- version: 2.7.0
85
+ version: 3.0.0
155
86
  required_rubygems_version: !ruby/object:Gem::Requirement
156
87
  requirements:
157
88
  - - ">="
158
89
  - !ruby/object:Gem::Version
159
90
  version: '0'
160
91
  requirements: []
161
- rubygems_version: 3.1.6
92
+ rubygems_version: 3.4.19
162
93
  signing_key:
163
94
  specification_version: 4
164
95
  summary: Logstash plugin for Sidekiq