Class: Sentry::Rails::ActionCableExtensions::ErrorHandler
- Inherits:
-
Object
- Object
- Sentry::Rails::ActionCableExtensions::ErrorHandler
- Defined in:
- lib/sentry/rails/action_cable.rb
Constant Summary collapse
- OP_NAME =
"websocket.server"
- SPAN_ORIGIN =
"auto.http.rails.actioncable"
Class Method Summary collapse
- .capture(connection, transaction_name:, extra_context: nil, &block) ⇒ Object
- .finish_transaction(transaction, status_code) ⇒ Object
- .start_transaction(env, scope) ⇒ Object
Class Method Details
.capture(connection, transaction_name:, extra_context: nil, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sentry/rails/action_cable.rb', line 11 def capture(connection, transaction_name:, extra_context: nil, &block) return block.call unless Sentry.initialized? # ActionCable's ConnectionStub (for testing) doesn't implement the exact same interfaces as Connection::Base. # One thing that's missing is `env`. So calling `connection.env` direclty will fail in test environments when `stub_connection` is used. # See https://github.com/getsentry/sentry-ruby/pull/1684 for more information. env = connection.respond_to?(:env) ? connection.env : {} Sentry.with_scope do |scope| scope.set_rack_env(env) scope.set_context("action_cable", extra_context) if extra_context scope.set_transaction_name(transaction_name, source: :view) transaction = start_transaction(env, scope) scope.set_span(transaction) if transaction begin result = block.call finish_transaction(transaction, 200) result rescue Exception => e # rubocop:disable Lint/RescueException Sentry::Rails.capture_exception(e) finish_transaction(transaction, 500) raise end end end |
.finish_transaction(transaction, status_code) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/sentry/rails/action_cable.rb', line 50 def finish_transaction(transaction, status_code) return unless transaction transaction.set_http_status(status_code) transaction.finish end |
.start_transaction(env, scope) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sentry/rails/action_cable.rb', line 38 def start_transaction(env, scope) = { name: scope.transaction_name, source: scope.transaction_source, op: OP_NAME, origin: SPAN_ORIGIN } transaction = Sentry.continue_trace(env, **) Sentry.start_transaction(transaction: transaction, **) end |