Skip to content

Commit 89f371f

Browse files
moznionst0012
andauthored
Suppress the unnecessary “unsupported options notice” (#2349)
* Suppress the unnecessary “unsupported options notice” In `Scope#update_from_options()`, the method strips key-value pairs from the `options` according to its parameters. When all keys in `options` are supported, it still logs an “unsupported options notice” for an empty `unsupported_option_keys` value with empty array literal in `Sentry::Hub#capture_event`, like: "Options [] are not supported and will not be applied to the event." Example: When calling `subject.capture_event(event, level: 'DEBUG')`, the `capture_event` method should handle the options like this: # In this case, options == {:level=>'DEBUG'} unsupported_option_keys = scope.update_from_options(**options) # unsupported_option_keys should be [], but the following debug log will be shown # like "Options [] are not supported and will not be applied to the event." configuration.log_debug <<~MSG Options #{unsupported_option_keys} are not supported and will not be applied to the event. You may want to set them under the `extra` option. MSG This patch changes the logic to check whether `unsupported_option_keys` is empty before logging the notice, thus suppressing unnecessary logs. Signed-off-by: moznion <[email protected]> * Update sentry-ruby/spec/sentry/hub_spec.rb --------- Signed-off-by: moznion <[email protected]> Co-authored-by: Stan Lo <[email protected]>
1 parent 36866c5 commit 89f371f

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- Use Concurrent.usable_processor_count when it is available ([#2339](https://github.com/getsentry/sentry-ruby/pull/2339))
66

7+
### Bug Fixes
8+
9+
- Suppress the unnecessary “unsupported options notice” ([#2349](https://github.com/getsentry/sentry-ruby/pull/2349))
10+
711
## 5.18.1
812

913
### Bug Fixes

sentry-ruby/lib/sentry/hub.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,12 @@ def capture_event(event, **options, &block)
195195
elsif !options.empty?
196196
unsupported_option_keys = scope.update_from_options(**options)
197197

198-
configuration.log_debug <<~MSG
199-
Options #{unsupported_option_keys} are not supported and will not be applied to the event.
200-
You may want to set them under the `extra` option.
201-
MSG
198+
unless unsupported_option_keys.empty?
199+
configuration.log_debug <<~MSG
200+
Options #{unsupported_option_keys} are not supported and will not be applied to the event.
201+
You may want to set them under the `extra` option.
202+
MSG
203+
end
202204
end
203205

204206
event = current_client.capture_event(event, scope, hint)

sentry-ruby/spec/sentry/hub_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@
350350
expect(string_io.string).to include("Options [:unsupported] are not supported and will not be applied to the event.")
351351
end
352352

353+
it "does not warn about unsupported options if all passed options are supported" do
354+
expect do
355+
subject.capture_event(event, level: 'DEBUG')
356+
end.not_to raise_error
357+
358+
expect(string_io.string).not_to include("Options [] are not supported and will not be applied to the event.")
359+
end
360+
353361
context "when event is a transaction" do
354362
it "transaction.set_context merges and takes precedence over scope.set_context" do
355363
scope.set_context(:foo, { val: 42 })

0 commit comments

Comments
 (0)