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

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

API:

  • private

Constant Summary collapse

OPERATION_NAME_PREFIX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

"active_record:"
DEFAULT_OPERATION_NAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

"sqlquery"

Instance Method Summary collapse

Methods inherited from AbstractInstrumenter

#finish, #scope_stack, #start

Instance Method Details

#span_name(payload) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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

  tags = {
    "component" => COMPONENT_TAG,
    "span.kind" => "client",
    "db.type" => "sql",
    "db.cached" => payload[:cached] || false,
  }

  # OpenTelemetry rejects nil attributes, so only add statement fields
  # when ActiveRecord supplies SQL (schema events may omit it).
  tags["db.statement"] = sql if sql
  tags["db.statement_fingerprint"] = fingerprint if fingerprint
  tags["db.connection_id"] = payload[:connection_id] if payload[:connection_id]

  tags
end