nadir 1.1.10 → 1.2.1

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: f9bdde9641cdde396db5ffc757bdad54d1e3a80bd5c50a5c0bfca0bd3b9eeb0a
4
- data.tar.gz: c7f25aca2ade3a7173cf4dc71608236adc1353a94d3f2ef046e8d25b161b7a08
3
+ metadata.gz: b235c9afa93b3a535bb7317ea48c5b3849c150d76c9809450531491256c2227a
4
+ data.tar.gz: 464956272e4cb23a6ef4833e0d03b3eee1bd158a19e9ab5b7c867323749eba0e
5
5
  SHA512:
6
- metadata.gz: a0c160705a8a8a094dd3636ea26ff7563c4b6ac877dfaa354c98e758ab515a724e1ebec4a5bce87184c9897372652853e284e0f1e8bfd984f638f734bb1f7033
7
- data.tar.gz: 0d6a5cbe7eb77aa54bce15443d1a777c18599a90ea095f7075fbe55e54167186c8daec90ecde224c0b7697bd787f0f44984bd6b965844bd7ca44ce5b7f579707
6
+ metadata.gz: e1208b36987f3b92d6d4bca79c3d3702bb7353f5ffb4c5b641974edacc4915925ef9ff0007ffc0014be3eb76b0ac285e7a451c9cc3c08296b7ed79da2e471afe
7
+ data.tar.gz: fae7ea7924ccc62f1faa3d0df4dd9e0bedcf44f4ec7a433f822a4ef2b61e798068a8a72f13964367d88852b815c101468d0718aadd31d07e55f7404084ae93c9
@@ -9,8 +9,8 @@ module Nadir
9
9
 
10
10
  def to_params
11
11
  {
12
- class: @exception.class.name,
13
- message: @exception.message,
12
+ class: notification_class,
13
+ message: message,
14
14
  location: location,
15
15
  backtrace: backtrace.join("\n"),
16
16
  environment: Nadir.config.env,
@@ -23,6 +23,7 @@ module Nadir
23
23
  request_headers: @params.dig(:request, :headers),
24
24
  user: @params.dig(:request, :user),
25
25
  job: @params.dig(:job),
26
+ context: @params.dig(:context),
26
27
  revision: revision
27
28
  }
28
29
  end
@@ -30,7 +31,29 @@ module Nadir
30
31
  private
31
32
 
32
33
  def location
33
- @params[:location] || $PROGRAM_NAME
34
+ return @params[:location] if @params[:location].present?
35
+
36
+ if $PROGRAM_NAME =~ /sidekiq/
37
+ @params.dig(:job, :class) || "Background job (Sidekiq)"
38
+ else
39
+ $PROGRAM_NAME
40
+ end
41
+ end
42
+
43
+ def notification_class
44
+ if @exception.is_a?(StandardError)
45
+ @exception.class.name
46
+ else
47
+ "Message"
48
+ end
49
+ end
50
+
51
+ def message
52
+ if @exception.is_a?(StandardError)
53
+ @exception.message
54
+ else
55
+ @exception
56
+ end
34
57
  end
35
58
 
36
59
  def backtrace
@@ -43,14 +66,22 @@ module Nadir
43
66
  cleaner.add_filter { |line| line.sub(Nadir.config.root.to_s, '') }
44
67
  cleaner.add_filter { |line| line.start_with?('/') ? line.sub('/', '') : line }
45
68
  cleaner.add_filter { |line| line.start_with?('.') ? line.sub('.', '') : line }
69
+ cleaner.add_silencer { |line| line.include?("nadir-rb/lib") }
70
+
71
+ stacktrace =
72
+ if @exception.is_a?(StandardError)
73
+ @exception.backtrace
74
+ else
75
+ caller
76
+ end
46
77
 
47
- cleaner.clean(@exception.backtrace)
78
+ cleaner.clean(stacktrace)
48
79
  end
49
80
  end
50
81
 
51
82
  def fingerprint
52
83
  first_backtrace_line = backtrace.find { |trace| trace !~ /pry|irb/ }
53
- checksum = [first_backtrace_line, @exception.class].join('|')
84
+ checksum = [first_backtrace_line, notification_class].join('|')
54
85
 
55
86
  Digest::SHA1.hexdigest checksum
56
87
  end
data/lib/nadir/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nadir
2
- VERSION = '1.1.10'
2
+ VERSION = '1.2.1'
3
3
  end
data/lib/nadir.rb CHANGED
@@ -22,7 +22,7 @@ module Nadir
22
22
  def notify(exception, params = {})
23
23
  return false unless config.validate
24
24
 
25
- notification = Notification.new exception, params
25
+ notification = Notification.new(exception, process_params(params))
26
26
 
27
27
  transport.deliver notification.to_params
28
28
 
@@ -33,6 +33,24 @@ module Nadir
33
33
  false
34
34
  end
35
35
 
36
+ def process_params(params)
37
+ ctx = Thread.current[:nadir_context]
38
+
39
+ if ctx
40
+ params[:job] = ctx.delete(:job) if ctx[:job]
41
+ params[:context] = ctx if ctx
42
+ end
43
+
44
+ params
45
+ end
46
+
47
+ def with_context(payload)
48
+ Thread.current[:nadir_context] = payload
49
+ yield
50
+ ensure
51
+ Thread.current[:nadir_context] = nil
52
+ end
53
+
36
54
  private
37
55
 
38
56
  def transport
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nadir
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.10
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georgi Mitrev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-11 00:00:00.000000000 Z
11
+ date: 2023-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -113,7 +113,7 @@ homepage: https://github.com/gmitrev/nadir-rb
113
113
  licenses:
114
114
  - MIT
115
115
  metadata: {}
116
- post_install_message:
116
+ post_install_message:
117
117
  rdoc_options: []
118
118
  require_paths:
119
119
  - lib
@@ -128,8 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  requirements: []
131
- rubygems_version: 3.0.3
132
- signing_key:
131
+ rubygems_version: 3.3.26
132
+ signing_key:
133
133
  specification_version: 4
134
134
  summary: Ruby library for Nadir
135
135
  test_files: []