Repository: discourse/prometheus_exporter (Ruby)

Issue:
 "super:  no superclass method `async_exec'" error in v2.0.4.
After upgrading to 2.0.4, the following error occurred when starting Ruby on Rails.

```
ERROR -- : super: no superclass method `async_exec' for #<PG::Connection:0x00007ff19d120b38 host=example.com port=5432 user=sample>
Did you mean?  sync_exec
               async_reset (NoMethodError)
/vendor/bundle/ruby/3.1.0/gems/prometheus_exporter-2.0.4/lib/prometheus_exporter/instrumentation/method_profiler.rb:63:in `async_exec'
```

We choose `:prepend` for the style of method patching.
https://github.com/discourse/prometheus_exporter#choosing-the-style-of-method-patching

I think that it is the effect of changing `prepend_instument` to `klass` in the following correspondence.
https://github.com/discourse/prometheus_exporter/pull/250/files#diff-cb9a335ee1d17a77e55d1bc374c4c76ebbf05e6b84de4ce41f1fbc560bda41b7R63




Discussion:
Hi maintainers,

Checked the code and wrote a patch below, I thought it would fix this
https://github.com/discourse/prometheus_exporter/pull/254 
Could you please take a time to check this up?

I and my colleagues are always helped by prometheus_exporter gem. Thank you.
thanks heaps for the PR and bug report, just working through the test cases atm, will try to do a release tomorrow once sorted 





Patch:
diff --git a/lib/prometheus_exporter/instrumentation/method_profiler.rb b/lib/prometheus_exporter/instrumentation/method_profiler.rb
index 2dc736cb..f1658df4 100644
--- a/lib/prometheus_exporter/instrumentation/method_profiler.rb
+++ b/lib/prometheus_exporter/instrumentation/method_profiler.rb
@@ -64,9 +64,9 @@ def #{method_name}(*args, &blk)
   end
 
   def self.patch_using_prepend(klass, methods, name)
-    prepend_instument = Module.new
-    define_methods_on_module(klass, methods, name)
-    klass.prepend(prepend_instument)
+    prepend_instrument = Module.new
+    define_methods_on_module(prepend_instrument, methods, name)
+    klass.prepend(prepend_instrument)
   end
 
   def self.patch_using_alias_method(klass, methods, name)


Test patch:
diff --git a/test/instrumentation/method_profiler_test.rb b/test/instrumentation/method_profiler_test.rb
index 262ef467..64026b24 100644
--- a/test/instrumentation/method_profiler_test.rb
+++ b/test/instrumentation/method_profiler_test.rb
@@ -16,10 +16,8 @@ def some_method
     end
   end
 
-  def setup
-    PrometheusExporter::Instrumentation::MethodProfiler.patch SomeClassPatchedUsingAliasMethod, [:some_method], :test, instrument: :alias_method
-    PrometheusExporter::Instrumentation::MethodProfiler.patch SomeClassPatchedUsingPrepend, [:some_method], :test, instrument: :prepend
-  end
+  PrometheusExporter::Instrumentation::MethodProfiler.patch SomeClassPatchedUsingAliasMethod, [:some_method], :test, instrument: :alias_method
+  PrometheusExporter::Instrumentation::MethodProfiler.patch SomeClassPatchedUsingPrepend, [:some_method], :test, instrument: :prepend
 
   def test_alias_method_source_location
     file, line = SomeClassPatchedUsingAliasMethod.instance_method(:some_method).source_location
@@ -27,9 +25,17 @@ def test_alias_method_source_location
     assert_equal 'def #{method_name}(*args, &blk)', source
   end
 
+  def test_alias_method_preserves_behavior
+    assert_equal 'Hello, world', SomeClassPatchedUsingAliasMethod.new.some_method
+  end
+
   def test_prepend_source_location
     file, line = SomeClassPatchedUsingPrepend.instance_method(:some_method).source_location
     source = File.read(file).lines[line - 1].strip
     assert_equal 'def #{method_name}(*args, &blk)', source
   end
+
+  def test_prepend_preserves_behavior
+    assert_equal 'Hello, world', SomeClassPatchedUsingPrepend.new.some_method
+  end
 end