sentry-delayed_job 4.2.1 → 4.5.0.pre.beta.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: 7eb64abb9fe7d687495e867798a9bbc079cd58cac16d7ac91a6a397292b57058
4
- data.tar.gz: 6828b40159946e22cfa840be3bd32b6693a94eb54aba9a98279481658bf754f7
3
+ metadata.gz: e71b41fbb9ead2dfb1755bed7a0f2bf1ac245d0e7348776552d10640b98ccd9e
4
+ data.tar.gz: 180c9b9da92a94126a8dadd41c2a5e11e74784f2d297200f938b23c55c7498ba
5
5
  SHA512:
6
- metadata.gz: 760b9e64122d71ce34dd61ac0d3ea486e2c30408497ed85f1892110c659cb80412c48b906b164ef79a2a67562f3472945e6496848ce0c29f6a10c6ae007959fa
7
- data.tar.gz: d486e5e384393e0089e2067e114b60919d278c7db0cbeff7cb18cc56938ee1a6a7fcba96e8a445c77b5e37c0ac65ca15861308b437f1afe03e203e220e69e82f
6
+ metadata.gz: 7f9a362698b4bed0d3fcd01eeec6144c1cba52288a0aadf219c63d3dc0696c308f15405a72a45d2d10735351f512e1caf9b176baba73db8ea21515bc26463eff
7
+ data.tar.gz: f98684f3377e74102d7f49e8fd4726b02ca56a153a3130e259c40eafdb108fad4efd0f1ddc3224456cf055b6a277db58d90862934a83c302745823b318ae1538
data/.craft.yml CHANGED
@@ -11,9 +11,9 @@ artifactProvider:
11
11
  name: github
12
12
  targets:
13
13
  - name: gem
14
- - name: github
15
- tagPrefix: sentry-delayed_job-v
16
14
  - name: registry
17
15
  type: sdk
18
16
  config:
19
17
  canonical: 'gem:sentry-delayed_job'
