Skip to content

Configurable controller and action default tags #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions lib/yabeda/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
11 changes: 11 additions & 0 deletions lib/yabeda/rails/action_controller_tags.rb
Original file line number Diff line number Diff line change
@@ -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