sentry-resque 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.
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sentry/rails/active_job_extension"
4
+ require "sentry/resque/active_job_support/reporter"
5
+
6
+ module Sentry
7
+ module Resque
8
+ # The extension sentry-rails uses for ActiveJob jobs on Resque when the app
9
+ # lets sentry-rails report them. It keeps sentry-resque's context, tags,
10
+ # origin and integration, so these jobs look the same in Sentry in either mode.
11
+ #
12
+ # @see ActiveJobSupport
13
+ class ActiveJobExtension < Sentry::Rails::ActiveJobExtension
14
+ SPAN_ORIGIN = "auto.queue.resque"
15
+ MESSAGING_SYSTEM = "resque"
16
+
17
+ def initialize(name: :resque, integration: Sentry::Resque, origin: SPAN_ORIGIN, **dependencies)
18
+ super(name: name, integration: integration, origin: origin, **dependencies)
19
+ end
20
+
21
+ # Adds sentry-resque's `Active-Job` context and `resque.queue` tag.
22
+ #
23
+ # @see Sentry::JobExtensions::Extension#scope_data
24
+ def scope_data(job:, **)
25
+ job_data = job._sentry_job_data || {}
26
+ context = {
27
+ job_class: job.class.name,
28
+ job_id: job.job_id,
29
+ executions: job_data["executions"],
30
+ exception_executions: job_data["exception_executions"],
31
+ locale: job_data["locale"],
32
+ enqueued_at: job_data["enqueued_at"],
33
+ queue: job.queue_name
34
+ }
35
+ context[:arguments] = job_data["arguments"] if Sentry.configuration.data_collection.queues
36
+
37
+ { contexts: { "Active-Job": context }, tags: { "resque.queue" => job.queue_name } }
38
+ end
39
+
40
+ # Describes the Resque message being processed.
41
+ #
42
+ # @see Sentry::JobExtensions::Extension#messaging_data
43
+ def messaging_data(job:, **)
44
+ job_data = job._sentry_job_data
45
+ data = {
46
+ system: MESSAGING_SYSTEM,
47
+ message_id: job.job_id,
48
+ destination: job.queue_name,
49
+ retry_count: (job.executions.to_i if job.respond_to?(:executions)),
50
+ receive_latency: Sentry::Utils::Latency.milliseconds_since(job_data&.[]("enqueued_at"))
51
+ }
52
+ data[:body_size] = body_size(job_data) if Sentry.get_current_scope.get_span&.sampled
53
+ data.compact
54
+ end
55
+
56
+ private
57
+
58
+ def body_size(job_data)
59
+ ::Resque.encode("class" => ActiveJobSupport::ACTIVE_JOB_WRAPPER, "args" => [job_data]).bytesize if job_data
60
+ rescue StandardError
61
+ nil
62
+ end
63
+ end
64
+
65
+ Sentry::Rails.register_active_job_extension(:resque, ActiveJobExtension.new)
66
+ end
67
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ module Resque
5
+ # Support for ActiveJob jobs run through Resque, which reports them in one of
6
+ # two modes:
7
+ #
8
+ # - By default, sentry-rails skips the Resque adapter and sentry-resque
9
+ # reports ActiveJob jobs like other Resque jobs.
10
+ # - When the app removes the Resque adapter from
11
+ # `config.rails.skippable_job_adapters`, sentry-rails reports them through
12
+ # {Sentry::Resque::ActiveJobExtension}, and {ActiveJobSupport::Reporter}
13
+ # keeps sentry-resque from reporting them a second time.
14
+ module ActiveJobSupport
15
+ ACTIVE_JOB_ADAPTER = "ActiveJob::QueueAdapters::ResqueAdapter"
16
+ ACTIVE_JOB_WRAPPER = "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper"
17
+
18
+ # Returns whether the Resque payload wraps an ActiveJob job.
19
+ #
20
+ # @param payload [Hash]
21
+ # @return [Boolean]
22
+ def self.handles?(payload)
23
+ payload.is_a?(Hash) && payload["class"].to_s == ACTIVE_JOB_WRAPPER
24
+ end
25
+
26
+ # Prepended to {SentryReporter} when sentry-rails reports ActiveJob jobs on
27
+ # Resque. For those jobs it only captures errors sentry-rails didn't, such as
28
+ # ones raised before the job runs.
29
+ module Reporter
30
+ def record(queue, worker, payload, &block)
31
+ return super unless ActiveJobSupport.handles?(payload)
32
+
33
+ capture_unreported_exception(queue, worker, payload, &block)
34
+ end
35
+
36
+ private
37
+
38
+ def capture_unreported_exception(queue, worker, payload)
39
+ yield
40
+ rescue Exception => exception # rubocop:disable Lint/RescueException
41
+ unless Sentry.exception_captured?(exception)
42
+ Sentry.with_scope do |scope|
43
+ apply_job_scope(scope, queue, worker, payload)
44
+ ::Sentry::Resque.capture_exception(exception, hint: { background: false })
45
+ end
46
+ end
47
+ raise
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sentry/resque/active_job_support/reporter"
4
+
5
+ module Sentry
6
+ module Resque
7
+ # Sets up how ActiveJob jobs on Resque are reported in Rails apps.
8
+ #
9
+ # @see ActiveJobSupport
10
+ class Railtie < ::Rails::Railtie
11
+ initializer "sentry.resque.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/resque/active_job_extension"
24
+ SentryReporter.singleton_class.prepend(ActiveJobSupport::Reporter)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sentry
4
4
  module Resque
