Class: CloseYourIt::Subscribers::SlowQuery
- Inherits:
-
Object
- Object
- CloseYourIt::Subscribers::SlowQuery
- Defined in:
- lib/closeyourit/subscribers/slow_query.rb
Overview
Riceve i dati di un evento ‘sql.active_record` e, se la query supera la soglia (escludendo SCHEMA/CACHE/TRANSACTION), invia un evento `slow_query`. Logica pura: il wiring ad ActiveSupport::Notifications vive nel Railtie.
Constant Summary collapse
- IGNORED_NAMES =
%w[SCHEMA CACHE TRANSACTION].freeze
Instance Method Summary collapse
-
#breadcrumb(name:, sql:, duration_ms:, cached: false) ⇒ Object
Breadcrumb per OGNI query non di sistema (non solo lente): SQL offuscato, niente bind.
-
#initialize(configuration = nil) ⇒ SlowQuery
constructor
A new instance of SlowQuery.
- #record(name:, duration_ms:, sql:, cached: false, connection: nil, binds: nil, type_casted_binds: nil, source: nil) ⇒ Object
Constructor Details
#initialize(configuration = nil) ⇒ SlowQuery
Returns a new instance of SlowQuery.
14 15 16 |
# File 'lib/closeyourit/subscribers/slow_query.rb', line 14 def initialize(configuration = nil) @configuration = configuration end |
Instance Method Details
#breadcrumb(name:, sql:, duration_ms:, cached: false) ⇒ Object
Breadcrumb per OGNI query non di sistema (non solo lente): SQL offuscato, niente bind. Dà la cronologia “quali query prima del crash” allegata all’evento d’errore.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/closeyourit/subscribers/slow_query.rb', line 35 def (name:, sql:, duration_ms:, cached: false) config = @configuration || CloseYourIt.configuration return if ignored_name?(name) return unless config. CloseYourIt.( category: "query", type: "query", message: Scrubber.new(config).obfuscate_sql(sql), data: { "name" => name, "duration_ms" => duration_ms.to_f.round(2), "cached" => cached } ) end |
#record(name:, duration_ms:, sql:, cached: false, connection: nil, binds: nil, type_casted_binds: nil, source: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/closeyourit/subscribers/slow_query.rb', line 18 def record(name:, duration_ms:, sql:, cached: false, connection: nil, binds: nil, type_casted_binds: nil, source: nil) config = @configuration || CloseYourIt.configuration return if ignored_name?(name) return if duration_ms < config.slow_query_threshold_ms event = SlowQueryEvent.new( { name: name, sql: sql, cached: cached, connection: connection, binds: binds, type_casted_binds: type_casted_binds, source: source }, duration_ms, config ) CloseYourIt.capture_event(event) end |