Module: NewRelic::Security::Instrumentation::PG::Connection

Included in:
Prepend
Defined in:
lib/newrelic_security/instrumentation-security/pg/chain.rb,
lib/newrelic_security/instrumentation-security/pg/prepend.rb,
lib/newrelic_security/instrumentation-security/pg/instrumentation.rb

Defined Under Namespace

Modules: Chain, Prepend

Instance Method Summary collapse

Instance Method Details

#async_exec_on_enter(*args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/newrelic_security/instrumentation-security/pg/instrumentation.rb', line 31

def async_exec_on_enter(*args)
  event = nil
  NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
  hash = {}
  hash[:sql] = args[0]
  hash[:parameters] = []
  event = NewRelic::Security::Agent::Control::Collector.collect(SQL_DB_COMMAND, [hash], POSTGRES) unless NewRelic::Security::Instrumentation::InstrumentationUtils.sql_filter_events?(hash[:sql])
rescue => exception
  NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
  yield
  return event
end

#async_exec_on_exit(event) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/newrelic_security/instrumentation-security/pg/instrumentation.rb', line 45

def async_exec_on_exit(event)
  NewRelic::Security::Agent.logger.debug "OnExit :  #{self.class}.#{__method__}"
  NewRelic::Security::Agent::Utils.create_exit_event(event)
rescue => exception
  NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
  yield
end

#exec_on_enter(sql) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/newrelic_security/instrumentation-security/pg/instrumentation.rb', line 8

def exec_on_enter(sql)
  event = nil
  NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
  hash = {}
  hash[:sql] = sql
  hash[:parameters] = []
  event = NewRelic::Security::Agent::Control::Collector.collect(SQL_DB_COMMAND, [hash], POSTGRES) unless NewRelic::Security::Instrumentation::InstrumentationUtils.sql_filter_events?(hash[:sql])
rescue => exception
  NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
  yield
  return event
end

#exec_on_exit(event) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/newrelic_security/instrumentation-security/pg/instrumentation.rb', line 22

def exec_on_exit(event)
  NewRelic::Security::Agent.logger.debug "OnExit :  #{self.class}.#{__method__}"
  NewRelic::Security::Agent::Utils.create_exit_event(event)
rescue => exception
  NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
  yield
end

#exec_prepared_on_enter(*args) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/newrelic_security/instrumentation-security/pg/instrumentation.rb', line 73

def exec_prepared_on_enter(*args)
  event = nil
  NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
  hash = {}
  hash[:sql] = NewRelic::Security::Agent::Control::HTTPContext.get_context.cache[args[0].to_s] if NewRelic::Security::Agent::Control::HTTPContext.get_context
  hash[:sql] = self.exec("select statement from pg_prepared_statements where name = '#{args[0]}'").getvalue(0,0) unless hash[:sql]
  hash[:parameters] = args[1].map(&:to_s)
  event = NewRelic::Security::Agent::Control::Collector.collect(SQL_DB_COMMAND, [hash], POSTGRES) unless NewRelic::Security::Instrumentation::InstrumentationUtils.sql_filter_events?(hash[:sql])
  NewRelic::Security::Agent::Control::HTTPContext.get_context.cache.delete(args[0].to_s) if NewRelic::Security::Agent::Control::HTTPContext.get_context
rescue => exception
  NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
  yield
  return event
end

#exec_prepared_on_exit(event) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/newrelic_security/instrumentation-security/pg/instrumentation.rb', line 89

def exec_prepared_on_exit(event)
  NewRelic::Security::Agent.logger.debug "OnExit :  #{self.class}.#{__method__}"
  NewRelic::Security::Agent::Utils.create_exit_event(event)
rescue => exception
  NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
  yield
end

#prepare_on_enter(*args) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/newrelic_security/instrumentation-security/pg/instrumentation.rb', line 54

def prepare_on_enter(*args)
  event = nil
  NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
  NewRelic::Security::Agent::Control::HTTPContext.get_context.cache[args[0].to_s] = args[1].to_s if NewRelic::Security::Agent::Control::HTTPContext.get_context
rescue => exception
  NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
  yield
  return event
end

#prepare_on_exit(event) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/newrelic_security/instrumentation-security/pg/instrumentation.rb', line 65

def prepare_on_exit(event)
  NewRelic::Security::Agent.logger.debug "OnExit :  #{self.class}.#{__method__}"
rescue => exception
  NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
  yield
end