Class: Labkit::Tracing::Rails::ActiveRecord::SqlInstrumenter

Inherits:
AbstractInstrumenter show all
Defined in:
lib/labkit/tracing/rails/active_record/sql_instrumenter.rb

Overview

For more information on the payloads: guides.rubyonrails.org/active_support_instrumentation.html

Constant Summary collapse

OPERATION_NAME_PREFIX =
"active_record:"
DEFAULT_OPERATION_NAME =
"sqlquery"

Instance Method Summary collapse

Methods inherited from AbstractInstrumenter

#finish, #scope_stack, #start

Instance Method Details

#span_name(payload) ⇒ Object



12
13
14
# File 'lib/labkit/tracing/rails/active_record/sql_instrumenter.rb', line 12

def span_name(payload)
  OPERATION_NAME_PREFIX + (payload[:name].presence || DEFAULT_OPERATION_NAME)
end

#tags(payload) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/labkit/tracing/rails/active_record/sql_instrumenter.rb', line 16

def tags(payload)
  if Labkit::Tracing.sampled? && payload[:sql]
    sql = Labkit::Logging::Sanitizer.sanitize_sql(payload[:sql])
    fingerprint = Labkit::Logging::Sanitizer.sql_fingerprint(sql)
  end

  {
    "component" => COMPONENT_TAG,
    "span.kind" => "client",
    "db.type" => "sql",
    "db.connection_id" => payload[:connection_id],
    "db.cached" => payload[:cached] || false,
    "db.statement" => sql,
    "db.statement_fingerprint" => fingerprint,
  }
end