sentry-rails 5.0.1 → 5.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9487ee74f0da8ec37873850f9b0d9651e4c61dc774e5928c419c553194c363c9
4
- data.tar.gz: 28bc3a23ea3e77013f7debf042aabb24e46944d504fcb016dd7427b40a8255dd
3
+ metadata.gz: 59ad5d09cc5a579e3790610a661a3ea67fea7a71c11859ad8731d67ccb57f4c9
4
+ data.tar.gz: 982e987f3905ee2b4dec3d254ddfa055cd635857307d2a4a798bf01451b7a757
5
5
  SHA512:
6
- metadata.gz: 6012e9e4272e82c60e7f38384c6ee44543661cbdcc3598182cf8b186e6a20fc8391fbb16d0b7688aeb4cc3e80398686416f9eb783364af971bba24acf01be45c
7
- data.tar.gz: 0040a4200a194e1fc3769ddf3c29bfc9988b411b1f42a6ddb6a73252720d583c473203348d933e307453f9d782bd2b76b8e13d65959665cc6684967c907c8c6d
6
+ metadata.gz: 4afbf7ca6532f422ce2f772865287363fcefe1133589151610bfc158dfc4377d86789aff2b6fc78d8889a112ca36ad13de69e7fb60ac401a964fd8dde072c186
7
+ data.tar.gz: 792a75fce8fdf69c1cfe62ffd7250952666811d14591758ba6a8897e70691477b5b9dab1990cdea8a5641c93933bacaea0faab7fce833817de9286e82a145391
data/.gitignore CHANGED
@@ -5,7 +5,7 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
- /spec/support/test_rails_app/db
8
+ /spec/dummy/test_rails_app/db
9
9
  /tmp/
10
10
 
11
11
  # rspec failure tracking
@@ -5,64 +5,81 @@ module Sentry
5
5
  if !Sentry.initialized? || already_supported_by_sentry_integration?
6
6
  super
7
7
  else
8
- Sentry.with_scope do |scope|
9
- capture_and_reraise_with_sentry(scope) do
10
- super
11
- end
8
+ SentryReporter.record(self) do
9
+ super
12
10
  end
13
11
  end
14
12
  end
15
13
 
16
- def capture_and_reraise_with_sentry(scope, &block)
17
- scope.set_transaction_name(self.class.name)
18
- transaction =
19
- if is_a?(::Sentry::SendEventJob)
20
- nil
21
- else
22
- Sentry.start_transaction(name: scope.transaction_name, op: "active_job")
23
- end
24
-
25
- scope.set_span(transaction) if transaction
14
+ def already_supported_by_sentry_integration?
15
+ Sentry.configuration.rails.skippable_job_adapters.include?(self.class.queue_adapter.class.to_s)
16
+ end
26
17
 
27
- return_value = block.call
18
+ class SentryReporter
19
+ class << self
20
+ def record(job, &block)
21
+ Sentry.with_scope do |scope|
22
+ begin
23
+ scope.set_transaction_name(job.class.name)
24
+ transaction =
25
+ if job.is_a?(::Sentry::SendEventJob)
26
+ nil
27
+ else
28
+ Sentry.start_transaction(name: scope.transaction_name, op: "active_job")
29
+ end
28
30
 
29
- finish_sentry_transaction(transaction, 200)
31
+ scope.set_span(transaction) if transaction
30
32
 
31
- return_value
32
- rescue Exception => e # rubocop:disable Lint/RescueException
33
- finish_sentry_transaction(transaction, 500)
33
+ yield.tap do
34
+ finish_sentry_transaction(transaction, 200)
35
+ end
36
+ rescue Exception => e # rubocop:disable Lint/RescueException
37
+ finish_sentry_transaction(transaction, 500)
34
38
 
35
- Sentry::Rails.capture_exception(
36
- e,
37
- extra: sentry_context,
38
- tags: {
39
- job_id: job_id,
40
- provider_job_id:provider_job_id
41
- }
42
- )
43
- raise e
44
- end
39
+ Sentry::Rails.capture_exception(
40
+ e,
41
+ extra: sentry_context(job),
42
+ tags: {
43
+ job_id: job.job_id,
44
+ provider_job_id: job.provider_job_id
45
+ }
46
+ )
47
+ raise
48
+ end
49
+ end
50
+ end
45
51
 
46
- def finish_sentry_transaction(transaction, status)
47
- return unless transaction
52
+ def finish_sentry_transaction(transaction, status)
53
+ return unless transaction
48
54
 
49
- transaction.set_http_status(status)
50
- transaction.finish
51
- end
55
+ transaction.set_http_status(status)
56
+ transaction.finish
57
+ end
52
58
 
53
- def already_supported_by_sentry_integration?
54
- Sentry.configuration.rails.skippable_job_adapters.include?(self.class.queue_adapter.class.to_s)
55
- end
59
+ def sentry_context(job)
60
+ {
61
+ active_job: job.class.name,
62
+ arguments: sentry_serialize_arguments(job.arguments),
63
+ scheduled_at: job.scheduled_at,
64
+ job_id: job.job_id,
65
+ provider_job_id: job.provider_job_id,
66
+ locale: job.locale
67
+ }
68
+ end
56
69
 
