Skip to content

Commit 5685885

Browse files
authored
fix: Don't transform attributes in place in metrics (#2883)
1 parent d8352b6 commit 5685885

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

sentry-ruby/lib/sentry/metric_event.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def to_h
4343
private
4444

4545
def serialize_attributes
46-
@attributes.transform_values! { |v| attribute_hash(v) }
46+
@attributes.transform_values { |v| attribute_hash(v) }
4747
end
4848
end
4949
end

sentry-ruby/spec/sentry/metric_event_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@
117117
expect(attributes["unknown"][:value]).to include("Object")
118118
end
119119

120+
it "does not mutate the original attributes hash" do
121+
attributes = { "foo" => "bar" }
122+
event1 = described_class.new(name: "test.metric", type: :counter, value: 1, attributes: attributes)
123+
event1.to_h
124+
125+
event2 = described_class.new(name: "test.metric", type: :counter, value: 1, attributes: attributes)
126+
hash = event2.to_h
127+
128+
expect(attributes).to eq({ "foo" => "bar" })
129+
expect(hash[:attributes]["foo"]).to eq({ type: "string", value: "bar" })
130+
end
131+
120132
it "merges custom attributes with default attributes" do
121133
event = described_class.new(
122134
name: "test.metric",

0 commit comments

Comments
 (0)