Skip to content

Commit 10210ea

Browse files
authored
[laravel] Clarify attaching a user to an event (#12830)
1 parent db8ca2e commit 10210ea

File tree

5 files changed

+91
-28
lines changed

5 files changed

+91
-28
lines changed

docs/platforms/php/common/data-management/data-collected.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ The category types and amount of data collected vary, depending on the integrati
1212

1313
By default, the Sentry SDK doesn't send any HTTP headers.
1414

15-
To start sending HTTP headers, set the [`send_default_pii` option](../configuration/options/#send-default-pii) to `true`.
15+
To start sending HTTP headers, set the <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii option</PlatformLink> to `true`.
1616

1717
## Cookies
1818

1919
By default, the Sentry SDK doesn't send cookies.
2020

21-
If you want to send cookies, set the [`send_default_pii` option](../configuration/options/#send-default-pii) to `true`.
21+
If you want to send cookies, set the <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii option</PlatformLink> to `true`.
2222

2323
## Users' IP Address
2424

2525
By default, the Sentry SDK doesn't send the user's IP address.
2626

27-
To enable sending the user's IP address, set the [`send_default_pii` option](../configuration/options/#send-default-pii) to `true`.
27+
To enable sending the user's IP address, set the <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii option</PlatformLink> to `true`.
2828

2929
## Request URL
3030

@@ -42,15 +42,15 @@ The request body of incoming HTTP requests can be sent to Sentry. Whether it's s
4242
-JSON and form bodies are sent
4343
-Raw request bodies are always removed
4444
-Uploaded files in the request bodies are never sent to Sentry
45-
- **The size of the request body:** There's a [`max_request_body_size` option](../configuration/options/#max-request-body-size) that's set to `medium` by default. This means that larger request bodies aren't sent to Sentry.
45+
- **The size of the request body:** There's a <PlatformLink to="/configuration/options/#max_request_body_size">max_request_body_size option</PlatformLink> that's set to `medium` by default. This means that larger request bodies aren't sent to Sentry.
4646

4747
If you want to prevent bodies from being sent to Sentry altogether, set `max_request_body_size` to `'never'`.
4848

4949
## Source Context
5050

5151
When an unhandled exception is sent to Sentry, a snapshot of the source code surrounding the line where the error originates is sent with it.
5252

53-
To opt out of sending this source context to Sentry, set the [`context_lines` option](../configuration/options/#context-lines) to `0`.
53+
To opt out of sending this source context to Sentry, set the <PlatformLink to="/configuration/options/#context-lines">`context_lines` option</PlatformLink> to `0`.
5454

5555
## Local Variables In Stack Trace
5656

docs/platforms/php/common/enriching-events/identify-user/index.mdx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ title: Users
33
description: "Learn how to configure the SDK to capture the user and gain critical pieces of information that construct a unique identity in Sentry."
44
---
55

6+
To attach the user to your events, we recommend to listen to Laravel's `\Illuminate\Auth\Events\Authenticated` event:
7+
8+
<PlatformContent includePath="enriching-events/set-user" />
9+
10+
You can also clear the currently set user:
11+
12+
<PlatformContent includePath="enriching-events/unset-user" />
13+
614
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:
715

816
<DefinitionList>
@@ -24,20 +32,10 @@ An alternative, or addition, to the username. Sentry is aware of email addresses
2432
The user's IP address. If the user is unauthenticated, Sentry uses the IP address as a unique identifier for the user.
2533
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 <PlatformIdentifier name="send-default-pii" /> set to `true` in the SDK options.
2634

27-
If the user's `ip_address` is set to `"{{auto}}"`, Sentry will infer the IP address from the connection between your app and Sentry's server.
28-
29-
If the field is omitted, the default value is `null`. However, due to backwards compatibility concerns, certain platforms (in particular JavaScript) have a different default value for `"{{auto}}"`. SDKs and other clients should not rely on this behavior and should set IP addresses or `"{{auto}}"` explicitly.
35+
If the field is omitted, the default value is `null`.
3036

3137
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](/security-legal-pii/scrubbing/) scrubbing to remove `$user.ip_address`. Adding such a rule ultimately overrules any other logic.
3238

3339
</DefinitionList>
3440

3541
Additionally, you can provide arbitrary key/value pairs beyond the reserved names, and the Sentry SDK will store those with the user.
36-
37-
To identify the user:
38-
39-
<PlatformContent includePath="enriching-events/set-user" />
40-
41-
You can also clear the currently set user:
42-
43-
<PlatformContent includePath="enriching-events/unset-user" />

docs/platforms/php/guides/laravel/data-management/data-collected.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ The category types and amount of data collected vary, depending on the integrati
1212

1313
By default, the Sentry SDK doesn't send any HTTP headers.
1414

15-
To start sending HTTP headers, set the [`send_default_pii` option](../configuration/options/#send-default-pii) to `true`.
15+
To start sending HTTP headers, set the <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii option</PlatformLink> to `true`.
1616

1717
## Cookies
1818

1919
By default, the Sentry SDK doesn't send cookies. Sentry tries to remove any cookies that contain sensitive information, (such as the Laravel Session, Remember Token and CSRF Token cookies).
2020

21-
If you want to send cookies, set the [`send_default_pii` option](../configuration/options/#send-default-pii) to `true`.
21+
If you want to send cookies, set the <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii option</PlatformLink> to `true`.
2222

2323
## Information About Logged-in User
2424

2525
By default, the Sentry SDK doesn't send any information about the logged-in user, (such as email address, user id, or username).
2626

27-
To start sending logged-in user information, set the [`send_default_pii` option](../configuration/options/#send-default-pii) to `true`.
27+
To start sending logged-in user information, set the <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii option</PlatformLink> to `true`.
2828

2929
## Users' IP Address
3030

3131
By default, the Sentry SDK doesn't send the user's IP address.
3232

33-
To enable sending the user's IP address, set the [`send_default_pii` option](../configuration/options/#send-default-pii) to `true`.
33+
To enable sending the user's IP address, set the <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii option</PlatformLink> to `true`.
3434

3535
## Request URL
3636

@@ -48,15 +48,15 @@ The request body of incoming HTTP requests can be sent to Sentry. Whether it's s
4848
-JSON and form bodies are sent
4949
-Raw request bodies are always removed
5050
-Uploaded files in the request bodies are never sent to Sentry
51-
- **The size of the request body:** There's a [`max_request_body_size` option](../configuration/options/#max-request-body-size) that's set to `medium` by default. This means that larger request bodies aren't sent to Sentry.
51+
- **The size of the request body:** There's an <PlatformLink to="/configuration/options/#max_request_body_size">max_request_body_size option</PlatformLink> that's set to `medium` by default. This means that larger request bodies aren't sent to Sentry.
5252

5353
If you want to prevent bodies from being sent to Sentry altogether, set `max_request_body_size` to `'never'`.
5454

5555
## Source Context
5656

5757
When an unhandled exception is sent to Sentry, a snapshot of the source code surrounding the line where the error originates is sent with it.
5858

59-
To opt out of sending this source context to Sentry, set the [`context_lines` option](../configuration/options/#context-lines) to `0`.
59+
To opt out of sending this source context to Sentry, set the <PlatformLink to="/configuration/options/#context_lines">context_lines option</PlatformLink> to `0`.
6060

6161
## Local Variables In Stack Trace
6262

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: Users
3+
description: "Learn how to configure the SDK to capture the user and gain critical pieces of information that construct a unique identity in Sentry."
4+
---
5+
6+
If the SDK is configured with <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii</PlatformLink> set to `true`, we automatically attach the authenticated user to all your events sent to Sentry.
7+
8+
If you instead want to manually attach the user to your events, we recommend to listen to Laravel's `\Illuminate\Auth\Events\Authenticated` event:
9+
10+
```php {filename:app/Providers/AppServiceProvider.php}
11+
/**
12+
* Bootstrap any application services.
13+
*/
14+
public function boot(): void
15+
{
16+
\Illuminate\Support\Facades\Event::listen(function (\Illuminate\Auth\Events\Authenticated $event) {
17+
$user = $event->user;
18+
19+
\Sentry\Laravel\Integration::configureScope(static function (Scope $scope) use ($user): void {
20+
$scope->setUser([
21+
'id' => $user->id,
22+
'name' => $user->name,
23+
'email' => $user->email,
24+
]);
25+
});
26+
});
27+
}
28+
```
29+
30+
You can also clear the currently set user:
31+
32+
```php
33+
\Sentry\Laravel\Integration::configureScope(static function (\Sentry\State\Scope $scope): void {
34+
$scope->removeUser();
35+
});
36+
```
37+
38+
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:
39+
40+
<DefinitionList>
41+
42+
### `id`
43+
44+
Your internal identifier for the user.
45+
46+
### `username`
47+
48+
The username. Typically used as a better label than the internal id.
49+
50+
### `email`
51+
52+
An alternative, or addition, to the username. Sentry is aware of email addresses and can display things such as Gravatars and unlock messaging capabilities.
53+
54+
### `ip_address`
55+
56+
The user's IP address. If the user is unauthenticated, Sentry uses the IP address as a unique identifier for the user.
57+
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 <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii</PlatformLink> set to `true` in the SDK options.
58+
59+
If the field is omitted, the default value is `null`.
60+
61+
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](/security-legal-pii/scrubbing/) scrubbing to remove `$user.ip_address`. Adding such a rule ultimately overrules any other logic.
62+
63+
</DefinitionList>
64+
65+
Additionally, you can provide arbitrary key/value pairs beyond the reserved names, and the Sentry SDK will store those with the user.

docs/platforms/php/guides/symfony/data-management/data-collected.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ The category types and amount of data collected vary, depending on the integrati
1212

1313
By default, the Sentry SDK doesn't send any HTTP headers.
1414

15-
To start sending HTTP headers, set the [`send_default_pii` option](../configuration/options/#send-default-pii) to `true`.
15+
To start sending HTTP headers, set the <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii option</PlatformLink> to `true`.
1616

1717
## Cookies
1818

1919
By default, the Sentry SDK doesn't send cookies.
2020

21-
If you want to send cookies, set the [`send_default_pii` option](../configuration/options/#send-default-pii) to `true`.
21+
If you want to send cookies, set the <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii option</PlatformLink> to `true`.
2222

2323
## Information About Logged-in User
2424

2525
By default, the Sentry SDK doesn't send any information about the logged-in user, (such as user id, or impersonator username).
2626

27-
To start sending logged-in user information, set the [`send_default_pii` option](../configuration/options/#send-default-pii) to `true`.
27+
To start sending logged-in user information, set the <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii option</PlatformLink> to `true`.
2828

2929
## Users' IP Address
3030

3131
By default, the Sentry SDK doesn't send the user's IP address.
3232

33-
To enable sending the user's IP address, set the [`send_default_pii` option](../configuration/options/#send-default-pii) to `true`.
33+
To enable sending the user's IP address, set the <PlatformLink to="/configuration/options/#send_default_pii">send_default_pii option</PlatformLink> to `true`.
3434

3535
## Request URL
3636

@@ -48,15 +48,15 @@ The request body of incoming HTTP requests can be sent to Sentry. Whether it's s
4848
-JSON and form bodies are sent
4949
-Raw request bodies are always removed
5050
-Uploaded files in the request bodies are never sent to Sentry
51-
- **The size of the request body:** There's a [`max_request_body_size` option](../configuration/options/#max-request-body-size) that's set to `medium` by default. This means that larger request bodies aren't sent to Sentry.
51+
- **The size of the request body:** There's an <PlatformLink to="/configuration/options/#max_request_body_size">max_request_body_size option</PlatformLink> that's set to `medium` by default. This means that larger request bodies aren't sent to Sentry.
5252

5353
If you want to prevent bodies from being sent to Sentry altogether, set `max_request_body_size` to `'never'`.
5454

5555
## Source Context
5656

5757
When an unhandled exception is sent to Sentry, a snapshot of the source code surrounding the line where the error originates is sent with it.
5858

59-
To opt out of sending this source context to Sentry, set the [`context_lines` option](../configuration/options/#context-lines) to `0`.
59+
To opt out of sending this source context to Sentry, set the <PlatformLink to="/configuration/options/#context_lines">context_lines option</PlatformLink> to `0`.
6060

6161
## Local Variables In Stack Trace
6262

0 commit comments

Comments
 (0)