57
- def sentry_context
58
- {
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
65
- }
70
+ def sentry_serialize_arguments(argument)
71
+ case argument
72
+ when Hash
73
+ argument.transform_values { |v| sentry_serialize_arguments(v) }
74
+ when Array, Enumerable
75
+ argument.map { |v| sentry_serialize_arguments(v) }
76
+ when ->(v) { v.respond_to?(:to_global_id) }
77
+ argument.to_global_id.to_s rescue argument
78
+ else
79
+ argument
80
+ end
81
+ end
82
+ end
66
83
  end
67
84
  end
68
85
  end
@@ -0,0 +1,11 @@
1
+ module Sentry
2
+ module Rails
3
+ # This is not a user-facing class. You should use it with Rails 7.0's error reporter feature and its interfaces.
4
+ # See https://github.com/rails/rails/blob/main/activesupport/lib/active_support/error_reporter.rb for more information.
5
+ class ErrorSubscriber
6
+ def report(error, handled:, severity:, context:)
7
+ Sentry::Rails.capture_exception(error, level: severity, contexts: { "rails.error" => context }, tags: { handled: handled })
8
+ end
9
+ end
10
+ end
11
+ end
@@ -46,6 +46,8 @@ module Sentry
46
46
  setup_backtrace_cleanup_callback
47
47
  inject_breadcrumbs_logger
48
48
  activate_tracing
49
+
50
+ register_error_subscriber(app) if ::Rails.version.to_f >= 7.0
49
51
  end
50
52
 
51
53
  runner do
@@ -115,5 +117,10 @@ module Sentry
115
117
  Sentry::Rails::Tracing.patch_active_support_notifications
116
118
  end
117
119
  end
120
+
121
+ def register_error_subscriber(app)
122
+ require "sentry/rails/error_subscriber"
123
+ app.executor.error_reporter.subscribe(Sentry::Rails::ErrorSubscriber.new)
124
+ end
118
125
  end
119
126
  end
@@ -5,10 +5,11 @@ module Sentry
5
5
  module Tracing
6
6
  class ActionViewSubscriber < AbstractSubscriber
7
7
  EVENT_NAMES = ["render_template.action_view"].freeze
8
+ SPAN_PREFIX = "template.".freeze
8
9
 
9
10
  def self.subscribe!
10
11
  subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
11
- record_on_current_span(op: event_name, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:identifier], duration: duration)
12
+ record_on_current_span(op: SPAN_PREFIX + event_name, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:identifier], duration: duration)
12
13
  end
13
14
  end
14
15
  end
@@ -5,13 +5,14 @@ module Sentry
5
5
  module Tracing
6
6
  class ActiveRecordSubscriber < AbstractSubscriber
7
7
  EVENT_NAMES = ["sql.active_record"].freeze
8
+ SPAN_PREFIX = "db.".freeze
8
9
  EXCLUDED_EVENTS = ["SCHEMA", "TRANSACTION"].freeze
9
10
 
10
11
  def self.subscribe!
11
12
  subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
12
13
  next if EXCLUDED_EVENTS.include? payload[:name]
13
14
 
14
- record_on_current_span(op: event_name, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:sql], duration: duration) do |span|
15
+ record_on_current_span(op: SPAN_PREFIX + event_name, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:sql], duration: duration) do |span|
15
16
  span.set_data(:connection_id, payload[:connection_id])
16
17
  end
17
18
  end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Rails
3
- VERSION = "5.0.1"
3
+ VERSION = "5.1.1"
4
4
  end
5
5
  end
data/sentry-rails.gemspec CHANGED
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ["lib"]
24
24
 
25
25
  spec.add_dependency "railties", ">= 5.0"
26
- spec.add_dependency "sentry-ruby-core", "~> 5.0.1"
26
+ spec.add_dependency "sentry-ruby-core", "~> 5.1.1"
27
27
  end
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: 5.0.1
4
+ version: 5.1.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: 2022-01-23 00:00:00.000000000 Z
11
+ date: 2022-02-24 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: 5.0.1
33
+ version: 5.1.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: 5.0.1
40
+ version: 5.1.1
41
41
  description: A gem that provides Rails integration for the Sentry error logger
42
42
  email: accounts@sentry.io
43
43
  executables: []
@@ -71,6 +71,7 @@ files:
71
71
  - lib/sentry/rails/controller_methods.rb
72
72
  - lib/sentry/rails/controller_transaction.rb
73
73
  - lib/sentry/rails/engine.rb
74
+ - lib/sentry/rails/error_subscriber.rb
74
75
  - lib/sentry/rails/instrument_payload_cleanup_helper.rb
75
76
  - lib/sentry/rails/overrides/streaming_reporter.rb
76
77
  - lib/sentry/rails/railtie.rb