Skip to content

Commit 7dd1a29

Browse files
authored
Allow defining default_tags only for rails group (#30)
1 parent 1a30347 commit 7dd1a29

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

lib/yabeda/rails/event.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def labels
1313
format: format,
1414
method: method,
1515
}
16-
labels.merge(payload.slice(*Yabeda.default_tags.keys - labels.keys))
16+
labels.merge(payload.slice(*(Yabeda.default_tags.keys + Yabeda.rails.default_tags.keys) - labels.keys))
1717
end
1818
end
1919

spec/support/rails_app.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class TestApplication < Rails::Application
1818
end
1919

2020
class HelloController < ActionController::API
21+
def append_info_to_payload(payload)
22+
super
23+
payload[:custom_tag_from_rails] = "hello-world-from-rails"
24+
payload[:custom_tag] = "hello-world"
25+
end
26+
2127
def world
2228
render json: { hello: :world }
2329
end

spec/yabeda/rails_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,30 @@ def app
4646
.by(1)
4747
end
4848
end
49+
50+
context "with default_tags set" do
51+
before do
52+
Yabeda.default_tag :custom_tag, nil
53+
end
54+
55+
it "increments counters for every request" do
56+
expect { get "/hello/world" }.to \
57+
increment_yabeda_counter(Yabeda.rails.requests_total)
58+
.with_tags(custom_tag: "hello-world")
59+
.by(1)
60+
end
61+
end
62+
63+
context "with ':rails' default_tags set" do
64+
before do
65+
Yabeda.default_tag :custom_tag_from_rails, nil, group: :rails
66+
end
67+
68+
it "increments counters for every request" do
69+
expect { get "/hello/world" }.to \
70+
increment_yabeda_counter(Yabeda.rails.requests_total)
71+
.with_tags(custom_tag_from_rails: "hello-world-from-rails")
72+
.by(1)
73+
end
74+
end
4975
end

0 commit comments

Comments
 (0)