FIX: implement exec_params instrumentation for PG gem

FIX: implement exec_params instrumentation for PG gem
From 5aa1d190ae85aaf955586adde6af527c5bbe3a9e Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Mon, 10 Dec 2018 13:14:24 +1100
Subject: [PATCH] FIX: implement exec_params instrumentation for PG gem


diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7dc7a66..ae66419 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
 # CHANGELOG
 
+## 1.0.1 2018-12-10
+
+- [FIX] add support for exec_params instrumentation in PG, this method as of PG 1.1.0 no longer
+ routes calls to exec / async_exec
+
 ## 1.0.0 2017-03-29
 
 - [BREAKING CHANGE] Ruby version 2.2.0 or later is required
diff --git a/lib/mini_profiler/version.rb b/lib/mini_profiler/version.rb
index a0916af..a230348 100644
--- a/lib/mini_profiler/version.rb
+++ b/lib/mini_profiler/version.rb
@@ -2,6 +2,6 @@
 
 module Rack
   class MiniProfiler
-    VERSION = '1.0.0'
+    VERSION = '1.0.1'
   end
 end
diff --git a/lib/patches/db/pg.rb b/lib/patches/db/pg.rb
index 480b087..802f092 100644
--- a/lib/patches/db/pg.rb
+++ b/lib/patches/db/pg.rb
@@ -35,6 +35,10 @@ class PG::Connection
   alias_method :send_query_prepared_without_profiling, :send_query_prepared
   alias_method :prepare_without_profiling, :prepare
 
+  if Gem::Version.new(PG::VERSION) >= Gem::Version.new("1.1.0")
+    alias_method:exec_params_without_profiling, :exec_params
+  end
+
   def prepare(*args,&blk)
     # we have no choice but to do this here,
     # if we do the check for profiling first, our cache may miss critical stuff
@@ -60,6 +64,21 @@ class PG::Connection
     result
   end
 
+
+  if Gem::Version.new(PG::VERSION) >= Gem::Version.new("1.1.0")
+    def exec_params(*args,&blk)
+      return exec_params_without_profiling(*args,&blk) unless SqlPatches.should_measure?
+
+      start        = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+      result       = exec_params_without_profiling(*args, &blk)
+      elapsed_time = SqlPatches.elapsed_time(start)
+      record       = ::Rack::MiniProfiler.record_sql(args[0], elapsed_time)
+      result.instance_variable_set("@miniprofiler_sql_id", record) if result
+
+      result
+    end
+  end
+
   def exec_prepared(*args,&blk)
     return exec_prepared_without_profiling(*args,&blk) unless SqlPatches.should_measure?

GitHub