According https://github.com/getsentry/sentry-php/pull/931 there is a depricated way to set user data over:
Sentry\configureScope(function (Sentry\State\Scope $scope) use ($user_info): void {
$scope->setUser([...]);
});
So, how I need to make is correctly. Now I'm getting warning like 'USER_DEPRECATED Replacing the data is deprecated since version 2.3 and will stop working from version 3.0'
You just need to pass true to the second argument of the setUser method:
$scope->setUser([...], true);
Since there is no way (at the moment, at least) to remove something set on the root-level of the context, if you need to do it the best way is to create a temporary nested scope that will be popped off from the stack when it will not be needed anymore. This happens because the data you pass to the method is merged with the existing data, thus it's impossible to unset the keys or replace the data entirely
configureScope(static function (Scope $scope): void {
$scope->setUser(['foo' => 'bar'], true);
});
// event.user = ['foo' => 'bar']
withScope(static function (Scope $scope): void {
$scope->setUser(['foo' => 'baz'], true);
$scope->setUser(['bar' => ['qux' => 'quux']], true);
// event.user = ['foo' => 'baz', 'bar' => ['qux' => 'quux']]
$scope->setUser(['bar' => ['quux' => 'quuz'], true);
// event.user = ['foo' => 'baz', 'bar' => ['quux' => 'quuz']]
});
// event.user = ['foo' => 'bar']
You just need to pass
trueto the second argument of thesetUsermethod:
oh, right! I decided that I need to change method I used. I was inattentive when I read that code
Most helpful comment
You just need to pass
trueto the second argument of thesetUsermethod:Since there is no way (at the moment, at least) to remove something set on the root-level of the context, if you need to do it the best way is to create a temporary nested scope that will be popped off from the stack when it will not be needed anymore. This happens because the data you pass to the method is merged with the existing data, thus it's impossible to unset the keys or replace the data entirely