sentry-rails 5.4.2 → 5.6.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: 92b1952096935f672e03a41883297d867b70e433c92434b24420062c37d2325f
4
- data.tar.gz: 3cdfb19c85436bdc509e00512734fe6eb11880bdbe22ef50e6d99908f38daf16
3
+ metadata.gz: 5bf51e07c223ef36d3cbe5ad72f7dad533159d05c1665b896a068394770327e4
4
+ data.tar.gz: 95c2fefcecd78940fc3e847cff711f855dda399d35adf6a6a343507304cd2e2a
5
5
  SHA512:
6
- metadata.gz: 2271053cd6e6d9f04ba55258d177347f8df8ce74d6c15bdb3083eef6cc3cd1b8f4847c448071c8e03b33d90498acc04f384c4cfe3730c792af046a1860a76a53
7
- data.tar.gz: 345700856d420c3e562201cedb88d18d396d4f60487bb945f262bffba028ca7f9b12aa481deeebad7607e8f9baa0c4db30308d97a856b45bd7fd0e3f75e06258
6
+ metadata.gz: cc9954d8ba18402bc7f20e3393d505b4cac9d422e3378261f793a7b19d2e478ca5585a5dd3ef5aa3a44424b84df102262ad63742e30ec31c39efd9b93dcffc66
7
+ data.tar.gz: ea7cb4dbf2f445a69802f8e6d171edebf21617b2fccddfa34152a3d1a90f813dbdd86ad227da328fa1509b8d72e7171375f6f885cc673c53d3afa6bb2864bf0b
@@ -2,6 +2,8 @@ module Sentry
2
2
  module Rails
3
3
  module ActionCableExtensions
4
4
  class ErrorHandler
5
+ OP_NAME = "websocket.server".freeze
6
+
5
7
  class << self
6
8
  def capture(connection, transaction_name:, extra_context: nil, &block)
7
9
  return block.call unless Sentry.initialized?
@@ -13,8 +15,8 @@ module Sentry
13
15
  Sentry.with_scope do |scope|
14
16
  scope.set_rack_env(env)
15
17
  scope.set_context("action_cable", extra_context) if extra_context
16
- scope.set_transaction_name(transaction_name)
17
- transaction = start_transaction(env, scope.transaction_name)
18
+ scope.set_transaction_name(transaction_name, source: :view)
19
+ transaction = start_transaction(env, scope)
18
20
  scope.set_span(transaction) if transaction
19
21
 
20
22
  begin
@@ -29,10 +31,12 @@ module Sentry
29
31
  end
30
32
  end
31
33
 
32
- def start_transaction(env, transaction_name)
34
+ def start_transaction(env, scope)
33
35
  sentry_trace = env["HTTP_SENTRY_TRACE"]
34
- options = { name: transaction_name, op: "rails.action_cable".freeze }
35
- transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace
36
+ baggage = env["HTTP_BAGGAGE"]
37
+
38
+ options = { name: scope.transaction_name, source: scope.transaction_source, op: OP_NAME }
39
+ transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, baggage: baggage, **options) if sentry_trace
36
40
  Sentry.start_transaction(transaction: transaction, **options)
37
41
  end
38
42
 
@@ -16,16 +16,18 @@ module Sentry
16
16
  end
17
17
 
18
18
  class SentryReporter
19
+ OP_NAME = "queue.active_job".freeze
20
+
19
21
  class << self
20
22
  def record(job, &block)
21
23
  Sentry.with_scope do |scope|
22
24
  begin
23
- scope.set_transaction_name(job.class.name)
25
+ scope.set_transaction_name(job.class.name, source: :task)
24
26
  transaction =
25
27
  if job.is_a?(::Sentry::SendEventJob)
26
28
  nil
27
29
  else
28
- Sentry.start_transaction(name: scope.transaction_name, op: "active_job")
30
+ Sentry.start_transaction(name: scope.transaction_name, source: scope.transaction_source, op: OP_NAME)
29
31
  end
30
32
 
31
33
  scope.set_span(transaction) if transaction
@@ -3,8 +3,11 @@ module Sentry
3
3
  def _perform(&block)
4
4
  block.call
5
5
  ensure
6
- # make sure the background worker returns AR connection if it accidentally acquire one during serialization
7
- ActiveRecord::Base.connection_pool.release_connection
6
+ # some applications have partial or even no AR connection
7
+ if ActiveRecord::Base.connected?
8
+ # make sure the background worker returns AR connection if it accidentally acquire one during serialization
9
+ ActiveRecord::Base.connection_pool.release_connection
10
+ end
8
11
  end
9
12
  end
10
13
  end
@@ -1,11 +1,11 @@
1
1
  module Sentry
2
2
  module Rails
3
3
  class CaptureExceptions < Sentry::Rack::CaptureExceptions
4
- def initialize(app)
4
+ def initialize(_)
5
5
  super
6
6
 
