sidekiq-logstash 3.1.0 → 3.2.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: '09e505554a5ed16d442f68da725e3647a2cd77d12f36897a657d54ff8a3cb8b8'
4
- data.tar.gz: 917723b1952886cfd29070668209e254198d2d9f3d2807aabbd10af0a5b46608
3
+ metadata.gz: 7da540744ff32bbe1218075f40fa979c9b5a9bdb7211c45df40ec8191b2b51cc
4
+ data.tar.gz: '09e58a7cd2504538079fc8493e7fef3a59a9217736a0b1bf1425f6ba208f20c8'
5
5
  SHA512:
6
- metadata.gz: f168b77deb49ef0eab0ff308ddfc8539d2b9cf6e1756373ed82301b5a7d5ac063ebefb16fd8a9941b4f0995066b5afcae54b8c9abf6caa1eea190841ca192c15
7
- data.tar.gz: ad292af73bb01ef763a1e171d1e960c345775db0128f2d904f32ee7166a654a33c065f2d0838c766e2f4057d5a84c054051c21e1945e1728ebb92bfbbb7018ce
6
+ metadata.gz: 746c123b2341c14f1d565d830f489a5eddb6591ba56f6c72ffaafd737524126cd24df17fdc808af5b8271fa88f94c5e5356d37e923ba5327cf849a56080d7d7e
7
+ data.tar.gz: f79226102532246d67bffcbe478d6e30781838d995d7c50f627e6a309f49f1a1b347aa7dbc1720733985a217a98d9c97d77db71ff53097d4b29c8fcd217012bc
data/.rubocop.yml CHANGED
@@ -13,6 +13,9 @@ 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/README.md CHANGED
@@ -83,6 +83,13 @@ Sidekiq::Logstash.configure do |config|
83
83
  # by default, sidekiq-logstash removes the default error handler
84
84
  # to keep it, simply set this to true
85
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
86
93
  end
87
94
  ```
88
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
@@ -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.1.0'
5
+ VERSION = '3.2.0'
6
6
  end
7
7
  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.1.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: 2024-09-03 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
@@ -60,6 +60,7 @@ files:
60
60
  - bin/console
61
61
  - bin/setup
62
62
  - bin/test_console
63
+ - lib/sidekiq/exception_utils.rb
63
64
  - lib/sidekiq/logging/argument_filter.rb
64
65
  - lib/sidekiq/logging/logstash_formatter.rb
65
66
  - lib/sidekiq/logging/shared.rb