Class: Skylight::Core::Normalizers::SQL Private

Inherits:
Normalizer
  • Object
show all
Defined in:
lib/skylight/core/normalizers/sql.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.

Normalizer for SQL requests

Constant Summary collapse

CAT =

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.

"db.sql.query".freeze

Instance Attribute Summary

Attributes inherited from Normalizer

#config

Instance Method Summary collapse

Methods inherited from Normalizer

#initialize, #normalize_after, register

Constructor Details

This class inherits a constructor from Skylight::Core::Normalizers::Normalizer

Instance Method Details

#normalize(trace, name, payload) ⇒ Array

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.

Parameters:

  • trace (Skylight::Messages::Trace::Builder)

    ignored, only present to match API

  • name (String)

    ignored, only present to match API

  • payload (Hash)

Options Hash (payload):

  • [:name] (String)

    The SQL operation

  • [:binds] (Hash)

    The bound parameters

Returns:

  • (Array)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/skylight/core/normalizers/sql.rb', line 15

def normalize(trace, name, payload)
  case payload[:name]
  when "SCHEMA".freeze, "CACHE".freeze
    return :skip
  else
    name  = CAT
    title = payload[:name] || "SQL".freeze
  end

  binds = payload[:binds]

  if binds && !binds.empty?
    binds = binds.map { |_col, val| val.inspect }
  end

  begin
    extracted_title, sql = extract_binds(trace.instrumenter, payload, binds)
    [name, extracted_title || title, sql]
  rescue => e
    config.logger.error "Failed to extract binds in SQL; sql=#{payload[:sql].inspect}; exception=#{e.inspect}"
    [name, title, nil]
  end
end