From fa151dc8478fe22aa8f16f0ba7c6f7c15f6f89b9 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Sat, 18 Jul 2020 17:18:09 +0200 Subject: [PATCH] Record exception class name If an exception happens during instrumentation with ActiveSupport the payload will have a key :exception. Report the exception class name as tag. Will make it possible to measure "potential" problems. Potential as we don't know if the exception will be handled higher up in the call chain. --- CHANGELOG.md | 1 + README.md | 7 ++++++- lib/influxdb/rails/middleware/request_subscriber.rb | 1 + spec/requests/action_controller_metrics_spec.rb | 5 +++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 646297e..b68f0f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ For the full commit log, [see here](https://github.com/influxdata/influxdb-rails - Implement `perform_start.active_job` subscriber (https://guides.rubyonrails.org/active_support_instrumentation.html#perform-start-active-job) - Implement `perform.active_job` subscriber (https://guides.rubyonrails.org/active_support_instrumentation.html#perform-active-job) - Implement block instrumentation `InfluxDB::Rails.instrument do; 1 + 1; end` +- Record unhandled exceptions as tags for process_action.action_controller ## v1.0.0, released 2019-10-23 The Final release, no code changes. diff --git a/README.md b/README.md index ca59587..654041d 100644 --- a/README.md +++ b/README.md @@ -71,10 +71,15 @@ Reported tags: method: "PostsController#index", http_method: "GET", format: "html", - status: "200" + status: ["200", ""] + exception: ["", "ArgumentError"] } ``` +*Note*: If an exception happens during that particular instrumentation the +`status` will be blank and the tag `exception` will contain the name of the +exception class. + ### Action View Reported ActiveSupport instrumentation hooks: diff --git a/lib/influxdb/rails/middleware/request_subscriber.rb b/lib/influxdb/rails/middleware/request_subscriber.rb index fa1f635..6da467f 100644 --- a/lib/influxdb/rails/middleware/request_subscriber.rb +++ b/lib/influxdb/rails/middleware/request_subscriber.rb @@ -19,6 +19,7 @@ def tags(payload) status: payload[:status], format: payload[:format], http_method: payload[:method], + exception: payload[:exception]&.first, } end diff --git a/spec/requests/action_controller_metrics_spec.rb b/spec/requests/action_controller_metrics_spec.rb index 953d2ad..84031a9 100644 --- a/spec/requests/action_controller_metrics_spec.rb +++ b/spec/requests/action_controller_metrics_spec.rb @@ -74,8 +74,9 @@ expect_metric( tags: a_hash_including( - method: "ExceptionsController#index", - hook: "process_action" + method: "ExceptionsController#index", + hook: "process_action", + exception: "ZeroDivisionError" ) ) end