diff --git a/lib/yabeda/rails/event.rb b/lib/yabeda/rails/event.rb index e991a3f..41d24e2 100644 --- a/lib/yabeda/rails/event.rb +++ b/lib/yabeda/rails/event.rb @@ -13,7 +13,7 @@ def labels format: format, method: method, } - labels.merge(payload.slice(*Yabeda.default_tags.keys - labels.keys)) + labels.merge(payload.slice(*(Yabeda.default_tags.keys + Yabeda.rails.default_tags.keys) - labels.keys)) end end diff --git a/spec/support/rails_app.rb b/spec/support/rails_app.rb index fb34ef3..0380cad 100644 --- a/spec/support/rails_app.rb +++ b/spec/support/rails_app.rb @@ -18,6 +18,12 @@ class TestApplication < Rails::Application end class HelloController < ActionController::API + def append_info_to_payload(payload) + super + payload[:custom_tag_from_rails] = "hello-world-from-rails" + payload[:custom_tag] = "hello-world" + end + def world render json: { hello: :world } end diff --git a/spec/yabeda/rails_spec.rb b/spec/yabeda/rails_spec.rb index 37be964..7b40179 100644 --- a/spec/yabeda/rails_spec.rb +++ b/spec/yabeda/rails_spec.rb @@ -46,4 +46,30 @@ def app .by(1) end end + + context "with default_tags set" do + before do + Yabeda.default_tag :custom_tag, nil + end + + it "increments counters for every request" do + expect { get "/hello/world" }.to \ + increment_yabeda_counter(Yabeda.rails.requests_total) + .with_tags(custom_tag: "hello-world") + .by(1) + end + end + + context "with ':rails' default_tags set" do + before do + Yabeda.default_tag :custom_tag_from_rails, nil, group: :rails + end + + it "increments counters for every request" do + expect { get "/hello/world" }.to \ + increment_yabeda_counter(Yabeda.rails.requests_total) + .with_tags(custom_tag_from_rails: "hello-world-from-rails") + .by(1) + end + end end