Users
Learn how to configure the SDK to capture the user and gain critical pieces of information that construct a unique identity in Sentry.
To attach the user to your events, we recommend to listen to Laravel's \Illuminate\Auth\Events\Authenticated
event:
\Sentry\configureScope(function (\Sentry\State\Scope $scope): void {
$scope->setUser(['email' => 'jane.doe@example.com']);
});
You can also clear the currently set user:
\Sentry\configureScope(function (\Sentry\State\Scope $scope): void {
$scope->removeUser();
});
Users consist of a few critical pieces of information that construct a unique identity in Sentry. Each of these is optional, but one must be present for the Sentry SDK to capture the user:
Your internal identifier for the user.
The username. Typically used as a better label than the internal id.
An alternative, or addition, to the username. Sentry is aware of email addresses and can display things such as Gravatars and unlock messaging capabilities.
The user's IP address. If the user is unauthenticated, Sentry uses the IP address as a unique identifier for the user. Serverside SDKs that instrument incoming requests will attempt to pull the IP address from the HTTP request data (request.env.REMOTE_ADDR
field in JSON), if available. That might require send_default_pii
set to true
in the SDK options.
If the field is omitted, the default value is null
.
To opt out of storing users' IP addresses in your event data, you can go to your project settings, click on "Security & Privacy", and enable "Prevent Storing of IP Addresses" or use Sentry's server-side data scrubbing to remove $user.ip_address
. Adding such a rule ultimately overrules any other logic.
Additionally, you can provide arbitrary key/value pairs beyond the reserved names, and the Sentry SDK will store those with the user.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").