Class: Sentry::Rails::LogSubscribers::ActiveRecordSubscriber
- Inherits:
-
Sentry::Rails::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- Sentry::Rails::LogSubscriber
- Sentry::Rails::LogSubscribers::ActiveRecordSubscriber
- Includes:
- ParameterFilter
- Defined in:
- lib/sentry/rails/log_subscribers/active_record_subscriber.rb
Overview
LogSubscriber for ActiveRecord events that captures database queries and logs them using Sentry’s structured logging system.
This subscriber captures sql.active_record events and formats them with relevant database information including SQL queries, duration, database configuration, and caching information.
Constant Summary collapse
- EXCLUDED_NAMES =
["SCHEMA", "TRANSACTION"].freeze
Constants included from ParameterFilter
Instance Method Summary collapse
-
#sql(event) ⇒ Object
Handle sql.active_record events.
Methods included from ParameterFilter
backend, #filter_sensitive_params
Methods inherited from Sentry::Rails::LogSubscriber
Instance Method Details
#sql(event) ⇒ Object
Handle sql.active_record events
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sentry/rails/log_subscribers/active_record_subscriber.rb', line 31 def sql(event) return if EXCLUDED_NAMES.include?(event.payload[:name]) sql = event.payload[:sql] statement_name = event.payload[:name] # Rails 5.0.0 doesn't include :cached in the payload, it was added in Rails 5.1 cached = event.payload.fetch(:cached, false) connection_id = event.payload[:connection_id] db_config = extract_db_config(event.payload) attributes = { sql: sql, duration_ms: duration_ms(event), cached: cached } attributes[:statement_name] = statement_name if statement_name && statement_name != "SQL" attributes[:connection_id] = connection_id if connection_id add_db_config_attributes(attributes, db_config) = (statement_name) log_structured_event( message: , level: :info, attributes: attributes ) end |