Skip to content

Commit

Permalink
Ensure the original hashes are not modified
Browse files Browse the repository at this point in the history
The customer might pass a hash that is used someplace else in their
application. We should not modify the given hash.

(We just saw this issue with appsignal/appsignal-javascript#639)
  • Loading branch information
unflxw committed Nov 12, 2024
1 parent 6244731 commit ae5b83b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/appsignal/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def silence(_severity = ERROR, &block)
attr_reader :default_attributes

def add_with_attributes(severity, message, group, attributes)
Thread.current[:appsignal_logger_attributes] = default_attributes.merge!(attributes)
Thread.current[:appsignal_logger_attributes] = default_attributes.merge(attributes)
add(severity, message, group)
ensure
Thread.current[:appsignal_logger_attributes] = nil
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/appsignal/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@
Appsignal::Utils::Data.generate({ :other_key => "other_value", :some_key => "some_value" }))
logger.error("Some message", { :other_key => "other_value" })
end

it "does not modify the original attribute hashes passed" do
default_attributes = { :some_key => "some_value" }
logger = Appsignal::Logger.new("group", :attributes => default_attributes)

line_attributes = { :other_key => "other_value" }
logger.error("Some message", line_attributes)

expect(default_attributes).to eq({ :some_key => "some_value" })
expect(line_attributes).to eq({ :other_key => "other_value" })
end
end

describe "#error with exception object" do
Expand Down

0 comments on commit ae5b83b

Please sign in to comment.