Class: NewRelic::Agent::SlowSql

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/sql_sampler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statement, metric_name, duration, backtrace = nil, params = nil) ⇒ SlowSql

Returns a new instance of SlowSql.



243
244
245
246
247
248
249
# File 'lib/new_relic/agent/sql_sampler.rb', line 243

def initialize(statement, metric_name, duration, backtrace = nil, params = nil)
  @statement = statement
  @metric_name = metric_name
  @duration = duration
  @backtrace = backtrace
  @params = params
end

Instance Attribute Details

#backtraceObject (readonly)



241
242
243
# File 'lib/new_relic/agent/sql_sampler.rb', line 241

def backtrace
  @backtrace
end

#durationObject (readonly)



240
241
242
# File 'lib/new_relic/agent/sql_sampler.rb', line 240

def duration
  @duration
end

#metric_nameObject (readonly)



239
240
241
# File 'lib/new_relic/agent/sql_sampler.rb', line 239

def metric_name
  @metric_name
end

#statementObject (readonly)



238
239
240
# File 'lib/new_relic/agent/sql_sampler.rb', line 238

def statement
  @statement
end

Instance Method Details

#base_paramsObject



255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/new_relic/agent/sql_sampler.rb', line 255

def base_params
  params = @params || {}

  if NewRelic::Agent.config[:'datastore_tracer.instance_reporting.enabled']
    params[:host] = statement.host if statement.host
    params[:port_path_or_id] = statement.port_path_or_id if statement.port_path_or_id
  end
  if NewRelic::Agent.config[:'datastore_tracer.database_name_reporting.enabled'] && statement.database_name
    params[:database_name] = statement.database_name
  end

  params
end

#explainObject



278
279
280
281
282
# File 'lib/new_relic/agent/sql_sampler.rb', line 278

def explain
  if statement.config && statement.explainer
    NewRelic::Agent::Database.explain_sql(statement)
  end
end

#normalizeObject



273
274
275
276
# File 'lib/new_relic/agent/sql_sampler.rb', line 273

def normalize
  NewRelic::Agent::Database::Obfuscator.instance \
    .default_sql_obfuscator(statement).gsub(/\?\s*\,\s*/, '').gsub(/\s/, '')
end

#obfuscateObject



269
270
271
# File 'lib/new_relic/agent/sql_sampler.rb', line 269

def obfuscate
  NewRelic::Agent::Database.obfuscate_sql(statement)
end

#prepare_to_sendObject

We can’t serialize the explainer, so clear it before we transmit



285
286
287
# File 'lib/new_relic/agent/sql_sampler.rb', line 285

def prepare_to_send
  statement.explainer = nil
end

#sqlObject



251
252
253
# File 'lib/new_relic/agent/sql_sampler.rb', line 251

def sql
  statement.sql
end