8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/vizsla/patches.rb', line 8
def patch_postgres(&block)
@postgres_event_handler = block
::PG::Connection.class_eval do
alias_method :exec_without_profiling, :exec
def exec(*args, &blk)
return exec_without_profiling(*args, &blk)
start_time = Time.now
result = exec_without_profiling(*args, &blk)
end_time = Time.now
event_data = [
'sql.postgres_exec',
start_time,
end_time,
{
sql: args[0]
}
]
::Vizsla::Patches.handle_event :postgres, event_data
result
end
end
end
|