Class: Sentry::Rails::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/sentry/rails/log_subscriber.rb

Overview

Base class for Sentry log subscribers that extends ActiveSupport::LogSubscriber to provide structured logging capabilities for Rails components.

This class follows Rails’ LogSubscriber pattern and provides common functionality for capturing Rails instrumentation events and logging them through Sentry’s structured logging system.

Examples:

Creating a custom log subscriber

class MySubscriber < Sentry::Rails::LogSubscriber
  attach_to :my_component

  def my_event(event)
    log_structured_event(
      message: "My event occurred",
      level: :info,
      attributes: {
        duration_ms: event.duration,
        custom_data: event.payload[:custom_data]
      }
    )
  end
end

Constant Summary collapse

ORIGIN =
"auto.logger.rails.log_subscriber"

Instance Method Summary collapse

Instance Method Details

#detach_from(namespace, notifications = ActiveSupport::Notifications) ⇒ Object

Rails 5.x does not provide detach_from



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sentry/rails/log_subscriber.rb', line 35

def detach_from(namespace, notifications = ActiveSupport::Notifications)
  listeners = public_instance_methods(false)
    .flat_map { |key|
      notifications.notifier.listeners_for("#{key}.#{namespace}")
    }
    .select { |listener| listener.instance_variable_get(:@delegate).is_a?(self) }

  listeners.map do |listener|
    notifications.notifier.unsubscribe(listener)
  end
end