diff --git a/README.md b/README.md index f373149..5addbf6 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,16 @@ end ``` `append_info_to_payload` is a method from [ActionController::Instrumentation](https://api.rubyonrails.org/classes/ActionController/Instrumentation.html#method-i-append_info_to_payload) +## Default tags: controller/action + +``` +Yabeda::Rails.enable_controller_action_default_tags = true +``` + +Other metrics that are generated while handing a request will include a tag for the controller and the action that we being handled. This works well with other yabeda gems like [yabeda-http_requests](https://github.com/yabeda-rb/yabeda-http_requestshttps://github.com/yabeda-rb/yabeda-http_requests). + +Due to the potential for high cardinality, this feature is disabled by default. + ## Development diff --git a/lib/yabeda/rails.rb b/lib/yabeda/rails.rb index bfca67a..47dfe36 100644 --- a/lib/yabeda/rails.rb +++ b/lib/yabeda/rails.rb @@ -21,10 +21,19 @@ def on_controller_action(&block) controller_handlers << block end + attr_accessor :enable_controller_action_default_tags + # Declare metrics and install event handlers for collecting themya # rubocop: disable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize def install! Yabeda.configure do + if enable_controller_action_default_tags + ::ActionController::Metal.prepend(::Yabeda::Rails::ActionControllerTags) + + default_tags :controller, "" + default_tags :action, "" + end + group :rails counter :requests_total, comment: "A counter of the total number of HTTP requests rails processed.", diff --git a/lib/yabeda/rails/action_controller_tags.rb b/lib/yabeda/rails/action_controller_tags.rb new file mode 100644 index 0000000..4554a4f --- /dev/null +++ b/lib/yabeda/rails/action_controller_tags.rb @@ -0,0 +1,11 @@ +module Yabeda + module Rails + module ActionControllerDefaultTags + def process_action(*args) + Yabeda.with_tags(controller: controller_name, action: action_name) do + super + end + end + end + end +end