Class: NewRelic::Agent::SqlTrace

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

Instance Attribute Summary collapse

Attributes inherited from Stats

#call_count, #max_call_time, #min_call_time, #sum_of_squares, #total_call_time, #total_exclusive_time

Instance Method Summary collapse

Methods included from Coerce

#float, #int, #log_failure, #string

Methods inherited from Stats

#==, #increment_count, #inspect, #is_reset?, #merge, #merge!, #record_apdex_f, #record_apdex_s, #record_apdex_t, #record_data_point, #record_multiple_data_points, #reset, #to_json, #to_s

Constructor Details

#initialize(normalized_query, slow_sql, path, uri) ⇒ SqlTrace

Returns a new instance of SqlTrace.



188
189
190
191
192
193
194
# File 'lib/new_relic/agent/sql_sampler.rb', line 188

def initialize(normalized_query, slow_sql, path, uri)
  super()
  @params = {} #FIXME
  @sql_id = consistent_hash(normalized_query)
  set_primary slow_sql, path, uri
  record_data_point(float(slow_sql.duration))
end

Instance Attribute Details

#database_metric_nameObject (readonly)

Returns the value of attribute database_metric_name.



185
186
187
# File 'lib/new_relic/agent/sql_sampler.rb', line 185

def database_metric_name
  @database_metric_name
end

#paramsObject (readonly)

Returns the value of attribute params.



186
187
188
# File 'lib/new_relic/agent/sql_sampler.rb', line 186

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



181
182
183
# File 'lib/new_relic/agent/sql_sampler.rb', line 181

def path
  @path
end

#sqlObject (readonly)

Returns the value of attribute sql.



184
185
186
# File 'lib/new_relic/agent/sql_sampler.rb', line 184

def sql
  @sql
end

#sql_idObject (readonly)

Returns the value of attribute sql_id.



183
184
185
# File 'lib/new_relic/agent/sql_sampler.rb', line 183

def sql_id
  @sql_id
end

#urlObject (readonly)

Returns the value of attribute url.



182
183
184
# File 'lib/new_relic/agent/sql_sampler.rb', line 182

def url
  @url
end

Instance Method Details

#aggregate(slow_sql, path, uri) ⇒ Object



206
207
208
209
210
211
212
# File 'lib/new_relic/agent/sql_sampler.rb', line 206

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

#need_to_explain?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/new_relic/agent/sql_sampler.rb', line 223

def need_to_explain?
  Agent.config[:'slow_sql.explain_enabled']
end

#need_to_obfuscate?Boolean

Returns:

  • (Boolean)


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

def need_to_obfuscate?
  Agent.config[:'slow_sql.record_sql'].to_s == 'obfuscated'
end

#prepare_to_sendObject



214
215
216
217
# File 'lib/new_relic/agent/sql_sampler.rb', line 214

def prepare_to_send
  params[:explain_plan] = @slow_sql.explain if need_to_explain?
  @sql = @slow_sql.obfuscate if need_to_obfuscate?
end

#set_primary(slow_sql, path, uri) ⇒ Object



196
197
198
199
200
201
202
203
204
# File 'lib/new_relic/agent/sql_sampler.rb', line 196

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
  # FIXME
  @params[:backtrace] = slow_sql.backtrace if slow_sql.backtrace
end

#to_collector_array(encoder) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/new_relic/agent/sql_sampler.rb', line 229

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