Class: Skylight::Normalizers::SQL Private

Inherits:
Normalizer show all
Defined in:
lib/skylight/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"

Instance Attribute Summary

Attributes inherited from Normalizer

#config

Instance Method Summary collapse

Methods inherited from Normalizer

#initialize, #normalize_after, #normalize_with_meta, register

Methods included from Util::Logging

#config_for_logging, #debug, #error, #fmt, #info, #log, #log_context, #raise_on_error?, #t, #trace, #trace?, #warn

Constructor Details

This class inherits a constructor from Skylight::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)


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

def normalize(_trace, _name, payload)
  return :skip if payload[:name] == "SCHEMA" || payload[:name] == "CACHE"

  title = payload[:name] || "SQL"

  # We can only handle UTF-8 encoded strings.
  # (Construction method here avoids extra allocations)
  sql = String.new.concat("<sk-sql>", payload[:sql], "</sk-sql>").force_encoding(Encoding::UTF_8)

  unless sql.valid_encoding?
    if config[:log_sql_parse_errors]
      config.logger.error "[#{Skylight::SqlLexError.formatted_code}] Unable to extract binds from non-UTF-8 " \
                            "query. " \
                            "encoding=#{payload[:sql].encoding.name} " \
                            "sql=#{payload[:sql].inspect} "
    end

    sql = nil
  end

  [CAT, title, sql]
end