module TraceView::Inst::Sequel
The common (shared) methods used by the TraceView
Sequel
instrumentation across multiple modules/classes.
Public Instance Methods
exec_with_traceview(method, sql, opts = ::Sequel::OPTS, &block)
click to toggle source
This method wraps and routes the call to the specified original method call
# File lib/traceview/inst/sequel.rb, line 70 def exec_with_traceview(method, sql, opts = ::Sequel::OPTS, &block) kvs = extract_trace_details(sql, opts) TraceView::API.log_entry(:sequel, kvs) send(method, sql, opts, &block) rescue => e TraceView::API.log_exception(:sequel, e) raise e ensure TraceView::API.log_exit(:sequel) end
extract_trace_details(sql, opts)
click to toggle source
Given SQL and the options hash, this method extracts the interesting bits for reporting to the TraceView
dashboard.
# File lib/traceview/inst/sequel.rb, line 19 def extract_trace_details(sql, opts) kvs = {} if !sql.is_a?(String) kvs[:IsPreparedStatement] = true end if ::Sequel::VERSION > '4.36.0' && !sql.is_a?(String) # In 4.37.0, sql was converted to a prepared statement object sql = sql.prepared_sql unless sql.is_a?(Symbol) end if TraceView::Config[:sanitize_sql] # Sanitize SQL and don't report binds if sql.is_a?(Symbol) kvs[:Query] = sql else kvs[:Query] = TraceView::Util.sanitize_sql(sql) end else # Report raw SQL and any binds if they exist kvs[:Query] = sql.to_s kvs[:QueryArgs] = opts[:arguments] if opts.is_a?(Hash) && opts.key?(:arguments) end kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:sequel][:collect_backtraces] if ::Sequel::VERSION < '3.41.0' && !(self.class.to_s =~ /Dataset$/) db_opts = @opts elsif @pool db_opts = @pool.db.opts else db_opts = @db.opts end kvs[:Database] = db_opts[:database] kvs[:RemoteHost] = db_opts[:host] kvs[:RemotePort] = db_opts[:port] if db_opts.key?(:port) kvs[:Flavor] = db_opts[:adapter] rescue => e TraceView.logger.debug "[traceview/debug Error capturing Sequel KVs: #{e.message}" if TraceView::Config[:verbose] ensure return kvs end