sentry-rails 4.8.1 → 4.9.1
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 +8 -2
- data/app/jobs/sentry/send_event_job.rb +2 -2
- data/lib/sentry/rails/action_cable.rb +95 -0
- data/lib/sentry/rails/active_job.rb +28 -38
- data/lib/sentry/rails/railtie.rb +13 -0
- data/lib/sentry/rails/version.rb +1 -1
- data/sentry-rails.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8f64ec5f71ef4544b1f9bf403cf7ca6b2c7a1da261bc60cbdd90ed2e6d62319
|
4
|
+
data.tar.gz: c89c1bdf903cdc922972ecbbb5d7522779ee5bcbc257850149037924ed608636
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3291ca030a819d5dd761f70cee7634a706e61895c98cd1758df8b10ad1716f387555a691811b8df5a74892227bb1d2ee30db5982cc7f4e0686cf567847a5b912
|
7
|
+
data.tar.gz: 106116f3dd129838931f2c155f9fb40ca6c75bb2eede9f11e247e36ae0a6f79f0457e0d9a89e0e0e0133cdb04a3df1e44e2473abb8ab8c227bab15500ca10103
|
data/Gemfile
CHANGED
@@ -6,17 +6,23 @@ gem "sentry-ruby", path: "../sentry-ruby"
|
|
6
6
|
|
7
7
|
rails_version = ENV["RAILS_VERSION"]
|
8
8
|
rails_version = "6.1.0" if rails_version.nil?
|
9
|
+
rails_version = Gem::Version.new(rails_version)
|
9
10
|
|
10
11
|
gem 'activerecord-jdbcmysql-adapter', platform: :jruby
|
11
12
|
gem "jdbc-sqlite3", platform: :jruby
|
12
13
|
|
13
|
-
if rails_version
|
14
|
+
if rails_version < Gem::Version.new("6.0.0")
|
14
15
|
gem "sqlite3", "~> 1.3.0", platform: :ruby
|
15
16
|
else
|
16
17
|
gem "sqlite3", platform: :ruby
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
+
if rails_version >= Gem::Version.new("7.0.0")
|
21
|
+
gem "rails", github: "rails/rails", branch: "7-0-stable"
|
22
|
+
else
|
23
|
+
gem "rails", "~> #{rails_version}"
|
24
|
+
end
|
25
|
+
|
20
26
|
gem "sprockets-rails"
|
21
27
|
|
22
28
|
gem "sidekiq"
|
@@ -16,8 +16,8 @@ if defined?(ActiveJob)
|
|
16
16
|
discard_on ActiveJob::DeserializationError
|
17
17
|
else
|
18
18
|
# mimic what discard_on does for Rails 5.0
|
19
|
-
rescue_from ActiveJob::DeserializationError do
|
20
|
-
logger.error "Discarded #{self.class} due to a #{exception}. The original exception was #{
|
19
|
+
rescue_from ActiveJob::DeserializationError do |exception|
|
20
|
+
logger.error "Discarded #{self.class} due to a #{exception}. The original exception was #{exception.cause.inspect}."
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Sentry
|
2
|
+
module Rails
|
3
|
+
module ActionCableExtensions
|
4
|
+
class ErrorHandler
|
5
|
+
class << self
|
6
|
+
def capture(connection, transaction_name:, extra_context: nil, &block)
|
7
|
+
# ActionCable's ConnectionStub (for testing) doesn't implement the exact same interfaces as Connection::Base.
|
8
|
+
# One thing that's missing is `env`. So calling `connection.env` direclty will fail in test environments when `stub_connection` is used.
|
9
|
+
# See https://github.com/getsentry/sentry-ruby/pull/1684 for more information.
|
10
|
+
env = connection.respond_to?(:env) ? connection.env : {}
|
11
|
+
|
12
|
+
Sentry.with_scope do |scope|
|
13
|
+
scope.set_rack_env(env)
|
14
|
+
scope.set_context("action_cable", extra_context) if extra_context
|
15
|
+
scope.set_transaction_name(transaction_name)
|
16
|
+
transaction = start_transaction(env, scope.transaction_name)
|
17
|
+
scope.set_span(transaction) if transaction
|
18
|
+
|
19
|
+
begin
|
20
|
+
block.call
|
21
|
+
finish_transaction(transaction, 200)
|
22
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
23
|
+
Sentry::Rails.capture_exception(e)
|
24
|
+
finish_transaction(transaction, 500)
|
25
|
+
|
26
|
+
raise
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def start_transaction(env, transaction_name)
|
32
|
+
sentry_trace = env["HTTP_SENTRY_TRACE"]
|
33
|
+
options = { name: transaction_name, op: "rails.action_cable".freeze }
|
34
|
+
transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace
|
35
|
+
Sentry.start_transaction(transaction: transaction, **options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def finish_transaction(transaction, status_code)
|
39
|
+
return unless transaction
|
40
|
+
|
41
|
+
transaction.set_http_status(status_code)
|
42
|
+
transaction.finish
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Connection
|
48
|
+
private
|
49
|
+
|
50
|
+
def handle_open
|
51
|
+
ErrorHandler.capture(self, transaction_name: "#{self.class.name}#connect") do
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def handle_close
|
57
|
+
ErrorHandler.capture(self, transaction_name: "#{self.class.name}#disconnect") do
|
58
|
+
super
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
module Channel
|
64
|
+
module Subscriptions
|
65
|
+
def self.included(base)
|
66
|
+
base.class_eval do
|
67
|
+
set_callback :subscribe, :around, ->(_, block) { sentry_capture(:subscribed, &block) }, prepend: true
|
68
|
+
set_callback :unsubscribe, :around, ->(_, block) { sentry_capture(:unsubscribed, &block) }, prepend: true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def sentry_capture(hook, &block)
|
75
|
+
extra_context = { params: params }
|
76
|
+
|
77
|
+
ErrorHandler.capture(connection, transaction_name: "#{self.class.name}##{hook}", extra_context: extra_context, &block)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
module Actions
|
82
|
+
private
|
83
|
+
|
84
|
+
def dispatch_action(action, data)
|
85
|
+
extra_context = { params: params, data: data }
|
86
|
+
|
87
|
+
ErrorHandler.capture(connection, transaction_name: "#{self.class.name}##{action}", extra_context: extra_context) do
|
88
|
+
super
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -1,28 +1,22 @@
|
|
1
1
|
module Sentry
|
2
2
|
module Rails
|
3
3
|
module ActiveJobExtensions
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
Sentry.with_scope do |scope|
|
12
|
-
capture_and_reraise_with_sentry(job, scope, block)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
else
|
16
|
-
block.call
|
4
|
+
def perform_now
|
5
|
+
if !Sentry.initialized? || already_supported_by_sentry_integration?
|
6
|
+
super
|
7
|
+
else
|
8
|
+
Sentry.with_scope do |scope|
|
9
|
+
capture_and_reraise_with_sentry(scope) do
|
10
|
+
super
|
17
11
|
end
|
18
12
|
end
|
19
13
|
end
|
20
14
|
end
|
21
15
|
|
22
|
-
def capture_and_reraise_with_sentry(
|
23
|
-
scope.set_transaction_name(
|
16
|
+
def capture_and_reraise_with_sentry(scope, &block)
|
17
|
+
scope.set_transaction_name(self.class.name)
|
24
18
|
transaction =
|
25
|
-
if
|
19
|
+
if is_a?(::Sentry::SendEventJob)
|
26
20
|
nil
|
27
21
|
else
|
28
22
|
Sentry.start_transaction(name: scope.transaction_name, op: "active_job")
|
@@ -30,50 +24,46 @@ module Sentry
|
|
30
24
|
|
31
25
|
scope.set_span(transaction) if transaction
|
32
26
|
|
33
|
-
block.call
|
27
|
+
return_value = block.call
|
34
28
|
|
35
|
-
|
29
|
+
finish_sentry_transaction(transaction, 200)
|
30
|
+
|
31
|
+
return_value
|
36
32
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
37
|
-
|
38
|
-
finish_transaction(transaction, 500)
|
39
|
-
return rescue_handler_result if rescue_handler_result
|
33
|
+
finish_sentry_transaction(transaction, 500)
|
40
34
|
|
41
35
|
Sentry::Rails.capture_exception(
|
42
36
|
e,
|
43
|
-
extra: sentry_context
|
37
|
+
extra: sentry_context,
|
44
38
|
tags: {
|
45
|
-
job_id:
|
46
|
-
provider_job_id:
|
39
|
+
job_id: job_id,
|
40
|
+
provider_job_id:provider_job_id
|
47
41
|
}
|
48
42
|
)
|
49
43
|
raise e
|
50
44
|
end
|
51
45
|
|
52
|
-
def
|
46
|
+
def finish_sentry_transaction(transaction, status)
|
53
47
|
return unless transaction
|
54
48
|
|
55
49
|
transaction.set_http_status(status)
|
56
50
|
transaction.finish
|
57
51
|
end
|
58
52
|
|
59
|
-
def
|
60
|
-
Sentry.configuration.rails.skippable_job_adapters.include?(
|
53
|
+
def already_supported_by_sentry_integration?
|
54
|
+
Sentry.configuration.rails.skippable_job_adapters.include?(self.class.queue_adapter.class.to_s)
|
61
55
|
end
|
62
56
|
|
63
|
-
def sentry_context
|
57
|
+
def sentry_context
|
64
58
|
{
|
65
|
-
active_job:
|
66
|
-
arguments:
|
67
|
-
scheduled_at:
|
68
|
-
job_id:
|
69
|
-
provider_job_id:
|
70
|
-
locale:
|
59
|
+
active_job: self.class.name,
|
60
|
+
arguments: arguments,
|
61
|
+
scheduled_at: scheduled_at,
|
62
|
+
job_id: job_id,
|
63
|
+
provider_job_id: provider_job_id,
|
64
|
+
locale: locale
|
71
65
|
}
|
72
66
|
end
|
73
67
|
end
|
74
68
|
end
|
75
69
|
end
|
76
|
-
|
77
|
-
class ActiveJob::Base
|
78
|
-
include Sentry::Rails::ActiveJobExtensions
|
79
|
-
end
|
data/lib/sentry/rails/railtie.rb
CHANGED
@@ -22,6 +22,19 @@ module Sentry
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
initializer "sentry.extend_action_cable", before: :eager_load! do |app|
|
26
|
+
ActiveSupport.on_load(:action_cable_connection) do
|
27
|
+
require "sentry/rails/action_cable"
|
28
|
+
prepend Sentry::Rails::ActionCableExtensions::Connection
|
29
|
+
end
|
30
|
+
|
31
|
+
ActiveSupport.on_load(:action_cable_channel) do
|
32
|
+
require "sentry/rails/action_cable"
|
33
|
+
include Sentry::Rails::ActionCableExtensions::Channel::Subscriptions
|
34
|
+
prepend Sentry::Rails::ActionCableExtensions::Channel::Actions
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
25
38
|
config.after_initialize do |app|
|
26
39
|
next unless Sentry.initialized?
|
27
40
|
|
data/lib/sentry/rails/version.rb
CHANGED
data/sentry-rails.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentry-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.9.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:
|
11
|
+
date: 2022-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.
|
33
|
+
version: 4.9.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 4.
|
40
|
+
version: 4.9.1
|
41
41
|
description: A gem that provides Rails integration for the Sentry error logger
|
42
42
|
email: accounts@sentry.io
|
43
43
|
executables: []
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- bin/setup
|
61
61
|
- lib/sentry-rails.rb
|
62
62
|
- lib/sentry/rails.rb
|
63
|
+
- lib/sentry/rails/action_cable.rb
|
63
64
|
- lib/sentry/rails/active_job.rb
|
64
65
|
- lib/sentry/rails/background_worker.rb
|
65
66
|
- lib/sentry/rails/backtrace_cleaner.rb
|