7
- if defined?(::Sprockets::Rails)
8
- @assets_regex = %r(\A/{0,2}#{::Rails.application.config.assets.prefix})
7
+ if Sentry.initialized?
8
+ @assets_regexp = Sentry.configuration.rails.assets_regexp
9
9
  end
10
10
  end
11
11
 
@@ -17,7 +17,7 @@ module Sentry
17
17
  end
18
18
 
19
19
  def transaction_op
20
- "rails.request".freeze
20
+ "http.server".freeze
21
21
  end
22
22
 
23
23
  def capture_exception(exception, env)
@@ -25,13 +25,6 @@ module Sentry
25
25
 
26
26
  # the exception will be swallowed by ShowExceptions middleware
27
27
  return if request.show_exceptions? && !Sentry.configuration.rails.report_rescued_exceptions
28
-
29
- current_scope = Sentry.get_current_scope
30
-
31
- if original_transaction = env["sentry.original_transaction"]
32
- current_scope.set_transaction_name(original_transaction)
33
- end
34
-
35
28
  Sentry::Rails.capture_exception(exception).tap do |event|
36
29
  env[ERROR_EVENT_ID_KEY] = event.event_id if event
37
30
  end
@@ -39,13 +32,15 @@ module Sentry
39
32
 
40
33
  def start_transaction(env, scope)
41
34
  sentry_trace = env["HTTP_SENTRY_TRACE"]
42
- options = { name: scope.transaction_name, op: transaction_op }
35
+ baggage = env["HTTP_BAGGAGE"]
36
+
37
+ options = { name: scope.transaction_name, source: scope.transaction_source, op: transaction_op }
43
38
 
44
- if @assets_regex && scope.transaction_name.match?(@assets_regex)
39
+ if @assets_regexp && scope.transaction_name.match?(@assets_regexp)
45
40
  options.merge!(sampled: false)
46
41
  end
47
42
 
48
- transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace
43
+ transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, baggage: baggage, **options) if sentry_trace
49
44
  Sentry.start_transaction(transaction: transaction, custom_sampling_context: { env: env }, **options)
50
45
  end
51
46
  end
@@ -60,10 +60,28 @@ module Sentry
60
60
 
61
61
  attr_accessor :tracing_subscribers
62
62
 
63
+ # sentry-rails by default skips asset request' transactions by checking if the path matches
64
+ #
65
+ # ```rb
66
+ # %r(\A/{0,2}#{::Rails.application.config.assets.prefix})
67
+ # ```
68
+ #
69
+ # If you want to use a different pattern, you can configure the `assets_regexp` option like:
70
+ #
71
+ # ```rb
72
+ # Sentry.init do |config|
73
+ # config.rails.assets_regexp = /my_regexp/
74
+ # end
75
+ # ```
76
+ attr_accessor :assets_regexp
77
+
63
78
  def initialize
64
79
  @register_error_subscriber = false
65
80
  @report_rescued_exceptions = true
66
81
  @skippable_job_adapters = []
82
+ @assets_regexp = if defined?(::Sprockets::Rails)
83
+ %r(\A/{0,2}#{::Rails.application.config.assets.prefix})
84
+ end
67
85
  @tracing_subscribers = Set.new([
68
86
  Sentry::Rails::Tracing::ActionControllerSubscriber,
69
87
  Sentry::Rails::Tracing::ActionViewSubscriber,
@@ -3,7 +3,9 @@ module Sentry
3
3
  module ControllerTransaction
4
4
  def self.included(base)
5
5
  base.prepend_before_action do |controller|
6
- Sentry.get_current_scope.set_transaction_name("#{controller.class}##{controller.action_name}")
6
+ if Sentry.initialized?
7
+ Sentry.get_current_scope.set_transaction_name("#{controller.class}##{controller.action_name}", source: :view)
8
+ end
7
9
  end
8
10
  end
9
11
  end
@@ -1,7 +1,8 @@
1
1
  module Sentry
2
2
  module Rails
3
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.
4
+ # See https://github.com/rails/rails/blob/main/activesupport/lib/active_support/error_reporter.rb to learn more about reporting APIs.
5
+ # If you want Sentry to subscribe to the error reporter, please set `config.rails.register_error_subscriber` to `true`.
5
6
  class ErrorSubscriber
6
7
  SKIP_SOURCES = Regexp.union([/.*_cache_store.active_support/])
7
8
 
@@ -8,6 +8,7 @@ module Sentry
8
8
  extend InstrumentPayloadCleanupHelper
9
9
 
10
10
  EVENT_NAMES = ["process_action.action_controller"].freeze
11
+ OP_NAME = "view.process_action.action_controller".freeze
11
12
 
12
13
  def self.subscribe!
13
14
  subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
@@ -15,7 +16,7 @@ module Sentry
15
16
  action = payload[:action]
16
17
 
17
18
  record_on_current_span(
18
- op: event_name,
19
+ op: OP_NAME,
19
20
  start_timestamp: payload[START_TIMESTAMP_NAME],
20
21
  description: "#{controller}##{action}",
21
22
  duration: duration
@@ -21,7 +21,7 @@ module Sentry
21
21
 
22
22
  def self.subscribe!
23
23
  subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
24
- record_on_current_span(op: event_name, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:service], duration: duration) do |span|
24
+ record_on_current_span(op: "file.#{event_name}".freeze, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:service], duration: duration) do |span|
25
25
  payload.each do |key, value|
26
26
  span.set_data(key, value) unless key == START_TIMESTAMP_NAME
27
27
  end
@@ -67,7 +67,7 @@ module Sentry
67
67
  end
68
68
 
69
69
  def self.get_current_transaction
70
- Sentry.get_current_scope.get_transaction
70
+ Sentry.get_current_scope.get_transaction if Sentry.initialized?
71
71
  end
72
72
 
73
73
  # it's just a container for the extended method
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Rails
3
- VERSION = "5.4.2"
3
+ VERSION = "5.6.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", "~> 5.4.2"
26
+ spec.add_dependency "sentry-ruby", "~> 5.6.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.4.2
4
+ version: 5.6.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-08-17 00:00:00.000000000 Z
11
+ date: 2022-11-08 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.4.2
33
+ version: 5.6.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.4.2
40
+ version: 5.6.0
41
41
  description: A gem that provides Rails integration for the Sentry error logger
42
42
  email: accounts@sentry.io
43
43
  executables: []