Sentry-php: Allow merging user data on Scope

Created on 9 Dec 2019  路  2Comments  路  Source: getsentry/sentry-php

Summary

Currently the Scope only allows us to replace user data with the setUser() method, and because of this it's not possible to gradually include more specific user data. It would be good to merge that data.

Motivation

We don't always get all the user info from the same place, so it would be useful to gradually populate that data. For instance: adding the IP before the user is authenticated, then adding username and email afterwards.

Additional Context

The motivation for this request is the fact that the RequestListener from getsentry/sentry-symfony is overwriting my user data. As it does add some useful data, it would be best if it was possible to keep the user data it provided while also adding some data myself without replacing it.

Confirmed Improvement

Most helpful comment

There you go @ste93cry: #931

All 2 comments

Indeed it makes sense and in fact the Unified API documentation says that the setUser method of the scope should do a shallow merge, so +1 on fixing this. How to do such change is another discussion unfortunately, as modifying the behavior of an existing function may break existing applications: adding a boolean argument defaulting to false that let users decide whether to replace the data as a whole or to merge existing data with the new one should be fine. Of course, we should throw a deprecation for the old behavior and then in 3.0 we will align with what other SDKs do out of the box. We should also add a removeUser method to let users remove information from the context, or we should clear all data if an empty array is passed (documentation talks about these two ways for solving this, but personally I find the first one the clearest). If this makes sense to you, are you willing to contribute the changes?

There you go @ste93cry: #931

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SunflowerFuchs picture SunflowerFuchs  路  7Comments

JanMikes picture JanMikes  路  4Comments

parichayawalia picture parichayawalia  路  3Comments

brunowowk picture brunowowk  路  5Comments

iluuu1994 picture iluuu1994  路  3Comments