sentry-delayed_job 7.2.0 → 7.3.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 +4 -4
- data/Gemfile +6 -0
- data/README.md +24 -2
- data/Rakefile +18 -2
- data/gemfiles/ruby-2.7.gemfile.lock +13 -13
- data/gemfiles/ruby-3.0.gemfile.lock +12 -12
- data/gemfiles/ruby-3.1.gemfile.lock +22 -22
- data/gemfiles/ruby-3.2.gemfile.lock +142 -132
- data/gemfiles/ruby-3.3.gemfile.lock +142 -132
- data/gemfiles/ruby-3.4.gemfile.lock +142 -132
- data/gemfiles/ruby-4.0.gemfile.lock +142 -132
- data/gemfiles/ruby-jruby-9.4.14.0.gemfile.lock +26 -26
- data/lib/sentry/delayed_job/active_job_extension.rb +33 -0
- data/lib/sentry/delayed_job/active_job_support/plugin.rb +76 -0
- data/lib/sentry/delayed_job/plugin.rb +44 -23
- data/lib/sentry/delayed_job/railtie.rb +28 -0
- data/lib/sentry/delayed_job/version.rb +1 -1
- data/lib/sentry-delayed_job.rb +2 -10
- data/sentry-delayed_job.gemspec +3 -2
- metadata +16 -10
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sentry
|
|
4
|
+
module DelayedJob
|
|
5
|
+
# Support for ActiveJob jobs run through delayed_job, which reports them in
|
|
6
|
+
# one of two modes:
|
|
7
|
+
#
|
|
8
|
+
# - By default, sentry-rails skips the delayed_job adapter and
|
|
9
|
+
# sentry-delayed_job reports ActiveJob jobs like other delayed_job jobs.
|
|
10
|
+
# - When the app removes the delayed_job adapter from
|
|
11
|
+
# `config.rails.skippable_job_adapters`, sentry-rails reports them through
|
|
12
|
+
# {Sentry::DelayedJob::ActiveJobExtension}, and {ActiveJobSupport::Plugin}
|
|
13
|
+
# keeps sentry-delayed_job from reporting them a second time.
|
|
14
|
+
module ActiveJobSupport
|
|
15
|
+
ACTIVE_JOB_ADAPTER = "ActiveJob::QueueAdapters::DelayedJobAdapter"
|
|
16
|
+
ACTIVE_JOB_WRAPPER = "ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper"
|
|
17
|
+
RECORD_ID_KEY = "delayed_job_id"
|
|
18
|
+
|
|
19
|
+
# Returns the `Active-Job` context sentry-delayed_job reports for the job's
|
|
20
|
+
# serialized data.
|
|
21
|
+
#
|
|
22
|
+
# @param job_data [Hash, nil]
|
|
23
|
+
# @return [Hash]
|
|
24
|
+
def self.active_job_context(job_data)
|
|
25
|
+
context = (job_data || {}).reject { |key, _value| key == Sentry::Rails::ActiveJobExtensions::SENTRY_PAYLOAD_KEY }
|
|
26
|
+
context = context.reject { |key, _value| key == "arguments" } unless Sentry.configuration.data_collection.queues
|
|
27
|
+
context.transform_keys(&:to_sym)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Returns whether the delayed_job record wraps an ActiveJob job.
|
|
31
|
+
#
|
|
32
|
+
# @param job [Delayed::Job]
|
|
33
|
+
# @return [Boolean]
|
|
34
|
+
def self.handles?(job)
|
|
35
|
+
job.payload_object.class.name == ACTIVE_JOB_WRAPPER
|
|
36
|
+
rescue ::Delayed::DeserializationError
|
|
37
|
+
false
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Prepended to {Sentry::DelayedJob::Plugin} when sentry-rails reports
|
|
41
|
+
# ActiveJob jobs on delayed_job. For those jobs it passes the record id on to
|
|
42
|
+
# sentry-rails and only captures errors sentry-rails didn't, such as ones
|
|
43
|
+
# raised before the job runs.
|
|
44
|
+
module Plugin
|
|
45
|
+
def record(job, *args, &block)
|
|
46
|
+
return super unless Sentry.initialized? && ActiveJobSupport.handles?(job)
|
|
47
|
+
|
|
48
|
+
hand_over_record_id(job)
|
|
49
|
+
capture_unreported_exception(job) { block.call(job, *args) }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def hand_over_record_id(job)
|
|
55
|
+
job_data = job.payload_object.job_data
|
|
56
|
+
sentry_data = (job_data[Sentry::Rails::ActiveJobExtensions::SENTRY_PAYLOAD_KEY] ||= {})
|
|
57
|
+
sentry_data[RECORD_ID_KEY] = job.id.to_s
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def capture_unreported_exception(job)
|
|
61
|
+
yield
|
|
62
|
+
rescue Exception => exception # rubocop:disable Lint/RescueException
|
|
63
|
+
unless Sentry.exception_captured?(exception)
|
|
64
|
+
Sentry.with_scope do |scope|
|
|
65
|
+
contexts = generate_contexts(job)
|
|
66
|
+
contexts[DelayedJob::Plugin::ACTIVE_JOB_CONTEXT_KEY]&.delete(Sentry::Rails::ActiveJobExtensions::SENTRY_PAYLOAD_KEY.to_sym)
|
|
67
|
+
apply_job_scope(scope, job, contexts)
|
|
68
|
+
capture_exception(exception, job)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
raise
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -17,34 +17,53 @@ module Sentry
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
lifecycle.around(:invoke_job) do |job, *args, &block|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
20
|
+
record(job, *args, &block)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Runs the job in its own scope and transaction, capturing its errors.
|
|
25
|
+
#
|
|
26
|
+
# @param job [Delayed::Job]
|
|
27
|
+
# @return [Object] the block's result
|
|
28
|
+
def self.record(job, *args, &block)
|
|
29
|
+
env = extract_trace_data(job)
|
|
30
|
+
return block.call(job, *args) unless Sentry.initialized?
|
|
31
|
+
|
|
32
|
+
Sentry.with_scope do |scope|
|
|
33
|
+
contexts = apply_job_scope(scope, job)
|
|
34
|
+
|
|
35
|
+
transaction = start_transaction(scope, env, contexts)
|
|
36
|
+
scope.set_span(transaction) if transaction
|
|
37
|
+
|
|
38
|
+
begin
|
|
39
|
+
block.call(job, *args)
|
|
40
|
+
|
|
41
|
+
finish_transaction(transaction, 200)
|
|
42
|
+
rescue Exception => e
|
|
43
|
+
capture_exception(e, job)
|
|
44
|
+
finish_transaction(transaction, 500)
|
|
45
|
+
raise
|
|
42
46
|
end
|
|
43
47
|
end
|
|
44
48
|
end
|
|
45
49
|
|
|
50
|
+
# Applies the job's transaction name, contexts and tags to the scope.
|
|
51
|
+
#
|
|
52
|
+
# @param scope [Scope]
|
|
53
|
+
# @param job [Delayed::Job]
|
|
54
|
+
# @param contexts [Hash]
|
|
55
|
+
# @return [Hash] the applied contexts
|
|
56
|
+
def self.apply_job_scope(scope, job, contexts = generate_contexts(job))
|
|
57
|
+
name = contexts.dig(ACTIVE_JOB_CONTEXT_KEY, :job_class) || contexts.dig(DELAYED_JOB_CONTEXT_KEY, :job_class)
|
|
58
|
+
scope.set_transaction_name(name, source: :task)
|
|
59
|
+
scope.set_contexts(**contexts)
|
|
60
|
+
scope.set_tags("delayed_job.queue" => job.queue, "delayed_job.id" => job.id.to_s)
|
|
61
|
+
contexts
|
|
62
|
+
end
|
|
63
|
+
|
|
46
64
|
def self.generate_contexts(job)
|
|
47
65
|
context = {}
|
|
66
|
+
collect_arguments = Sentry.configuration.data_collection.queues
|
|
48
67
|
|
|
49
68
|
context[DELAYED_JOB_CONTEXT_KEY] = {
|
|
50
69
|
id: job.id.to_s,
|
|
@@ -56,14 +75,16 @@ module Sentry
|
|
|
56
75
|
queue: job.queue,
|
|
57
76
|
created_at: job.created_at,
|
|
58
77
|
last_error: job.last_error&.byteslice(0..1000),
|
|
59
|
-
handler: job.handler&.byteslice(0..1000),
|
|
60
78
|
job_class: compute_job_class(job.payload_object)
|
|
61
79
|
}
|
|
80
|
+
context[DELAYED_JOB_CONTEXT_KEY][:handler] = job.handler&.byteslice(0..1000) if collect_arguments
|
|
62
81
|
|
|
63
82
|
if job.payload_object.respond_to?(:job_data)
|
|
64
83
|
context[ACTIVE_JOB_CONTEXT_KEY] = {}
|
|
65
84
|
|
|
66
85
|
job.payload_object.job_data.each do |key, value|
|
|
86
|
+
next if key.to_s == "arguments" && !collect_arguments
|
|
87
|
+
|
|
67
88
|
context[ACTIVE_JOB_CONTEXT_KEY][key.to_sym] = value
|
|
68
89
|
end
|
|
69
90
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "sentry/delayed_job/active_job_support/plugin"
|
|
4
|
+
|
|
5
|
+
module Sentry
|
|
6
|
+
module DelayedJob
|
|
7
|
+
# Sets up how ActiveJob jobs on delayed_job are reported in Rails apps.
|
|
8
|
+
#
|
|
9
|
+
# @see ActiveJobSupport
|
|
10
|
+
class Railtie < ::Rails::Railtie
|
|
11
|
+
initializer "sentry.delayed_job.skippable_job_adapter", before: :load_environment_config do
|
|
12
|
+
next unless defined?(::Sentry::Rails)
|
|
13
|
+
|
|
14
|
+
Sentry::Configuration.after(:initialize) { rails.skippable_job_adapters << ActiveJobSupport::ACTIVE_JOB_ADAPTER }
|
|
15
|
+
# The callback only covers configurations created from here on, so an app that
|
|
16
|
+
# initialized Sentry earlier gets the adapter added to its current configuration.
|
|
17
|
+
Sentry.configuration.rails.skippable_job_adapters << ActiveJobSupport::ACTIVE_JOB_ADAPTER if Sentry.initialized?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
config.after_initialize do
|
|
21
|
+
next unless defined?(::Sentry::Rails) && Sentry::Rails.active_job_owns_adapter?(ActiveJobSupport::ACTIVE_JOB_ADAPTER)
|
|
22
|
+
|
|
23
|
+
require "sentry/delayed_job/active_job_extension"
|
|
24
|
+
Plugin.singleton_class.prepend(ActiveJobSupport::Plugin)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
data/lib/sentry-delayed_job.rb
CHANGED
|
@@ -12,15 +12,7 @@ module Sentry
|
|
|
12
12
|
extend Sentry::Integrable
|
|
13
13
|
|
|
14
14
|
register_integration name: "delayed_job", version: Sentry::DelayedJob::VERSION
|
|
15
|
-
|
|
16
|
-
if defined?(::Rails::Railtie)
|
|
17
|
-
class Railtie < ::Rails::Railtie
|
|
18
|
-
config.after_initialize do
|
|
19
|
-
next unless Sentry.initialized? && defined?(::Sentry::Rails)
|
|
20
|
-
|
|
21
|
-
Sentry.configuration.rails.skippable_job_adapters << "ActiveJob::QueueAdapters::DelayedJobAdapter"
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
15
|
end
|
|
26
16
|
end
|
|
17
|
+
|
|
18
|
+
require "sentry/delayed_job/railtie" if defined?(::Rails::Railtie)
|
data/sentry-delayed_job.gemspec
CHANGED
|
@@ -6,7 +6,8 @@ Gem::Specification.new do |spec|
|
|
|
6
6
|
spec.name = "sentry-delayed_job"
|
|
7
7
|
spec.version = Sentry::DelayedJob::VERSION
|
|
8
8
|
spec.authors = ["Sentry Team"]
|
|
9
|
-
spec.
|
|
9
|
+
spec.summary = "A gem that provides DelayedJob integration for the Sentry error logger (maintenance mode)"
|
|
10
|
+
spec.description = "Maintenance-mode DelayedJob integration for the Sentry error logger. ActiveJob users should use the ActiveJob integration in sentry-rails, which sentry-delayed_job enriches with delayed_job data."
|
|
10
11
|
spec.email = "accounts@sentry.io"
|
|
11
12
|
spec.license = 'MIT'
|
|
12
13
|
|
|
@@ -30,6 +31,6 @@ Gem::Specification.new do |spec|
|
|
|
30
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
31
32
|
spec.require_paths = ["lib"]
|
|
32
33
|
|
|
33
|
-
spec.add_dependency "sentry-ruby", "~> 7.
|
|
34
|
+
spec.add_dependency "sentry-ruby", "~> 7.3.0"
|
|
34
35
|
spec.add_dependency "delayed_job", ">= 4.0"
|
|
35
36
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sentry-delayed_job
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.
|
|
4
|
+
version: 7.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sentry Team
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 7.
|
|
18
|
+
version: 7.3.0
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 7.
|
|
25
|
+
version: 7.3.0
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: delayed_job
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -37,7 +37,9 @@ dependencies:
|
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
39
|
version: '4.0'
|
|
40
|
-
description:
|
|
40
|
+
description: Maintenance-mode DelayedJob integration for the Sentry error logger.
|
|
41
|
+
ActiveJob users should use the ActiveJob integration in sentry-rails, which sentry-delayed_job
|
|
42
|
+
enriches with delayed_job data.
|
|
41
43
|
email: accounts@sentry.io
|
|
42
44
|
executables: []
|
|
43
45
|
extensions: []
|
|
@@ -65,19 +67,22 @@ files:
|
|
|
65
67
|
- gemfiles/ruby-4.0.gemfile.lock
|
|
66
68
|
- gemfiles/ruby-jruby-9.4.14.0.gemfile.lock
|
|
67
69
|
- lib/sentry-delayed_job.rb
|
|
70
|
+
- lib/sentry/delayed_job/active_job_extension.rb
|
|
71
|
+
- lib/sentry/delayed_job/active_job_support/plugin.rb
|
|
68
72
|
- lib/sentry/delayed_job/configuration.rb
|
|
69
73
|
- lib/sentry/delayed_job/plugin.rb
|
|
74
|
+
- lib/sentry/delayed_job/railtie.rb
|
|
70
75
|
- lib/sentry/delayed_job/version.rb
|
|
71
76
|
- sentry-delayed_job.gemspec
|
|
72
|
-
homepage: https://github.com/getsentry/sentry-ruby/tree/7.
|
|
77
|
+
homepage: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-delayed_job
|
|
73
78
|
licenses:
|
|
74
79
|
- MIT
|
|
75
80
|
metadata:
|
|
76
|
-
homepage_uri: https://github.com/getsentry/sentry-ruby/tree/7.
|
|
77
|
-
source_code_uri: https://github.com/getsentry/sentry-ruby/tree/7.
|
|
78
|
-
changelog_uri: https://github.com/getsentry/sentry-ruby/blob/7.
|
|
81
|
+
homepage_uri: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-delayed_job
|
|
82
|
+
source_code_uri: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-delayed_job
|
|
83
|
+
changelog_uri: https://github.com/getsentry/sentry-ruby/blob/7.3.0/CHANGELOG.md
|
|
79
84
|
bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
|
|
80
|
-
documentation_uri: http://www.rubydoc.info/gems/sentry-delayed_job/7.
|
|
85
|
+
documentation_uri: http://www.rubydoc.info/gems/sentry-delayed_job/7.3.0
|
|
81
86
|
rdoc_options: []
|
|
82
87
|
require_paths:
|
|
83
88
|
- lib
|
|
@@ -94,5 +99,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
94
99
|
requirements: []
|
|
95
100
|
rubygems_version: 3.6.9
|
|
96
101
|
specification_version: 4
|
|
97
|
-
summary: A gem that provides DelayedJob integration for the Sentry error logger
|
|
102
|
+
summary: A gem that provides DelayedJob integration for the Sentry error logger (maintenance
|
|
103
|
+
mode)
|
|
98
104
|
test_files: []
|