diff --git a/CHANGELOG b/CHANGELOG
index e2fa16e4eee8843359961f1ff41ef963ebdc09af..daa7ed2a1e5a207517f400f8228e7add74084473 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -27,6 +27,7 @@ v 8.10.0 (unreleased)
   - Better caching of git calls on ProjectsController#show.
   - Add API endpoint for a group issues !4520 (mahcsig)
   - Add Bugzilla integration !4930 (iamtjg)
+  - Metrics for Rouge::Plugins::Redcarpet and Rouge::Formatters::HTMLGitlab
   - Allow [ci skip] to be in any case and allow [skip ci]. !4785 (simon_w)
   - Add basic system information like memory and disk usage to the admin panel
 
diff --git a/config/initializers/metrics.rb b/config/initializers/metrics.rb
index 75f89d524e71543b73c24883dec1b4ed9be14e74..44601f2b2bde5a428daac152a6ae2f0f23101288 100644
--- a/config/initializers/metrics.rb
+++ b/config/initializers/metrics.rb
@@ -132,6 +132,9 @@ if Gitlab::Metrics.enabled?
     config.instrument_instance_methods(API::Helpers)
 
     config.instrument_instance_methods(RepositoryCheck::SingleRepositoryWorker)
+
+    config.instrument_instance_methods(Rouge::Plugins::Redcarpet)
+    config.instrument_instance_methods(Rouge::Formatters::HTMLGitlab)
   end
 
   GC::Profiler.enable
diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb
index 62a79c62e20ef90183a8e2f3d7ee8d3ea2ef17d0..536b478979f78ad64babe872bf3f1baf18d4f199 100644
--- a/lib/banzai/filter/syntax_highlight_filter.rb
+++ b/lib/banzai/filter/syntax_highlight_filter.rb
@@ -27,12 +27,17 @@ module Banzai
           highlighted = "<pre>#{code}</pre>"
         end
 
-        # Replace the parent `pre` element with the entire highlighted block
-        node.parent.replace(highlighted)
+        # Extracted to a method to measure it
+        replace_parent_pre_element(node, highlighted)
       end
 
       private
 
+      def replace_parent_pre_element(node, highlighted)
+        # Replace the parent `pre` element with the entire highlighted block
+        node.parent.replace(highlighted)
+      end
+
       # Override Rouge::Plugins::Redcarpet#rouge_formatter
       def rouge_formatter(lexer)
         Rouge::Formatters::HTMLGitlab.new(