Skip to content

Commit 55a386c

Browse files
committed
Configurable controller and action default tags
1 parent 57d6b38 commit 55a386c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ end
7676
```
7777
`append_info_to_payload` is a method from [ActionController::Instrumentation](https://api.rubyonrails.org/classes/ActionController/Instrumentation.html#method-i-append_info_to_payload)
7878

79+
## Default tags: controller/action
80+
81+
```
82+
Yabeda::Rails.enable_controller_action_default_tags = true
83+
```
84+
85+
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).
86+
87+
Due to the potential for high cardinality, this feature is disabled by default.
88+
7989
8090
## Development
8191

lib/yabeda/rails.rb

+9
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@ def on_controller_action(&block)
2121
controller_handlers << block
2222
end
2323

24+
attr_accessor :enable_controller_action_default_tags
25+
2426
# Declare metrics and install event handlers for collecting themya
2527
# rubocop: disable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize
2628
def install!
2729
Yabeda.configure do
30+
if enable_controller_action_default_tags
31+
::ActionController::Metal.prepend(::Yabeda::Rails::ActionControllerTags)
32+
33+
default_tags :controller, ""
34+
default_tags :action, ""
35+
end
36+
2837
group :rails
2938

3039
counter :requests_total, comment: "A counter of the total number of HTTP requests rails processed.",
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Yabeda
2+
module Rails
3+
module ActionControllerDefaultTags
4+
def process_action(*args)
5+
Yabeda.with_tags(controller: controller_name, action: action_name) do
6+
super
7+
end
8+
end
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)