Module: OpenTelemetry::Instrumentation::Trilogy::Patches::Client

Defined in:
lib/opentelemetry/instrumentation/trilogy/patches/client.rb

Overview

Module to prepend to Trilogy for instrumentation

Constant Summary collapse

QUERY_NAMES =

rubocop:disable Metrics/ModuleLength

[
  'set names',
  'select',
  'insert',
  'update',
  'delete',
  'begin',
  'commit',
  'rollback',
  'savepoint',
  'release savepoint',
  'explain',
  'drop database',
  'drop table',
  'create database',
  'create table'
].freeze
QUERY_NAME_RE =
Regexp.new("^(#{QUERY_NAMES.join('|')})", Regexp::IGNORECASE)
COMPONENTS_REGEX_MAP =
{
  single_quotes: /'(?:[^']|'')*?(?:\\'.*|'(?!'))/,
  double_quotes: /"(?:[^"]|"")*?(?:\\".*|"(?!"))/,
  numeric_literals: /-?\b(?:[0-9]+\.)?[0-9]+([eE][+-]?[0-9]+)?\b/,
  boolean_literals: /\b(?:true|false|null)\b/i,
  hexadecimal_literals: /0x[0-9a-fA-F]+/,
  comments: /(?:#|--).*?(?=\r|\n|$)/i,
  multi_line_comments: %r{\/\*(?:[^\/]|\/[^*])*?(?:\*\/|\/\*.*)}
}.freeze
MYSQL_COMPONENTS =
%i[
  single_quotes
  double_quotes
  numeric_literals
  boolean_literals
  hexadecimal_literals
  comments
  multi_line_comments
].freeze
FULL_SQL_REGEXP =
Regexp.union(MYSQL_COMPONENTS.map { |component| COMPONENTS_REGEX_MAP[component] })

Instance Method Summary collapse

Instance Method Details

#initialize(args) ⇒ Object



51
52
53
54
# File 'lib/opentelemetry/instrumentation/trilogy/patches/client.rb', line 51

def initialize(args)
  @_otel_net_peer_name = args[:host]
  super
end

#query(sql) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/opentelemetry/instrumentation/trilogy/patches/client.rb', line 56

def query(sql)
  tracer.in_span(
    database_span_name(sql),
    attributes: client_attributes(sql),
    kind: :client
  ) do
    super(sql)
  end
end