module Sentry::Rails::Tracing

def self.get_current_transaction

def self.get_current_transaction
  Sentry.get_current_scope.get_transaction
end

def self.patch_active_support_notifications

so we need to retrieve the correct time this way
this is necessary because instrumentation events don't record absolute start/finish time
def self.patch_active_support_notifications
  unless ::ActiveSupport::Notifications::Instrumenter.ancestors.include?(SentryNotificationExtension)
    ::ActiveSupport::Notifications::Instrumenter.send(:prepend, SentryNotificationExtension)
  end
  SentryNotificationExtension.module_eval do
    def instrument(name, payload = {}, &block)
      is_public_event = name[0] != "!"
      payload[:start_timestamp] = Time.now.utc.to_f if is_public_event
      super(name, payload, &block)
    end
  end
end

def self.remove_active_support_notifications_patch

def self.remove_active_support_notifications_patch
  if ::ActiveSupport::Notifications::Instrumenter.ancestors.include?(SentryNotificationExtension)
    SentryNotificationExtension.module_eval do
      def instrument(name, payload = {}, &block)
        super
      end
    end
  end
end

def self.subscribe_tracing_events

def self.subscribe_tracing_events
  # need to avoid duplicated subscription
  return if @subscribed
  AVAILABLE_SUBSCRIBERS.each(&:subscribe!)
  @subscribed = true
end

def self.unsubscribe_tracing_events

def self.unsubscribe_tracing_events
  return unless @subscribed
  AVAILABLE_SUBSCRIBERS.each(&:unsubscribe!)
  @subscribed = false
end

def instrument(name, payload = {}, &block)

def instrument(name, payload = {}, &block)
  is_public_event = name[0] != "!"
  payload[:start_timestamp] = Time.now.utc.to_f if is_public_event
  super(name, payload, &block)
end

def instrument(name, payload = {}, &block)

def instrument(name, payload = {}, &block)
  super
end