Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge context with the same key instead of replacing the old value. #1621

Merged
merged 3 commits into from
Nov 19, 2021
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## 4.8.1

### Bug Fixes

- Merge context with the same key instead of replacing the old value. [#1621](https://github.com/getsentry/sentry-ruby/pull/1621)
- Fixes [#1619](https://github.com/getsentry/sentry-ruby/issues/1619)

### Refactoring

- Extract envelope construction logic from Transport [#1616](https://github.com/getsentry/sentry-ruby/pull/1616)
Expand Down
10 changes: 6 additions & 4 deletions sentry-ruby/lib/sentry/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def set_extras(extras_hash)
end

def set_extra(key, value)
@extra.merge!(key => value)
set_extras(key => value)
end

def set_tags(tags_hash)
Expand All @@ -121,17 +121,19 @@ def set_tags(tags_hash)
end

def set_tag(key, value)
@tags.merge!(key => value)
set_tags(key => value)
end

def set_contexts(contexts_hash)
check_argument_type!(contexts_hash, Hash)
@contexts.merge!(contexts_hash)
@contexts.merge!(contexts_hash) do |key, old, new|
new.merge(old)
end
end

def set_context(key, value)
check_argument_type!(value, Hash)
@contexts.merge!(key => value)
set_contexts(key => value)
end

def set_level(level)
Expand Down
12 changes: 12 additions & 0 deletions sentry-ruby/spec/sentry/scope/setters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@
expect(subject.contexts).to include({ character: { name: "John", age: 25 }})
expect(subject.contexts).to include({ another_character: { name: "Jane", age: 20 }})
end

it "merges context with the same key" do
subject.set_contexts({ character: { name: "John" }})
subject.set_contexts({ character: { age: 25 }})
expect(subject.contexts).to include({ character: { name: "John", age: 25 }})
end
end

describe "#set_context" do
Expand All @@ -127,6 +133,12 @@
}
)
end

it "merges context with the same key" do
subject.set_context(:character, { name: "John" })
subject.set_context(:character, { age: 25 })
expect(subject.contexts).to include({ character: { name: "John", age: 25 }})
end
end

describe "#set_tags" do
Expand Down