Skip to content

Sentry::Scope#set_contexts fails duplicate keys don't have Hash values #1805

@tsu-shiuan

Description

@tsu-shiuan

Issue Description

Introduced here #1621 in versions 4.8.1 and above.

I believe the intention here is that when additional context is given for the same key, and when the value is a Hash, we want to append any new key values to the existing Hash as shown in the description.

The problem is that not all values are Hashes, which results in 👇

NoMethodError: undefined method `merge' for "bar":String

Reproduction Steps

Sentry.configure_scope do |scope|
  scope.set_contexts({:foo => "bar"})
end

Sentry.configure_scope do |scope|
   scope.set_contexts({:foo => "new bar"})
end

Expected Behavior

Replaces the existing "bar" value with "new bar"

Actual Behavior

NoMethodError: undefined method `merge' for "new bar":String
from /srv/bundle/ruby/2.7.0/gems/sentry-ruby-core-4.8.1/lib/sentry/scope.rb:132:in `block in set_contexts'

### Ruby Version

2.7.5

### SDK Version

5.3.0

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions