Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.rubocop_todo.yml linguist-generated
25 changes: 25 additions & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: RuboCop

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
Comment thread
tagliala marked this conversation as resolved.

permissions:
contents: read

jobs:
rubocop:
name: RuboCop
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '4.0'
bundler-cache: true
- name: RuboCop
run: bundle exec rubocop -f github
88 changes: 88 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Ruby specs

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
Comment thread
tagliala marked this conversation as resolved.

permissions:
contents: read

jobs:
test:
name: Ruby specs
runs-on: ubuntu-latest

strategy:
matrix:
ruby-version: ['3.0', '3.1', '3.2', '3.3', '3.4', '4.0']
gemfile: [rails_7.0, rails_7.1, rails_7.2, rails_8.0, rails_8.1]
channel: [stable]

include:
- ruby-version: '3.3'
gemfile: rails_edge
channel: experimental

- ruby-version: '3.4'
gemfile: rails_edge
channel: experimental

- ruby-version: '4.0'
gemfile: rails_edge
channel: experimental

- ruby-version: 'head'
gemfile: rails_7.1
channel: experimental
- ruby-version: 'head'
gemfile: rails_7.2
channel: experimental
- ruby-version: 'head'
gemfile: rails_8.0
channel: experimental
- ruby-version: 'head'
gemfile: rails_8.1
channel: experimental
- ruby-version: 'head'
gemfile: rails_edge
channel: experimental

exclude:
- ruby-version: '3.0'
gemfile: rails_7.2
- ruby-version: '3.0'
gemfile: rails_8.0
- ruby-version: '3.0'
gemfile: rails_8.1

- ruby-version: '3.1'
gemfile: rails_8.0
- ruby-version: '3.1'
gemfile: rails_8.1

- ruby-version: '3.4'
gemfile: rails_7.0

- ruby-version: '4.0'
gemfile: rails_7.0
- ruby-version: '4.0'
gemfile: rails_7.1
- ruby-version: '4.0'
gemfile: rails_7.2

env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile

continue-on-error: ${{ matrix.channel != 'stable' }}

steps:
- uses: actions/checkout@v6
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Run specs
run: bundle exec rspec
34 changes: 20 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.bundle
*.so
*.o
*.a
mkmf.log
# See https://github.com/weppos/gitignore/blob/weppos/Ruby.gitignore
Gemfile.lock

coverage
rdoc
tmp

# Bundler
.bundle
pkg

# YARD artifacts
.yardoc
_yardoc
doc/

gemfiles/*.lock
bin/test

spec/examples.txt
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--require spec_helper
--color
26 changes: 26 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
inherit_from: .rubocop_todo.yml

plugins:
- rubocop-packaging
- rubocop-performance
- rubocop-rake
- rubocop-rspec

AllCops:
TargetRubyVersion: 3.0
NewCops: enable
Exclude:
- .git/**/*
- .github/**/*
- bin/**/*
- coverage/**/*
- doc/**/*
- gemfiles/*
- tmp/**/*
- vendor/**/*

RSpec/ExampleLength:
Max: 10

RSpec/MultipleExpectations:
Max: 5
34 changes: 34 additions & 0 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

appraise 'rails-7.0' do
gem 'rails', '~> 7.0.0'
end

appraise 'rails-7.1' do
gem 'rails', '~> 7.1.0'
end

appraise 'rails-7.2' do
gem 'rails', '~> 7.2.0'
end

appraise 'rails-8.0' do
gem 'rails', '~> 8.0.0'
end

appraise 'rails-8.1' do
gem 'rails', '~> 8.1.0'
end

appraise 'rails-edge' do
gem 'rails', git: 'https://github.com/rails/rails.git', branch: 'main'
end
18 changes: 17 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in instrumenter.gemspec
git_source(:ifad) { |repo| "git@github.com:ifad/#{repo}.git" }

gem 'appraisal2'
gem 'byebug'
gem 'rails'
gem 'rake'
gem 'rspec'
gem 'simplecov'

gem 'rubocop', require: false
gem 'rubocop-packaging', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rake', require: false
gem 'rubocop-rspec', require: false

gemspec
48 changes: 38 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Instrumenter

[![RuboCop](https://github.com/ifad/instrumenter/actions/workflows/rubocop.yml/badge.svg)](https://github.com/ifad/instrumenter/actions/workflows/rubocop.yml)
[![Ruby](https://github.com/ifad/instrumenter/actions/workflows/ruby.yml/badge.svg)](https://github.com/ifad/instrumenter/actions/workflows/ruby.yml)

Quick hack to add ActiveSupport Instrumentations to a class.

## Installation
Expand All @@ -21,25 +24,50 @@ Or install it yourself as:
## Usage

```ruby
module Awesome
module Client

Instrumenter.instrument self, :awesome
module Awesome
module Client
Instrumenter.instrument self, :awesome

def send_request
instrument 'request', method: 'something', url: 'something else', params: {foo: :bar} do
# Actual HTTP Request send
#
end
def send_request
instrument 'request', method: 'something', url: 'something else', params: {foo: :bar} do
# Actual HTTP Request send
end

end
end
end
```

You'll get messages with timings in your log file, and aggregate timings at
the bottom of log stanzas generated by controller actions.

## Testing

### Appraisal

Gem dependency versions are managed by [Appraisal](https://github.com/thoughtbot/appraisal).

After any change to `Appraisals`, regenerate the appraisal gemfiles by running:

```sh
bundle exec appraisal generate
```

To install dependencies for all appraisal gemfiles, run:

```sh
bundle exec appraisal install
```

To run specs against a specific Rails version, run:

```sh
bundle exec appraisal rails-7.2 rspec
```

### Testing matrix

GitHub Actions runs the Appraisal matrix declared in `.github/workflows/ruby.yml`, and RuboCop runs in `.github/workflows/rubocop.yml`.

## Contributing

1. Fork it ( https://github.com/ifad/instrumenter/fork )
Expand Down
8 changes: 7 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
require "bundler/gem_tasks"
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:test)

task default: :test
17 changes: 17 additions & 0 deletions gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file was generated by Appraisal2

source "https://rubygems.org"

gem "appraisal2"
gem "byebug"
gem "rails", "~> 7.0.0"
gem "rake"
gem "rspec"
gem "simplecov"
gem "rubocop", :require => false
gem "rubocop-packaging", :require => false
gem "rubocop-performance", :require => false
gem "rubocop-rake", :require => false
gem "rubocop-rspec", :require => false

gemspec :path => "../"
17 changes: 17 additions & 0 deletions gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file was generated by Appraisal2

source "https://rubygems.org"

gem "appraisal2"
gem "byebug"
gem "rails", "~> 7.1.0"
gem "rake"
gem "rspec"
gem "simplecov"
gem "rubocop", :require => false
gem "rubocop-packaging", :require => false
gem "rubocop-performance", :require => false
gem "rubocop-rake", :require => false
gem "rubocop-rspec", :require => false

gemspec :path => "../"
17 changes: 17 additions & 0 deletions gemfiles/rails_7.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file was generated by Appraisal2

source "https://rubygems.org"

gem "appraisal2"
gem "byebug"
gem "rails", "~> 7.2.0"
gem "rake"
gem "rspec"
gem "simplecov"
gem "rubocop", :require => false
gem "rubocop-packaging", :require => false
gem "rubocop-performance", :require => false
gem "rubocop-rake", :require => false
gem "rubocop-rspec", :require => false

gemspec :path => "../"
Loading