Skip to content

Append to Context/User #933

Open
Open
@rcoup

Description

@rcoup

Use case:

  1. get a user id when the request is initially parsed (eg. from an Authorization header), and call scope.set_user({'http-username': 'bob'})
  2. later during request processing, get some more user information (say, email), and do scope.set_user({'email': 'test@example.com'}). Lets assume the request/headers aren't available at that point to re-retrieve http-username.
  3. the later call replaces existing data in the scope (ie: the event ends up with only {'email': 'test@example.com'})
  4. same applies to other context sections (via scope.set_context('section', {'some': 'value'}))

AFAICT there isn't even a way to get the current user/contexts out again in order to manually merge them except via internals (scope._user/scope._contexts['a_section']). The framework integrations all seem to append to the user data, but that seems to happen much later in the processing.

Would it be worth exposing getter properties/methods, add scope.merge_*() methods (which call dict.update()), add merge=True|False parameters to set_user() & set_context(), or something else equivalent?

Activity

github-actions

github-actions commented on Jan 5, 2022

@github-actions

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

rcoup

rcoup commented on Jan 6, 2022

@rcoup
Author

Would it be worth exposing getter properties/methods, add scope.merge_*() methods (which call dict.update()), add merge=True|False parameters to set_user() & set_context(), or something else equivalent?

@sl0thentr0py I can potentially do a PR for this, but need some direction on which option is preferred

self-assigned this
on Jan 6, 2022
sl0thentr0py

sl0thentr0py commented on Jan 6, 2022

@sl0thentr0py
Member

Hi @rcoup, user facing API changes need to be discussed internally first. A lot of folks are on vacation right now. I'll try to get back to you with more info next week.

added this to the Sentry SDK 2.0 milestone on Jul 4, 2023
sentrivana

sentrivana commented on Jul 4, 2023

@sentrivana
Contributor

Note for later: https://develop.sentry.dev/sdk/unified-api/#scope
We're currently not doing what the documentation states, so we should probably change this in the next major.

added
TriagedHas been looked at recently during old issue triage
on Aug 28, 2023
modified the milestones: Sentry SDK 2.0, Breaking changes on Feb 16, 2024
removed this from the Breaking Changes milestone on Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @rcoup@antonpirker@sl0thentr0py@stephanie-anderson@hubertdeng123

    Issue actions

      Append to Context/User · Issue #933 · getsentry/sentry-python