Skip to content

Context values validation in set_contexts method #2021

Closed

Description

Issue Description

In the Sentry Ruby SDK docs about enriching events with context, there is info that context param should be an object and it values can be arbitrary:

A context must always be a dictionary or map, and its values can be arbitrary.

but when I report error using set_contexts method to set multiple contexts at once, with context value that is not Hash, I get the following error on the issue page in UI:
image (5)
and this value is not shown anywhere in contexts of this issue (other context values that are hashes are fine and are shown correctly)

Error badge says, that value should be an object, so I suppose in Ruby it's the Hash instance.
In source there is only validation that contexts param is a Hash but for example, in set_context method that sets only one context value there is check if this value it's a Hash.
I think that for setting multiple contexts it should also check whether those are hashes too to match Sentry web app validation and to prevent this kind of errors and discards. And because this method later tries to merge those with current context.

Reproduction Steps

Sentry.with_scope do |scope|
  scope.set_contexts({ id: 1 })
   
  Sentry.capture_message("test")
end

Expected Behavior

It should raise argument error as it's invalid context value.

Actual Behavior

No error raised, message is sent to Sentry and there is error badge in reported issue in Sentry web app.

Ruby Version

2.7

SDK Version

5.8.0

Integration and Its Version

None

Sentry Config

None

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions