Skip to content

Should set_context with the same context name clobber existing values? #1619

Closed

Description

It wasn't clear to me from the documentation that calling Scope#set_context with the same name multiple times would clobber existing values, should that be the case? By way of example, here's what I'm doing:

# in my correlation ID middleware:
Sentry.configure_scope do |scope|
  scope.set_context(:request, { correlation_id: env[NAME] })
end

# in my separate session ID middleware:
Sentry.configure_scope do |scope|
  scope.set_context(:request, { session_id: env[Rack::RACK_SESSION][NAME] })
end

Right now, the only context stored in the :request name is the :session_id because that's called later in my middleware stack. Maybe it's just personal opinion, but I would have expected the :request context to contain both :correlation_id and :session_id, but the code calls .merge! and clobbers any existing value using the same name.

Is this by design or should we be able to add to contexts over time? I'd be happy to contribute a change to get that sort of feature added if that would help.

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