18
+ - name: github
19
+ tagPrefix: sentry-delayed_job-v
data/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.4.0
4
+
5
+ ### Features
6
+
7
+ - Allow delayed job's exceptions to be reported to sentry until the last job retry [#1364](https://github.com/getsentry/sentry-ruby/pull/1364)
8
+
9
+ Add the `report_after_job_retries` configuration option to only report an exception to Sentry if this is the last job's retry after multiple exceptions.
10
+
11
+ ```ruby
12
+ config.delayed_job.report_after_job_retries = true # default is false
13
+ ```
14
+
15
+ - Use context for delayed_job's job info [#1395](https://github.com/getsentry/sentry-ruby/pull/1395)
16
+
17
+ **Before:**
18
+
19
+ <img width="60%" alt="job info in extra" src="https://user-images.githubusercontent.com/5079556/114307133-de856c00-9b10-11eb-8967-cd0e67e80539.png">
20
+
21
+ **After:**
22
+
23
+ <img width="60%" alt="job info in context" src="https://user-images.githubusercontent.com/5079556/114307135-e2b18980-9b10-11eb-9fc4-af885bf0f68d.png">
24
+
25
+ ## 4.3.1
26
+
27
+ - Return delayed job when the SDK is not initialized [#1373](https://github.com/getsentry/sentry-ruby/pull/1373)
28
+ - Fixes [#1334](https://github.com/getsentry/sentry-ruby/issues/1334)
29
+
30
+ ## 4.3.0
31
+
32
+ - No integration-specific changes
33
+
3
34
  ## 4.2.1
4
35
 
5
36
  - Use ::Rails::Railtie for checking Rails definition [#1287](https://github.com/getsentry/sentry-ruby/pull/1284)
@@ -1,6 +1,7 @@
1
1
  require "delayed_job"
2
2
  require "sentry-ruby"
3
3
  require "sentry/integrable"
4
+ require "sentry/delayed_job/configuration"
4
5
  require "sentry/delayed_job/version"
5
6
  require "sentry/delayed_job/plugin"
6
7
 
@@ -0,0 +1,21 @@
1
+ module Sentry
2
+ class Configuration
3
+ attr_reader :delayed_job
4
+
5
+ add_post_initialization_callback do
6
+ @delayed_job = Sentry::DelayedJob::Configuration.new
7
+ end
8
+ end
9
+
10
+ module DelayedJob
11
+ class Configuration
12
+ # Set this option to true if you want Sentry to only capture the last job
13
+ # retry if it fails.
14
+ attr_accessor :report_after_job_retries
15
+
16
+ def initialize
17
+ @report_after_job_retries = false
18
+ end
19
+ end
20
+ end
21
+ end
@@ -4,16 +4,22 @@ require "delayed_job"
4
4
  module Sentry
5
5
  module DelayedJob
6
6
  class Plugin < ::Delayed::Plugin
7
+ # need to symbolize strings as keyword arguments in Ruby 2.4~2.6
8
+ DELAYED_JOB_CONTEXT_KEY = :"Delayed-Job"
9
+ ACTIVE_JOB_CONTEXT_KEY = :"Active-Job"
10
+
7
11
  callbacks do |lifecycle|
8
12
  lifecycle.around(:invoke_job) do |job, *args, &block|
13
+ next block.call(job, *args) unless Sentry.initialized?
14
+
9
15
  Sentry.with_scope do |scope|
10
- scope.set_extras(**generate_extra(job))
16
+ scope.set_contexts(**generate_contexts(job))
11
17
  scope.set_tags("delayed_job.queue" => job.queue, "delayed_job.id" => job.id.to_s)
12
18
 
13
19
  begin
14
20
  block.call(job, *args)
15
21
  rescue Exception => e
16
- Sentry::DelayedJob.capture_exception(e, hint: { background: false })
22
+ capture_exception(e, job)
17
23
 
18
24
  raise
19
25
  end
@@ -21,27 +27,43 @@ module Sentry
21
27
  end
22
28
  end
23
29
 
24
- def self.generate_extra(job)
25
- extra = {
26
- "delayed_job.id": job.id.to_s,
27
- "delayed_job.priority": job.priority,
28
- "delayed_job.attempts": job.attempts,
29
- "delayed_job.run_at": job.run_at,
30
- "delayed_job.locked_at": job.locked_at,
31
- "delayed_job.locked_by": job.locked_by,
32
- "delayed_job.queue": job.queue,
33
- "delayed_job.created_at": job.created_at,
34
- "delayed_job.last_error": job.last_error&.byteslice(0..1000),
35
- "delayed_job.handler": job.handler&.byteslice(0..1000)
30
+ def self.generate_contexts(job)
31
+ context = {}
32
+
33
+ context[DELAYED_JOB_CONTEXT_KEY] = {
34
+ id: job.id.to_s,
35
+ priority: job.priority,
36
+ attempts: job.attempts,
37
+ run_at: job.run_at,
38
+ locked_at: job.locked_at,
39
+ locked_by: job.locked_by,
40
+ queue: job.queue,
41
+ created_at: job.created_at,
42
+ last_error: job.last_error&.byteslice(0..1000),
43
+ handler: job.handler&.byteslice(0..1000)
36
44
  }
37
45
 
38
46
  if job.payload_object.respond_to?(:job_data)
47
+ context[ACTIVE_JOB_CONTEXT_KEY] = {}
48
+
39
49
  job.payload_object.job_data.each do |key, value|
40
- extra[:"active_job.#{key}"] = value
50
+ context[ACTIVE_JOB_CONTEXT_KEY][key.to_sym] = value
41
51
  end
42
52
  end
43
53
 
44
- extra
54
+ context
55
+ end
56
+
57
+ def self.capture_exception(exception, job)
58
+ Sentry::DelayedJob.capture_exception(exception, hint: { background: false }) if report?(job)
59
+ end
60
+
61
+ def self.report?(job)
62
+ return true unless Sentry.configuration.delayed_job.report_after_job_retries
63
+
64
+ # We use the predecessor because the job's attempts haven't been increased to the new
65
+ # count at this point.
66
+ job.attempts >= Delayed::Worker.max_attempts.pred
45
67
  end
46
68
  end
47
69
  end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module DelayedJob
3
- VERSION = "4.2.1"
3
+ VERSION = "4.5.0-beta.1"
4
4
  end
5
5
  end
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "sentry-ruby-core", "~> 4.2.0"
25
+ spec.add_dependency "sentry-ruby-core", "~> 4.5.0-beta.1"
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-delayed_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 4.5.0.pre.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-18 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sentry-ruby-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0
19
+ version: 4.5.0.pre.beta.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.0
26
+ version: 4.5.0.pre.beta.1
27
27
  description: A gem that provides DelayedJob integration for the Sentry error logger
28
28
  email: accounts@sentry.io
29
29
  executables: []
@@ -47,6 +47,7 @@ files:
47
47
  - example/Gemfile
48
48
  - example/app.rb
49
49
  - lib/sentry-delayed_job.rb
50
+ - lib/sentry/delayed_job/configuration.rb
50
51
  - lib/sentry/delayed_job/plugin.rb
51
52
  - lib/sentry/delayed_job/version.rb
52
53
  - sentry-delayed_job.gemspec
@@ -68,11 +69,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
69
  version: '2.4'
69
70
  required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  requirements:
71
- - - ">="
72
+ - - ">"
72
73
  - !ruby/object:Gem::Version
73
- version: '0'
74
+ version: 1.3.1
74
75
  requirements: []
75
- rubygems_version: 3.0.3
76
+ rubygems_version: 3.1.6
76
77
  signing_key:
77
78
  specification_version: 4
78
79
  summary: A gem that provides DelayedJob integration for the Sentry error logger