Modernize instrumenter#1
Merged
Merged
Conversation
93b7902 to
d0021e7
Compare
d0021e7 to
25f91e4
Compare
There was a problem hiding this comment.
Pull request overview
This PR modernizes the instrumenter gem by adding CI/linting, introducing an Appraisal-based Rails version test matrix, and refactoring the core instrumentation implementation with a new RSpec suite.
Changes:
- Refactors
Instrumenterinternals (newSubscriberBase, updatedMaker, updated logging/runtime behavior). - Adds RSpec test suite and test helpers, plus a default
raketest task. - Adds RuboCop configuration and GitHub Actions workflows, plus Appraisal gemfiles/matrix documentation.
Reviewed changes
Copilot reviewed 24 out of 25 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
lib/instrumenter.rb |
Major refactor of instrumentation/log subscriber + Railtie/controller runtime generation. |
lib/version.rb |
Removes old version constant location. |
lib/instrumenter/version.rb |
Adds new version file and bumps version to 0.0.2. |
instrumenter.gemspec |
Modernizes gemspec, adds activesupport dependency and Ruby requirement, changes packaged file list. |
spec/spec_helper.rb |
Adds RSpec + optional SimpleCov setup and loads Rails/instrumenter for specs. |
spec/helpers.rb |
Adds shared spec helpers and thread-local runtime cleanup. |
spec/instrumenter_spec.rb |
Adds specs for Instrumenter::VERSION and .instrument behavior. |
spec/instrumenter/maker_spec.rb |
Adds specs covering generated subscriber/controller runtime/railtie behavior. |
Rakefile |
Adds RSpec rake task and sets default task to run tests. |
README.md |
Adds CI badges and documents Appraisal/testing matrix usage. |
Gemfile |
Adds dev dependencies (rspec, rubocop, appraisal2, rails, etc.). |
Appraisals |
Declares Rails version appraisal matrix (7.0–8.1 + edge). |
gemfiles/rails_7.0.gemfile |
Appraisal-generated Rails 7.0 gemfile. |
gemfiles/rails_7.1.gemfile |
Appraisal-generated Rails 7.1 gemfile. |
gemfiles/rails_7.2.gemfile |
Appraisal-generated Rails 7.2 gemfile. |
gemfiles/rails_8.0.gemfile |
Appraisal-generated Rails 8.0 gemfile. |
gemfiles/rails_8.1.gemfile |
Appraisal-generated Rails 8.1 gemfile. |
gemfiles/rails_edge.gemfile |
Appraisal-generated Rails edge gemfile. |
.rubocop.yml |
Enables RuboCop plugins and sets project linting rules. |
.rubocop_todo.yml |
Adds auto-generated RuboCop todo. |
.rspec |
Configures RSpec to always require spec_helper. |
.gitignore |
Updates ignored files (coverage/tmp/pkg, appraisal locks, etc.). |
.gitattributes |
Marks .rubocop_todo.yml as linguist-generated. |
.github/workflows/ruby.yml |
Adds GitHub Actions job to run specs across Ruby/Rails matrix. |
.github/workflows/rubocop.yml |
Adds GitHub Actions job to run RuboCop. |
Comments suppressed due to low confidence (2)
lib/instrumenter.rb:60
- Default argument
prefix.to_s.camelize.constantizerelies on ActiveSupport inflections (String#camelize/#constantize), but this file only requiresactive_support/notifications/log_subscriber, which may not load those core extensions in non-Rails usage. Consider requiring the needed inflector/core_ext explicitly (or usingActiveSupport::Inflector.camelize/constantize) to avoidNoMethodErrorwhen Rails isn't loaded.
def self.instrument(target, prefix, klass = prefix.to_s.camelize.constantize)
target.instance_eval do
define_method :instrument do |action, payload, &block|
ActiveSupport::Notifications.instrument("#{action}.#{prefix}", payload, &block)
end
lib/instrumenter.rb:80
define!can calldefine_railtie!wheneverRailsis defined, even ifActionController::Baseisn't (so@runtimestaysnil). In that scenario (e.g., onlyrailtiesloaded), the initializer will later executeinclude runtimewithruntime == nil, raising aTypeError. Consider gating railtie generation ondefined?(::Rails::Railtie)and on@runtimebeing present (or make the initializer conditional) so partial-Rails environments don't break.
def define!
define_log_subscriber!
define_controller_runtime! if defined?(ActionController::Base)
define_railtie! if defined?(Rails)
end
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f659d41 to
b23e0e9
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 24 out of 25 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
lib/instrumenter.rb:16
instrumentdefaultsklassviaprefix.to_s.camelize.constantize, but this file only requiresactive_support. In a non-Rails environment,String#camelize/#constantizeare not guaranteed to be loaded, which can causeNoMethodErrorat call time. Consider requiringactive_support/core_ext/string/inflections(or switching toActiveSupport::Inflector.camelize/constantizeto avoid relying on core extensions).
require 'active_support'
require 'active_support/notifications'
require 'active_support/log_subscriber'
require_relative 'instrumenter/version'
# Provides ActiveSupport-based instrumentation helpers for target classes.
module Instrumenter
LOG_MESSAGE_FORMAT = ' %<name>s: %<method>s %<url>s (%<duration>.1fms) - cache %<cache>s'
def self.instrument(target, prefix, klass = prefix.to_s.camelize.constantize)
target.instance_eval do
define_method :instrument do |action, payload, &block|
ActiveSupport::Notifications.instrument("#{action}.#{prefix}", payload, &block)
d35bcb4 to
616178e
Compare
616178e to
f8e82fb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.