Skip to content
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

Allow defining default_tags only for rails group #30

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
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
Loading