Skip to content

Commit

Permalink
Clarify tags are merged in tags helpers (#1148)
Browse files Browse the repository at this point in the history
Document the tags helpers better.

Also add a test for the calling of the tags helper multiple times.

[skip changeset]
  • Loading branch information
tombruijn authored Jul 4, 2024
1 parent 1caab59 commit c153ae7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/appsignal/helpers/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,10 @@ def set_namespace(namespace)
# Tags are extra bits of information that are added to transaction and
# appear on sample details pages on AppSignal.com.
#
# When this method is called multiple times, it will merge the tags.
#
# @example
# Appsignal.tag_request(:locale => "en")
# Appsignal.tag_request(:locale => "en", :user_id => 1)
# Appsignal.tag_request("locale" => "en")
# Appsignal.tag_request("user_id" => 1)
#
Expand Down
4 changes: 3 additions & 1 deletion lib/appsignal/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,16 @@ def set_params_if_nil(given_params)

# Set tags on the transaction.
#
# When this method is called multiple times, it will merge the tags.
#
# @param given_tags [Hash] Collection of tags.
# @option given_tags [String, Symbol, Integer] :any
# The name of the tag as a Symbol.
# @option given_tags [String, Symbol, Integer] "any"
# The name of the tag as a String.
# @return [void]
#
# @see Appsignal.tag_request
# @see Helpers::Instrumentation#tag_request
# @see https://docs.appsignal.com/ruby/instrumentation/tagging.html
# Tagging guide
def set_tags(given_tags = {})
Expand Down
18 changes: 14 additions & 4 deletions spec/lib/appsignal/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ def create_transaction(id = transaction_id)

describe "#set_tags" do
let(:long_string) { "a" * 10_001 }
before do

it "stores tags on the transaction" do
transaction.set_tags(
:valid_key => "valid_value",
"valid_string_key" => "valid_value",
Expand All @@ -443,10 +444,8 @@ def create_transaction(id = transaction_id)
:too_long_value => long_string,
long_string => "too_long_key"
)
transaction.sample_data
end
transaction._sample

it "stores tags on the transaction" do
expect(transaction).to include_tags(
"valid_key" => "valid_value",
"valid_string_key" => "valid_value",
Expand All @@ -456,6 +455,17 @@ def create_transaction(id = transaction_id)
long_string => "too_long_key"
)
end

it "merges the tags when called multiple times" do
transaction.set_tags(:key1 => "value1")
transaction.set_tags(:key2 => "value2")
transaction._sample

expect(transaction).to include_tags(
"key1" => "value1",
"key2" => "value2"
)
end
end

describe "#add_breadcrumb" do
Expand Down

0 comments on commit c153ae7

Please sign in to comment.