Skip to content
Merged
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 sentry-ruby/lib/sentry/metric_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def to_h
private

def serialize_attributes
@attributes.transform_values! { |v| attribute_hash(v) }
@attributes.transform_values { |v| attribute_hash(v) }
end
end
end
12 changes: 12 additions & 0 deletions sentry-ruby/spec/sentry/metric_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@
expect(attributes["unknown"][:value]).to include("Object")
end

it "does not mutate the original attributes hash" do
attributes = { "foo" => "bar" }
event1 = described_class.new(name: "test.metric", type: :counter, value: 1, attributes: attributes)
event1.to_h

event2 = described_class.new(name: "test.metric", type: :counter, value: 1, attributes: attributes)
hash = event2.to_h

expect(attributes).to eq({ "foo" => "bar" })
expect(hash[:attributes]["foo"]).to eq({ type: "string", value: "bar" })
end

it "merges custom attributes with default attributes" do
event = described_class.new(
name: "test.metric",
Expand Down
Loading