Sha256: dce62a06015e95fb9b38175ed935fcf1ef8b1b8eef850baa2caa967308045760

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

# (c) Copyright IBM Corp. 2024

module Instana
  module Instrumentation
    module Sequel
      IGNORED_SQL = %w[BEGIN COMMIT SET].freeze
      VERSION_SELECT_STATEMENT = "SELECT VERSION()".freeze
      SANITIZE_REGEXP = /('[\s\S][^']*'|\d*\.\d+|\d+|NULL)/i

      def log_connection_yield(sql, conn, *args)
        call_payload = {
          sequel: {
            adapter: opts[:adapter],
            host: opts[:host],
            username: opts[:user],
            db: opts[:database],
            sql: maybe_sanitize(sql)
          }
        }
        maybe_trace(call_payload) { super(sql, conn, *args) }
      end

      private

      def maybe_sanitize(sql)
        ::Instana.config[:sanitize_sql] ? sql.gsub(SANITIZE_REGEXP, '?') : sql
      end

      def maybe_trace(call_payload, &blk)
        if ::Instana.tracer.tracing? && !ignored?(call_payload)
          ::Instana.tracer.trace(:sequel, call_payload, &blk)
        else
          yield
        end
      end

      def ignored?(call_payload)
        IGNORED_SQL.any? { |s| call_payload[:sequel][:sql].upcase.start_with?(s) } || call_payload[:sequel][:sql].upcase == VERSION_SELECT_STATEMENT
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
instana-1.217.1 lib/instana/instrumentation/sequel.rb
instana-1.217.0 lib/instana/instrumentation/sequel.rb