sentry-rails 5.0.2 → 5.1.0

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: dbb2adfc21656bba09244e0895c88a20f58e2401fcb5d4b693f48d10319c9121
4
- data.tar.gz: 6e2c595d8d719208524bfa270d6aa0e8d2123c60b80923fe05323f93bb29f98f
3
+ metadata.gz: f45143dd79cff19a0e7338912f235cec728d9ceb81a37e7a50df78a1722ce1b8
4
+ data.tar.gz: 7b5a8dec4f9b6875f6f42794911d30e7a75e0a8662e7d5e83584726066eb3fd4
5
5
  SHA512:
6
- metadata.gz: b3af907f32e77d292f5d86b99bfa5d62e580118e4971f940eb07278951147a9e53b4680926d436833d69548b0872eb560cb2c73dc44361b86ab2e951271d9519
7
- data.tar.gz: daad9ecf642f47a149ff2065ee3ce79e56ab33b2379b477f60d86c85ca051c8e0c4cc924c1c68786bdb015b7eac4e998c336b8d5ad0883fe0f11050586fc1103
6
+ metadata.gz: 0dbdd5331da560f4bc67a84390bb1f3579fbe7e03da95758cc2e3b103540f407bb2efb153202070f57dc4e2e1b5044dd9dca7e237272460560531d160890211c
7
+ data.tar.gz: 1163c26220a308aca6fe3f624e4358446f82d1919eda4daf0c38729f1977eba08b53c4f8bb65543adfc1df7a129ca4098af35060acb3d921d8ddf58025176633
@@ -37,7 +37,7 @@ module Sentry
37
37
  extra: sentry_context,
38
38
  tags: {
39
39
  job_id: job_id,
40
- provider_job_id:provider_job_id
40
+ provider_job_id: provider_job_id
41
41
  }
42
42
  )
43
43
  raise e
@@ -57,13 +57,26 @@ module Sentry
57
57
  def sentry_context
58
58
  {
59
59
  active_job: self.class.name,
60
- arguments: arguments,
60
+ arguments: sentry_serialize_arguments(arguments),
61
61
  scheduled_at: scheduled_at,
62
62
  job_id: job_id,
63
63
  provider_job_id: provider_job_id,
64
64
  locale: locale
65
65
  }
66
66
  end
67
+
68
+ def sentry_serialize_arguments(argument)
69
+ case argument
70
+ when Hash
71
+ argument.transform_values { |v| sentry_serialize_arguments(v) }
72
+ when Array, Enumerable
73
+ argument.map { |v| sentry_serialize_arguments(v) }
74
+ when ->(v) { v.respond_to?(:to_global_id) }
75
+ argument.to_global_id.to_s rescue argument
76
+ else
77
+ argument
78
+ end
79
+ end
67
80
  end
68
81
  end
69
82
  end
@@ -0,0 +1,20 @@
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
+ # a component may already have an integration to capture exceptions while its operation is also wrapped inside an `app.executor.wrap` (e.g. ActionCable)
8
+ # in such condition, the exception would be captured repeatedly. it usually happens in this order:
9
+ #
10
+ # 1. exception captured and reported by the component integration and re-raised
11
+ # 2. exception captured by the executor, which then reports it with executor.error_reporter
12
+ #
13
+ # and because there's no direct communication between the 2 callbacks, we need a way to identify if an exception has been captured before
14
+ # using a Sentry-specific intance variable should be the last impactful way
15
+ return if error.instance_variable_get(:@__sentry_captured)
16
+ Sentry::Rails.capture_exception(error, level: severity, contexts: { "rails.error" => context }, tags: { handled: handled })
17
+ end
18
+ end
19
+ end
20
+ 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.2"
3
+ VERSION = "5.1.0"
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.2"
26
+ spec.add_dependency "sentry-ruby-core", "~> 5.1.0"
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.2
4
+ version: 5.1.0
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-31 00:00:00.000000000 Z
11
+ date: 2022-02-10 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.2
33
+ version: 5.1.0
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.2
40
+ version: 5.1.0
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