Class: NewRelic::Agent::SlowSql
- Inherits:
-
Object
- Object
- NewRelic::Agent::SlowSql
- Defined in:
- lib/new_relic/agent/sql_sampler.rb
Instance Attribute Summary collapse
- #backtrace ⇒ Object readonly
- #duration ⇒ Object readonly
- #metric_name ⇒ Object readonly
- #statement ⇒ Object readonly
Instance Method Summary collapse
- #base_params ⇒ Object
- #explain ⇒ Object
-
#initialize(statement, metric_name, duration, backtrace = nil, params = nil) ⇒ SlowSql
constructor
A new instance of SlowSql.
- #normalize ⇒ Object
- #obfuscate ⇒ Object
-
#prepare_to_send ⇒ Object
We can’t serialize the explainer, so clear it before we transmit.
- #sql ⇒ Object
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
#backtrace ⇒ Object (readonly)
240 241 242 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 240 def backtrace @backtrace end |
#duration ⇒ Object (readonly)
239 240 241 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 239 def duration @duration end |
#metric_name ⇒ Object (readonly)
238 239 240 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 238 def metric_name @metric_name end |
#statement ⇒ Object (readonly)
237 238 239 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 237 def statement @statement end |
Instance Method Details
#base_params ⇒ Object
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 |
#explain ⇒ Object
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 |
#normalize ⇒ Object
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 |
#obfuscate ⇒ Object
268 269 270 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 268 def obfuscate NewRelic::Agent::Database.obfuscate_sql(statement) end |
#prepare_to_send ⇒ Object
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 |
#sql ⇒ Object
250 251 252 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 250 def sql statement.sql end |