class NewRelic::Agent::SqlTrace
Attributes
Public Class Methods
Source
# File lib/new_relic/agent/sql_sampler.rb, line 298 def initialize(normalized_query, slow_sql, path, uri) super() @params = slow_sql.base_params @sql_id = consistent_hash(normalized_query) set_primary(slow_sql, path, uri) record_data_point(float(slow_sql.duration)) end
Calls superclass method
Public Instance Methods
Source
# File lib/new_relic/agent/sql_sampler.rb, line 315 def aggregate(slow_sql, path, uri) if slow_sql.duration > max_call_time set_primary(slow_sql, path, uri) end record_data_point(float(slow_sql.duration)) end
Source
# File lib/new_relic/agent/sql_sampler.rb, line 323 def aggregate_trace(trace) aggregate(trace.slow_sql, trace.path, trace.url) end
Source
# File lib/new_relic/agent/sql_sampler.rb, line 337 def need_to_explain? Agent.config[:'slow_sql.explain_enabled'] end
Source
# File lib/new_relic/agent/sql_sampler.rb, line 333 def need_to_obfuscate? Agent.config[:'slow_sql.record_sql'].to_s == 'obfuscated' end
Source
# File lib/new_relic/agent/sql_sampler.rb, line 327 def prepare_to_send params[:explain_plan] = @slow_sql.explain if need_to_explain? @sql = @slow_sql.obfuscate if need_to_obfuscate? @slow_sql.prepare_to_send end
Source
# File lib/new_relic/agent/sql_sampler.rb, line 306 def set_primary(slow_sql, path, uri) @slow_sql = slow_sql @sql = slow_sql.sql @database_metric_name = slow_sql.metric_name @path = path @url = uri @params[:backtrace] = slow_sql.backtrace if slow_sql.backtrace end
Source
# File lib/new_relic/agent/sql_sampler.rb, line 343 def to_collector_array(encoder) [string(@path), string(@url), int(@sql_id), string(@sql), string(@database_metric_name), int(@call_count), Helper.time_to_millis(@total_call_time), Helper.time_to_millis(@min_call_time), Helper.time_to_millis(@max_call_time), encoder.encode(@params)] end
Private Instance Methods
Source
# File lib/new_relic/agent/sql_sampler.rb, line 359 def consistent_hash(string) if NewRelic::Agent.config[:'slow_sql.use_longer_sql_id'] Digest::SHA1.hexdigest(string).hex.modulo(2**63 - 1) else # from when sql_id needed to fit in an INT(11) Digest::SHA1.hexdigest(string).hex.modulo(2**31 - 1) end end
need to hash the same way in every process, to be able to aggregate slow SQL traces