Skip to content

Commit

Permalink
Allow defining default_tags only for rails group
Browse files Browse the repository at this point in the history
  • Loading branch information
magec committed Aug 28, 2024
1 parent 3874b3c commit 40bef96
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/yabeda/rails/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions spec/support/rails_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions spec/yabeda/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 40bef96

Please sign in to comment.