diff --git a/.rubocop.yml b/.rubocop.yml index d95f178..d6debf3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,7 +11,8 @@ AllCops: - 'vendor/bundle/**/*' DisplayCopNames: true StyleGuideCopsOnly: false - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.5 + NewCops: enable Layout/EmptyLinesAroundArguments: Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 1121bf8..490481d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ For the full commit log, [see here](https://github.com/influxdata/influxdb-rails/commits/one-stable). +## v1.0.3, released 2021-09-15 + +- In case of unhandled exceptions, set status in measurements like Rails.logger does +- Require Ruby 2.5 + ## v1.0.2, released 2021-04-13 Fix passing booleans to custom tags. diff --git a/influxdb-rails.gemspec b/influxdb-rails.gemspec index bd576a3..e651c49 100644 --- a/influxdb-rails.gemspec +++ b/influxdb-rails.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features|smoke)/}) spec.require_paths = ["lib"] - spec.required_ruby_version = ">= 2.4.0" + spec.required_ruby_version = ">= 2.5.0" spec.add_runtime_dependency "influxdb", "~> 0.6", ">= 0.6.4" spec.add_runtime_dependency "railties", ">= 5.0" diff --git a/lib/influxdb/rails/middleware/request_subscriber.rb b/lib/influxdb/rails/middleware/request_subscriber.rb index 8ab0ee9..41e5237 100644 --- a/lib/influxdb/rails/middleware/request_subscriber.rb +++ b/lib/influxdb/rails/middleware/request_subscriber.rb @@ -16,7 +16,7 @@ def tags { method: "#{payload[:controller]}##{payload[:action]}", hook: "process_action", - status: payload[:status], + status: status, format: payload[:format], http_method: payload[:method], exception: payload[:exception]&.first, @@ -38,6 +38,14 @@ def started configuration.client.time_precision ) end + + def status + if payload[:exception] && ::Rails::VERSION::MAJOR < 7 + ActionDispatch::ExceptionWrapper.status_code_for_exception(payload[:exception].first) + else + payload[:status] + end + end end end end diff --git a/lib/influxdb/rails/version.rb b/lib/influxdb/rails/version.rb index 1c4a33e..f8d9fa3 100644 --- a/lib/influxdb/rails/version.rb +++ b/lib/influxdb/rails/version.rb @@ -1,5 +1,5 @@ module InfluxDB module Rails - VERSION = "1.0.2".freeze + VERSION = "1.0.3".freeze end end diff --git a/spec/requests/action_controller_metrics_spec.rb b/spec/requests/action_controller_metrics_spec.rb index 15ac743..2820e66 100644 --- a/spec/requests/action_controller_metrics_spec.rb +++ b/spec/requests/action_controller_metrics_spec.rb @@ -89,7 +89,8 @@ tags: a_hash_including( method: "ExceptionsController#index", hook: "process_action", - exception: "ZeroDivisionError" + exception: "ActiveRecord::RecordNotFound", + status: 404 ) ) end diff --git a/spec/support/rails5/app.rb b/spec/support/rails5/app.rb index c900b98..f1b4cf2 100644 --- a/spec/support/rails5/app.rb +++ b/spec/support/rails5/app.rb @@ -76,7 +76,7 @@ def show class ExceptionsController < ApplicationController def index - 1 / 0 + raise ActiveRecord::RecordNotFound end end diff --git a/spec/support/rails6/app.rb b/spec/support/rails6/app.rb index c900b98..f1b4cf2 100644 --- a/spec/support/rails6/app.rb +++ b/spec/support/rails6/app.rb @@ -76,7 +76,7 @@ def show class ExceptionsController < ApplicationController def index - 1 / 0 + raise ActiveRecord::RecordNotFound end end