Skip to content

Conversation

@zzak
Copy link

@zzak zzak commented Oct 16, 2025

See: rails/rails@7d12071

This change will land in Rails 8.1.

@orehmane
Copy link

Started running into this one, would be great to get it merged.

@jasonligg
Copy link

Seeing this as well. 🙏

@alexdeng-mp
Copy link

We're seeing this too. Would be awesome to get this in soon

@robertino
Copy link

robertino commented Oct 23, 2025

bumping again, this is causing errors now:
Could not log "sql.active_record" event. NoMethodError: undefined method 'sql_runtime' for module ActiveRecord::RuntimeRegistry on Rails 8.1.0 which was released yesterday

@orehmane
Copy link

I created a monkeypatch to fix this in the meantime, based on @rubyroob's excellent work in #249.

Stick this in a file in config/initializers and it should clear up issues until the gem is updated.

# frozen_string_literal: true

LAST_TESTED_VERSION = '4.18.0'

require 'rails_semantic_logger/version'

unless RailsSemanticLogger::VERSION == LAST_TESTED_VERSION
  raise "rails_semantic_logger is version #{RailsSemanticLogger::VERSION} but the monkey patch was last tested on " \
        "#{LAST_TESTED_VERSION} - manually check if it can find the sql_runtime module."
end

module RailsSemanticLogger
  module ActiveRecord
    class LogSubscriber < ActiveSupport::LogSubscriber
      def self.runtime=(value)
        if ::ActiveRecord::RuntimeRegistry.respond_to?(:stats)
          ::ActiveRecord::RuntimeRegistry.stats.sql_runtime = value
        else
          ::ActiveRecord::RuntimeRegistry.sql_runtime = value
        end
      end

      def self.runtime
        if ::ActiveRecord::RuntimeRegistry.respond_to?(:stats)
          ::ActiveRecord::RuntimeRegistry.stats.sql_runtime ||= 0
        else
          ::ActiveRecord::RuntimeRegistry.sql_runtime ||= 0
        end
      end
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants