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.

Options Hash (payload):

  • [:name] (String)

    The SQL operation

  • [:binds] (Hash)

    The bound parameters



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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
    if defined?(Skylight::SqlLexError) && e.is_a?(Skylight::SqlLexError)
      if config[:log_sql_parse_errors]
        config.logger.error "[#{e.formatted_code}] Failed to extract binds from SQL query. " \
                            "It's likely that this query uses more advanced syntax than we currently support. " \
                            "sql=#{payload[:sql].inspect}"
      end
    else
      config.logger.error "Failed to extract binds in SQL; sql=#{payload[:sql].inspect}; exception=#{e.inspect}"
    end

    [ name, title, nil ]
  end
end