bugsnag 6.21.0 → 6.22.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: d25c44a654cbfc8684f28ea8ae1853f3aa482abc2741574662afb8368ab8c5b2
4
- data.tar.gz: a5c2462967da4d5995a7e07715a310bf5290019943395feef4a782290f2e34c2
3
+ metadata.gz: 5a06ee3b5502be46d703f258c7bda2a5fca647fbe210095e989dd069af901a78
4
+ data.tar.gz: 622e923de05d81c2d15fe65d738e7191e75b84230c0bbdcb8fed7c9f6831057c
5
5
  SHA512:
6
- metadata.gz: 97c2d1764646f0e7fa90fd7c6d9fd4f3811acde1da0cd110a5f186cd164d52fb61fe2a13add1d75f3fd492ccc4c034e63167a4f1c7f06e8586363b95a58788db
7
- data.tar.gz: 64c6671f0cddbcdcc71e34ceb4719132f9e503a9e5be9ec73692348b3d023c3b68f572bba05489220dda5eea9f4a4fb89a3559f16d416eb19e6150bf86482640
6
+ metadata.gz: 7ea25266b534f698108e3bc1cbbfeb81d6b528b77653ffe8edce45b7d6d0309faba4a43f0aeb946ace35b84b738cdd275e12cdc998abc7c2b20c02fa2ea07ed4
7
+ data.tar.gz: 96a1fe53d1f2167cc3458e53ec178e6c8c25fbde85d1dca17a329da85f9ebde4e72416b5930f9ed595955c48e043e22d60915483e163d0f274a4292a06fa70d8
data/CHANGELOG.md CHANGED
@@ -1,6 +1,23 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## v6.22.1 (11 August 2021)
5
+
6
+ ### Fixes
7
+
8
+ * Fix possible `LocalJumpError` introduced in v6.22.0
9
+ | [#675](https://github.com/bugsnag/bugsnag-ruby/pull/675)
10
+
11
+ ## v6.22.0 (10 August 2021)
12
+
13
+ ### Enhancements
14
+
15
+ * Add support for tracking exceptions and capturing metadata in Active Job, when not using an existing integration
16
+ | [#670](https://github.com/bugsnag/bugsnag-ruby/pull/670)
17
+
18
+ * Improve the report context when using Delayed Job or Resque as the Active Job queue adapter
19
+ | [#671](https://github.com/bugsnag/bugsnag-ruby/pull/671)
20
+
4
21
  ## v6.21.0 (23 June 2021)
5
22
 
6
23
  ### Enhancements
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.21.0
1
+ 6.22.1
@@ -25,9 +25,9 @@ module Bugsnag
25
25
  end
26
26
 
27
27
  # Hook up rack-based notification middlewares
28
- config.middleware.insert_before([Bugsnag::Middleware::Rails3Request,Bugsnag::Middleware::Callbacks], Bugsnag::Middleware::RackRequest) if defined?(::Rack)
29
- config.middleware.insert_before(Bugsnag::Middleware::Callbacks, Bugsnag::Middleware::WardenUser) if defined?(Warden)
30
- config.middleware.insert_before(Bugsnag::Middleware::Callbacks, Bugsnag::Middleware::ClearanceUser) if defined?(Clearance)
28
+ config.internal_middleware.insert_before(Bugsnag::Middleware::Rails3Request, Bugsnag::Middleware::RackRequest) if defined?(::Rack)
29
+ config.internal_middleware.use(Bugsnag::Middleware::WardenUser) if defined?(Warden)
30
+ config.internal_middleware.use(Bugsnag::Middleware::ClearanceUser) if defined?(Clearance)
31
31
 
32
32
  # Set environment data for payload
33
33
  # Note we only set the detected app_type if it's not already set. This
@@ -0,0 +1,102 @@
1
+ require 'set'
2
+
3
+ module Bugsnag::Rails
4
+ module ActiveJob
5
+ SEVERITY = 'error'
6
+ SEVERITY_REASON = {
7
+ type: Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
8
+ attributes: { framework: 'Active Job' }
9
+ }
10
+
11
+ EXISTING_INTEGRATIONS = Set[
12
+ 'ActiveJob::QueueAdapters::DelayedJobAdapter',
13
+ 'ActiveJob::QueueAdapters::QueAdapter',
14
+ 'ActiveJob::QueueAdapters::ResqueAdapter',
15
+ 'ActiveJob::QueueAdapters::ShoryukenAdapter',
16
+ 'ActiveJob::QueueAdapters::SidekiqAdapter'
17
+ ]
18
+
19
+ INLINE_ADAPTER = 'ActiveJob::QueueAdapters::InlineAdapter'
20
+
21
+ # these methods were added after the first Active Job release so
22
+ # may not be present, depending on the Rails version
23
+ MAYBE_MISSING_METHODS = [
24
+ :provider_job_id,
25
+ :priority,
26
+ :executions,
27
+ :enqueued_at,
28
+ :timezone
29
+ ]
30
+
31
+ def self.included(base)
32
+ base.class_eval do
33
+ around_perform do |job, block|
34
+ adapter = _bugsnag_get_adapter_name(job)
35
+
36
+ # if we have an integration for this queue adapter already then we should
37
+ # leave this job alone or we'll end up with duplicate metadata
38
+ next block.call if EXISTING_INTEGRATIONS.include?(adapter)
39
+
40
+ Bugsnag.configuration.detected_app_type = 'active job'
41
+
42
+ begin
43
+ Bugsnag.configuration.set_request_data(:active_job, _bugsnag_extract_metadata(job))
44
+
45
+ block.call
46
+ rescue Exception => e
47
+ Bugsnag.notify(e, true) do |report|
48
+ report.severity = SEVERITY
49
+ report.severity_reason = SEVERITY_REASON
50
+ end
51
+
52
+ # when using the "inline" adapter the job is run immediately, which
53
+ # will result in our Rack integration catching the re-raised error
54
+ # and reporting it a second time if it's run in a web request
55
+ if adapter == INLINE_ADAPTER
56
+ e.instance_eval do
57
+ def skip_bugsnag
58
+ true
59
+ end
60
+ end
61
+ end
62
+
63
+ raise
64
+ ensure
65
+ Bugsnag.configuration.clear_request_data
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ private
72
+
73
+ def _bugsnag_get_adapter_name(job)
74
+ adapter = job.class.queue_adapter
75
+
76
+ # in Rails 4 queue adapters were references to a class. In Rails 5+
77
+ # they are an instance of that class instead
78
+ return adapter.name if adapter.is_a?(Class)
79
+
80
+ adapter.class.name
81
+ end
82
+
83
+ def _bugsnag_extract_metadata(job)
84
+ metadata = {
85
+ job_id: job.job_id,
86
+ job_name: job.class.name,
87
+ queue: job.queue_name,
88
+ arguments: job.arguments,
89
+ locale: job.locale
90
+ }
91
+
92
+ MAYBE_MISSING_METHODS.each do |method_name|
93
+ next unless job.respond_to?(method_name)
94
+
95
+ metadata[method_name] = job.send(method_name)
96
+ end
97
+
98
+ metadata.compact!
99
+ metadata
100
+ end
101
+ end
102
+ end
@@ -60,7 +60,7 @@ module Bugsnag
60
60
  config.logger = ::Rails.logger
61
61
  config.release_stage ||= ::Rails.env.to_s
62
62
  config.project_root = ::Rails.root.to_s
63
- config.middleware.insert_before Bugsnag::Middleware::Callbacks, Bugsnag::Middleware::Rails3Request
63
+ config.internal_middleware.use(Bugsnag::Middleware::Rails3Request)
64
64
  config.runtime_versions["rails"] = ::Rails::VERSION::STRING
65
65
  end
66
66
 
@@ -74,6 +74,14 @@ module Bugsnag
74
74
  include Bugsnag::Rails::ActiveRecordRescue
75
75
  end
76
76
 
77
+ ActiveSupport.on_load(:active_job) do
78
+ require "bugsnag/middleware/active_job"
79
+ Bugsnag.configuration.internal_middleware.use(Bugsnag::Middleware::ActiveJob)
80
+
81
+ require "bugsnag/integrations/rails/active_job"
82
+ include Bugsnag::Rails::ActiveJob
83
+ end
84
+
77
85
  Bugsnag::Rails::DEFAULT_RAILS_BREADCRUMBS.each { |event| event_subscription(event) }
78
86
 
79
87
  # Make sure we don't overwrite the value set by another integration because
@@ -44,8 +44,18 @@ module Bugsnag
44
44
  :attributes => FRAMEWORK_ATTRIBUTES
45
45
  }
46
46
 
47
- context = "#{payload['class']}@#{queue}"
48
- report.meta_data.merge!({:context => context, :payload => payload})
47
+ metadata = payload
48
+ class_name = payload['class']
49
+
50
+ # when using Active Job the payload "class" will always be the Resque
51
+ # "JobWrapper", not the actual job class so we need to fix this here
52
+ if metadata['args'] && metadata['args'][0] && metadata['args'][0]['job_class']
53
+ class_name = metadata['args'][0]['job_class']
54
+ metadata['wrapped'] ||= class_name
55
+ end
56
+
57
+ context = "#{class_name}@#{queue}"
58
+ report.meta_data.merge!({ context: context, payload: metadata })
49
59
  report.context = context
50
60
  end
51
61
  end
@@ -0,0 +1,18 @@
1
+ module Bugsnag::Middleware
2
+ class ActiveJob
3
+ def initialize(bugsnag)
4
+ @bugsnag = bugsnag
5
+ end
6
+
7
+ def call(report)
8
+ data = report.request_data[:active_job]
9
+
10
+ if data
11
+ report.add_tab(:active_job, data)
12
+ report.context = "#{data[:job_name]}@#{data[:queue]}"
13
+ end
14
+
15
+ @bugsnag.call(report)
16
+ end
17
+ end
18
+ end
@@ -2,6 +2,11 @@ module Bugsnag::Middleware
2
2
  ##
3
3
  # Attaches delayed_job information to an error report
4
4
  class DelayedJob
5
+ # Active Job's queue adapter sets the "display_name" to this format. This
6
+ # breaks the event context as the ID and arguments are included, which will
7
+ # differ between executions of the same job
8
+ ACTIVE_JOB_DISPLAY_NAME = /^.* \[[0-9a-f-]+\] from DelayedJob\(.*\) with arguments: \[.*\]$/
9
+
5
10
  def initialize(bugsnag)
6
11
  @bugsnag = bugsnag
7
12
  end
@@ -23,8 +28,10 @@ module Bugsnag::Middleware
23
28
  if job.respond_to?(:payload_object)
24
29
  job_data[:active_job] = job.payload_object.job_data if job.payload_object.respond_to?(:job_data)
25
30
  payload_data = construct_job_payload(job.payload_object)
26
- report.context = payload_data[:display_name] if payload_data.include?(:display_name)
27
- report.context ||= payload_data[:class] if payload_data.include?(:class)
31
+
32
+ context = get_context(payload_data, job_data[:active_job])
33
+ report.context = context unless context.nil?
34
+
28
35
  job_data[:payload] = payload_data
29
36
  end
30
37
 
@@ -70,5 +77,17 @@ module Bugsnag::Middleware
70
77
  end
71
78
  data
72
79
  end
80
+
81
+ private
82
+
83
+ def get_context(payload_data, active_job_data)
84
+ if payload_data.include?(:display_name) && !ACTIVE_JOB_DISPLAY_NAME.match?(payload_data[:display_name])
85
+ payload_data[:display_name]
86
+ elsif active_job_data && active_job_data['job_class'] && active_job_data['queue_name']
87
+ "#{active_job_data['job_class']}@#{active_job_data['queue_name']}"
88
+ elsif payload_data.include?(:class)
89
+ payload_data[:class]
90
+ end
91
+ end
73
92
  end
74
93
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bugsnag
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.21.0
4
+ version: 6.22.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-23 00:00:00.000000000 Z
11
+ date: 2021-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -55,6 +55,7 @@ files:
55
55
  - lib/bugsnag/integrations/mongo.rb
56
56
  - lib/bugsnag/integrations/que.rb
57
57
  - lib/bugsnag/integrations/rack.rb
58
+ - lib/bugsnag/integrations/rails/active_job.rb
58
59
  - lib/bugsnag/integrations/rails/active_record_rescue.rb
59
60
  - lib/bugsnag/integrations/rails/controller_methods.rb
60
61
  - lib/bugsnag/integrations/rails/rails_breadcrumbs.rb
@@ -64,6 +65,7 @@ files:
64
65
  - lib/bugsnag/integrations/shoryuken.rb
65
66
  - lib/bugsnag/integrations/sidekiq.rb
66
67
  - lib/bugsnag/meta_data.rb
68
+ - lib/bugsnag/middleware/active_job.rb
67
69
  - lib/bugsnag/middleware/breadcrumbs.rb
68
70
  - lib/bugsnag/middleware/callbacks.rb
69
71
  - lib/bugsnag/middleware/classify_error.rb