From 07aaf5ed8818e6693439c8f1972ef2e7483a6724 Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Tue, 23 Apr 2024 13:07:38 +0200 Subject: [PATCH] Don't throw error on arbitrary arguments being passed to `capture_event` options (#2301) --- CHANGELOG.md | 5 +++++ sentry-ruby/lib/sentry/scope.rb | 3 ++- sentry-ruby/spec/sentry/scope_spec.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df155c303..4f6e8a798 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ Rails users will be able to use `bin/rails generate sentry` to generate their `config/initializers/sentry.rb` file. +### Bug Fixes + +- Don't throw error on arbitrary arguments being passed to `capture_event` options [#2301](https://github.com/getsentry/sentry-ruby/pull/2301) + - Fixes [#2299](https://github.com/getsentry/sentry-ruby/issues/2299) + ## 5.17.3 ### Internal diff --git a/sentry-ruby/lib/sentry/scope.rb b/sentry-ruby/lib/sentry/scope.rb index 6e78c6e04..8f03277b8 100644 --- a/sentry-ruby/lib/sentry/scope.rb +++ b/sentry-ruby/lib/sentry/scope.rb @@ -135,7 +135,8 @@ def update_from_options( tags: nil, user: nil, level: nil, - fingerprint: nil + fingerprint: nil, + **options ) self.contexts.merge!(contexts) if contexts self.extra.merge!(extra) if extra diff --git a/sentry-ruby/spec/sentry/scope_spec.rb b/sentry-ruby/spec/sentry/scope_spec.rb index c3799602a..973662495 100644 --- a/sentry-ruby/spec/sentry/scope_spec.rb +++ b/sentry-ruby/spec/sentry/scope_spec.rb @@ -336,4 +336,30 @@ subject.generate_propagation_context(env) end end + + describe '#update_from_options' do + it 'updates data from arguments' do + subject.update_from_options( + contexts: { context: 1 }, + extra: { foo: 42 }, + tags: { tag: 2 }, + user: { name: 'jane' }, + level: :info, + fingerprint: 'ABCD' + ) + + expect(subject.contexts).to include(context: 1) + expect(subject.extra).to eq({ foo: 42 }) + expect(subject.tags).to eq({ tag: 2 }) + expect(subject.user).to eq({ name: 'jane' }) + expect(subject.level).to eq(:info) + expect(subject.fingerprint).to eq('ABCD') + end + + it 'does not throw when arbitrary options passed' do + expect do + subject.update_from_options(foo: 42) + end.not_to raise_error + end + end end