class Sentry::Rails::Tracing::AbstractSubscriber

Public Class Methods

record_on_current_span(duration:, **options) { |span| ... } click to toggle source
# File lib/sentry/rails/tracing/abstract_subscriber.rb, line 32
def record_on_current_span(duration:, **options)
  return unless options[:start_timestamp]

  scope = Sentry.get_current_scope
  transaction = scope.get_transaction
  return unless transaction && transaction.sampled

  span = transaction.start_child(**options)
  # duration in ActiveSupport is computed in millisecond
  # so we need to covert it as second before calculating the timestamp
  span.set_timestamp(span.start_timestamp + duration / 1000)
  yield(span) if block_given?
end
subscribe!() click to toggle source
# File lib/sentry/rails/tracing/abstract_subscriber.rb, line 7
def subscribe!
  raise NotImplementedError
end
subscribe_to_event(event_name) { |event_name, duration, payload| ... } click to toggle source
# File lib/sentry/rails/tracing/abstract_subscriber.rb, line 15
def subscribe_to_event(event_name)
  if ::Rails.version.to_i == 5
    ActiveSupport::Notifications.subscribe(event_name) do |*args|
      next unless Tracing.get_current_transaction

      event = ActiveSupport::Notifications::Event.new(*args)
      yield(event_name, event.duration, event.payload)
    end
  else
    ActiveSupport::Notifications.subscribe(event_name) do |event|
      next unless Tracing.get_current_transaction

      yield(event_name, event.duration, event.payload)
    end
  end
end
unsubscribe!() click to toggle source
# File lib/sentry/rails/tracing/abstract_subscriber.rb, line 11
def unsubscribe!
  ActiveSupport::Notifications.unsubscribe(self::EVENT_NAME)
end