5
- VERSION = "7.2.0"
5
+ VERSION = "7.3.0"
6
6
  end
7
7
  end
data/lib/sentry/resque.rb CHANGED
@@ -21,12 +21,7 @@ module Sentry
21
21
  def record(queue, worker, payload, &block)
22
22
  Sentry.with_scope do |scope|
23
23
  begin
24
- contexts = generate_contexts(queue, worker, payload)
25
- scope.set_contexts(**contexts)
26
- scope.set_tags("resque.queue" => queue)
27
-
28
- name = contexts.dig(:"Active-Job", :job_class) || contexts.dig(:"Resque", :job_class)
29
- scope.set_transaction_name(name, source: :task)
24
+ apply_job_scope(scope, queue, worker, payload)
30
25
  transaction = Sentry.start_transaction(
31
26
  name: scope.transaction_name,
32
27
  source: scope.transaction_source,
@@ -75,7 +70,9 @@ module Sentry
75
70
  }
76
71
  end
77
72
 
78
- context
73
+ return context if Sentry.configuration.data_collection.queues
74
+
75
+ context.transform_values { |job_context| job_context.reject { |key, _| key == :arguments } }
79
76
  end
80
77
 
81
78
  def finish_transaction(transaction, status)
@@ -87,6 +84,15 @@ module Sentry
87
84
 
88
85
  private
89
86
 
87
+ def apply_job_scope(scope, queue, worker, payload)
88
+ contexts = generate_contexts(queue, worker, payload)
89
+ scope.set_contexts(**contexts)
90
+ scope.set_tags("resque.queue" => queue)
91
+
92
+ name = contexts.dig(:"Active-Job", :job_class) || contexts.dig(:"Resque", :job_class)
93
+ scope.set_transaction_name(name, source: :task)
94
+ end
95
+
90
96
  def raise_if_retries_remain(klass, exception)
91
97
  return unless Sentry.configuration.resque.report_after_job_retries &&
92
98
  defined?(::Resque::Plugins::Retry) == "constant"
data/lib/sentry-resque.rb CHANGED
@@ -12,15 +12,7 @@ module Sentry
12
12
  extend Sentry::Integrable
13
13
 
14
14
  register_integration name: "resque", version: Sentry::Resque::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::ResqueAdapter"
22
- end
23
- end
24
- end
25
15
  end
26
16
  end
17
+
18
+ require "sentry/resque/railtie" if defined?(::Rails::Railtie)
@@ -6,7 +6,8 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "sentry-resque"
7
7
  spec.version = Sentry::Resque::VERSION
8
8
  spec.authors = ["Sentry Team"]
9
- spec.description = spec.summary = "A gem that provides Resque integration for the Sentry error logger"
9
+ spec.summary = "A gem that provides Resque integration for the Sentry error logger (maintenance mode)"
10
+ spec.description = "Maintenance-mode Resque integration for the Sentry error logger. ActiveJob users should use the ActiveJob integration in sentry-rails, which sentry-resque enriches with Resque 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.2.0"
34
+ spec.add_dependency "sentry-ruby", "~> 7.3.0"
34
35
  spec.add_dependency "resque", ">= 1.24"
35
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-resque
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.0
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.2.0
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.2.0
25
+ version: 7.3.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: resque
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -37,7 +37,9 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '1.24'
40
- description: A gem that provides Resque integration for the Sentry error logger
40
+ description: Maintenance-mode Resque integration for the Sentry error logger. ActiveJob
41
+ users should use the ActiveJob integration in sentry-rails, which sentry-resque
42
+ enriches with Resque data.
41
43
  email: accounts@sentry.io
42
44
  executables: []
43
45
  extensions: []
@@ -65,18 +67,21 @@ files:
65
67
  - gemfiles/ruby-jruby-9.4.14.0.gemfile.lock
66
68
  - lib/sentry-resque.rb
67
69
  - lib/sentry/resque.rb
70
+ - lib/sentry/resque/active_job_extension.rb
71
+ - lib/sentry/resque/active_job_support/reporter.rb
68
72
  - lib/sentry/resque/configuration.rb
73
+ - lib/sentry/resque/railtie.rb
69
74
  - lib/sentry/resque/version.rb
70
75
  - sentry-resque.gemspec
71
- homepage: https://github.com/getsentry/sentry-ruby/tree/7.2.0/sentry-resque
76
+ homepage: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-resque
72
77
  licenses:
73
78
  - MIT
74
79
  metadata:
75
- homepage_uri: https://github.com/getsentry/sentry-ruby/tree/7.2.0/sentry-resque
76
- source_code_uri: https://github.com/getsentry/sentry-ruby/tree/7.2.0/sentry-resque
77
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/7.2.0/CHANGELOG.md
80
+ homepage_uri: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-resque
81
+ source_code_uri: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-resque
82
+ changelog_uri: https://github.com/getsentry/sentry-ruby/blob/7.3.0/CHANGELOG.md
78
83
  bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
79
- documentation_uri: http://www.rubydoc.info/gems/sentry-resque/7.2.0
84
+ documentation_uri: http://www.rubydoc.info/gems/sentry-resque/7.3.0
80
85
  rdoc_options: []
81
86
  require_paths:
82
87
  - lib
@@ -93,5 +98,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
98
  requirements: []
94
99
  rubygems_version: 3.6.9
95
100
  specification_version: 4
96
- summary: A gem that provides Resque integration for the Sentry error logger
101
+ summary: A gem that provides Resque integration for the Sentry error logger (maintenance
102
+ mode)
97
103
  test_files: []