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.



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

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)



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

def backtrace
  @backtrace
end

#durationObject (readonly)



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

def duration
  @duration
end

#metric_nameObject (readonly)



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

def metric_name
  @metric_name
end

#statementObject (readonly)



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

def statement
  @statement
end

Instance Method Details

#base_paramsObject



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

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



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

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

#normalizeObject



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

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

#obfuscateObject



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

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

#prepare_to_sendObject

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



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

def prepare_to_send
  statement.explainer = nil
end

#sqlObject



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

def sql
  statement.sql
end