module Sentry::Rails::Tracing

Public Class Methods

get_current_transaction() click to toggle source
# File lib/sentry/rails/tracing.rb, line 57
def self.get_current_transaction
  Sentry.get_current_scope.get_transaction
end
patch_active_support_notifications() click to toggle source

this is necessary because instrumentation events don't record absolute start/finish time so we need to retrieve the correct time this way

# File lib/sentry/rails/tracing.rb, line 31
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
register_subscribers(subscribers) click to toggle source
# File lib/sentry/rails/tracing.rb, line 4
def self.register_subscribers(subscribers)
  @subscribers = subscribers
end
remove_active_support_notifications_patch() click to toggle source
# File lib/sentry/rails/tracing.rb, line 47
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
subscribe_tracing_events() click to toggle source
# File lib/sentry/rails/tracing.rb, line 12
def self.subscribe_tracing_events
  # need to avoid duplicated subscription
  return if @subscribed

  subscribers.each(&:subscribe!)

  @subscribed = true
end
subscribers() click to toggle source
# File lib/sentry/rails/tracing.rb, line 8
def self.subscribers
  @subscribers
end
unsubscribe_tracing_events() click to toggle source
# File lib/sentry/rails/tracing.rb, line 21
def self.unsubscribe_tracing_events
  return unless @subscribed

  subscribers.each(&:unsubscribe!)

  @subscribed = false
end

Public Instance Methods

instrument(name, payload = {}, &block) click to toggle source
Calls superclass method
# File lib/sentry/rails/tracing.rb, line 37
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