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.



210
211
212
213
214
215
216
# File 'lib/new_relic/agent/sql_sampler.rb', line 210

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)



208
209
210
# File 'lib/new_relic/agent/sql_sampler.rb', line 208

def backtrace
  @backtrace
end

#durationObject (readonly)



207
208
209
# File 'lib/new_relic/agent/sql_sampler.rb', line 207

def duration
  @duration
end

#metric_nameObject (readonly)



206
207
208
# File 'lib/new_relic/agent/sql_sampler.rb', line 206

def metric_name
  @metric_name
end

#statementObject (readonly)



205
206
207
# File 'lib/new_relic/agent/sql_sampler.rb', line 205

def statement
  @statement
end

Instance Method Details

#base_paramsObject



222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/new_relic/agent/sql_sampler.rb', line 222

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



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

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

#normalizeObject



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

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

#obfuscateObject



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

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

#prepare_to_sendObject

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



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

def prepare_to_send
  statement.explainer = nil
end

#sqlObject



218
219
220
# File 'lib/new_relic/agent/sql_sampler.rb', line 218

def sql
  statement.sql
end