Add source location for MethodProfiler patches (#168)

Add source location for MethodProfiler patches (#168)

diff --git a/lib/prometheus_exporter/instrumentation/method_profiler.rb b/lib/prometheus_exporter/instrumentation/method_profiler.rb
index fb9b403..d483d22 100644
--- a/lib/prometheus_exporter/instrumentation/method_profiler.rb
+++ b/lib/prometheus_exporter/instrumentation/method_profiler.rb
@@ -5,6 +5,7 @@ module PrometheusExporter::Instrumentation; end
 
 class PrometheusExporter::Instrumentation::MethodProfiler
   def self.patch(klass, methods, name)
+    patch_source_line = __LINE__ + 3
     patches = methods.map do |method_name|
       <<~RUBY
       unless defined?(#{method_name}__mp_unpatched)
@@ -26,7 +27,7 @@ class PrometheusExporter::Instrumentation::MethodProfiler
       RUBY
     end.join("\n")
 
-    klass.class_eval patches
+    klass.class_eval patches, __FILE__, patch_source_line
   end
 
   def self.transfer
diff --git a/test/instrumentation/method_profiler_test.rb b/test/instrumentation/method_profiler_test.rb
new file mode 100644
index 0000000..309c3eb
--- /dev/null
+++ b/test/instrumentation/method_profiler_test.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'test_helper'
+require 'prometheus_exporter/instrumentation'
+
+class PrometheusInstrumentationMethodProfilerTest < Minitest::Test
+  class SomeClass
+    def some_method
+      "Hello, world"
+    end
+  end
+
+  def setup
+    PrometheusExporter::Instrumentation::MethodProfiler.patch SomeClass, [:some_method], :test
+  end
+
+  def test_source_location
+    file, line = SomeClass.instance_method(:some_method).source_location
+    source = File.read(file).lines[line - 1].strip
+
+    assert_equal 'def #{method_name}(*args, &blk)', source
+  end
+end

GitHub sha: cb0283d9

This commit appears in #168 which was merged by SamSaffron.